import type { TemplateContext } from '../types'; export function generateCompletionStatus(ctx: TemplateContext): string { return `## Completion Status Protocol When completing a skill workflow, report status using one of: - **DONE** — All steps completed successfully. Evidence provided for each claim. - **DONE_WITH_CONCERNS** — Completed, but with issues the user should know about. List each concern. - **BLOCKED** — Cannot proceed. State what is blocking and what was tried. - **NEEDS_CONTEXT** — Missing information required to continue. State exactly what you need. ### Escalation It is always OK to stop and say "this is too hard for me" or "I'm not confident in this result." Bad work is worse than no work. You will not be penalized for escalating. - If you have attempted a task 3 times without success, STOP and escalate. - If you are uncertain about a security-sensitive change, STOP and escalate. - If the scope of work exceeds what you can verify, STOP and escalate. Escalation format: \`\`\` STATUS: BLOCKED | NEEDS_CONTEXT REASON: [1-2 sentences] ATTEMPTED: [what you tried] RECOMMENDATION: [what the user should do next] \`\`\` ## Operational Self-Improvement Before completing, reflect on this session: - Did any commands fail unexpectedly? - Did you take a wrong approach and have to backtrack? - Did you discover a project-specific quirk (build order, env vars, timing, auth)? - Did something take longer than expected because of a missing flag or config? If yes, log an operational learning for future sessions: \`\`\`bash ${ctx.paths.binDir}/gstack-learnings-log '{"skill":"SKILL_NAME","type":"operational","key":"SHORT_KEY","insight":"DESCRIPTION","confidence":N,"source":"observed"}' \`\`\` Replace SKILL_NAME with the current skill name. Only log genuine operational discoveries. Don't log obvious things or one-time transient errors (network blips, rate limits). A good test: would knowing this save 5+ minutes in a future session? If yes, log it. ## Telemetry (run last) After the skill workflow completes (success, error, or abort), log the telemetry event. Determine the skill name from the \`name:\` field in this file's YAML frontmatter. Determine the outcome from the workflow result (success if completed normally, error if it failed, abort if the user interrupted). **PLAN MODE EXCEPTION — ALWAYS RUN:** This command writes telemetry to \`~/.gstack/analytics/\` (user config directory, not project files). The skill preamble already writes to the same directory — this is the same pattern. Skipping this command loses session duration and outcome data. Run this bash: \`\`\`bash _TEL_END=$(date +%s) _TEL_DUR=$(( _TEL_END - _TEL_START )) rm -f ~/.gstack/analytics/.pending-"$_SESSION_ID" 2>/dev/null || true # Session timeline: record skill completion (local-only, never sent anywhere) ~/.claude/skills/gstack/bin/gstack-timeline-log '{"skill":"SKILL_NAME","event":"completed","branch":"'$(git branch --show-current 2>/dev/null || echo unknown)'","outcome":"OUTCOME","duration_s":"'"$_TEL_DUR"'","session":"'"$_SESSION_ID"'"}' 2>/dev/null || true # Local analytics (gated on telemetry setting) if [ "$_TEL" != "off" ]; then echo '{"skill":"SKILL_NAME","duration_s":"'"$_TEL_DUR"'","outcome":"OUTCOME","browse":"USED_BROWSE","session":"'"$_SESSION_ID"'","ts":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' >> ~/.gstack/analytics/skill-usage.jsonl 2>/dev/null || true fi # Remote telemetry (opt-in, requires binary) if [ "$_TEL" != "off" ] && [ -x ~/.claude/skills/gstack/bin/gstack-telemetry-log ]; then ~/.claude/skills/gstack/bin/gstack-telemetry-log \\ --skill "SKILL_NAME" --duration "$_TEL_DUR" --outcome "OUTCOME" \\ --used-browse "USED_BROWSE" --session-id "$_SESSION_ID" 2>/dev/null & fi \`\`\` Replace \`SKILL_NAME\` with the actual skill name from frontmatter, \`OUTCOME\` with success/error/abort, and \`USED_BROWSE\` with true/false based on whether \`$B\` was used. If you cannot determine the outcome, use "unknown". The local JSONL always logs. The remote binary only runs if telemetry is not off and the binary exists. ## Plan Mode Safe Operations When in plan mode, these operations are always allowed because they produce artifacts that inform the plan, not code changes: - \`$B\` commands (browse: screenshots, page inspection, navigation, snapshots) - \`$D\` commands (design: generate mockups, variants, comparison boards, iterate) - \`codex exec\` / \`codex review\` (outside voice, plan review, adversarial challenge) - Writing to \`~/.gstack/\` (config, analytics, review logs, design artifacts, learnings) - Writing to the plan file (already allowed by plan mode) - \`open\` commands for viewing generated artifacts (comparison boards, HTML previews) These are read-only in spirit — they inspect the live site, generate visual artifacts, or get independent opinions. They do NOT modify project source files. ## Skill Invocation During Plan Mode If a user invokes a skill during plan mode, that invoked skill workflow takes precedence over generic plan mode behavior until it finishes or the user explicitly cancels that skill. Treat the loaded skill as executable instructions, not reference material. Follow it step by step. Do not summarize, skip, reorder, or shortcut its steps. If the skill says to use AskUserQuestion, do that. Those AskUserQuestion calls satisfy plan mode's requirement to end turns with AskUserQuestion. If the skill reaches a STOP point, stop immediately at that point, ask the required question if any, and wait for the user's response. Do not continue the workflow past a STOP point, and do not call ExitPlanMode at that point. If the skill includes commands marked "PLAN MODE EXCEPTION — ALWAYS RUN," execute them. The skill may edit the plan file, and other writes are allowed only if they are already permitted by Plan Mode Safe Operations or explicitly marked as a plan mode exception. Only call ExitPlanMode after the active skill workflow is complete and there are no other invoked skill workflows left to run, or if the user explicitly tells you to cancel the skill or leave plan mode. ## Plan Status Footer When you are in plan mode and about to call ExitPlanMode: 1. Check if the plan file already has a \`## GSTACK REVIEW REPORT\` section. 2. If it DOES — skip (a review skill already wrote a richer report). 3. If it does NOT — run this command: \\\`\\\`\\\`bash ~/.claude/skills/gstack/bin/gstack-review-read \\\`\\\`\\\` Then write a \`## GSTACK REVIEW REPORT\` section to the end of the plan file: - If the output contains review entries (JSONL lines before \`---CONFIG---\`): format the standard report table with runs/status/findings per skill, same format as the review skills use. - If the output is \`NO_REVIEWS\` or empty: write this placeholder table: \\\`\\\`\\\`markdown ## GSTACK REVIEW REPORT | Review | Trigger | Why | Runs | Status | Findings | |--------|---------|-----|------|--------|----------| | CEO Review | \\\`/plan-ceo-review\\\` | Scope & strategy | 0 | — | — | | Codex Review | \\\`/codex review\\\` | Independent 2nd opinion | 0 | — | — | | Eng Review | \\\`/plan-eng-review\\\` | Architecture & tests (required) | 0 | — | — | | Design Review | \\\`/plan-design-review\\\` | UI/UX gaps | 0 | — | — | | DX Review | \\\`/plan-devex-review\\\` | Developer experience gaps | 0 | — | — | **VERDICT:** NO REVIEWS YET — run \\\`/autoplan\\\` for full review pipeline, or individual reviews above. \\\`\\\`\\\` **PLAN MODE EXCEPTION — ALWAYS RUN:** This writes to the plan file, which is the one file you are allowed to edit in plan mode. The plan file review report is part of the plan's living status.`; }