wtf-p 0.8.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -18
- package/bin/lib/adapter-compiler.js +269 -55
- package/package.json +1 -1
- package/protocol/actions/advance.json +232 -0
- package/protocol/actions/plan-revision.json +8 -3
- package/protocol/actions/verify-work.json +6 -2
- package/protocol/aliases.lock.json +1 -0
- package/protocol/catalog.json +4 -2
- package/protocol/project/README.md +2 -0
- package/protocol/roles/research-synthesizer.md +1 -1
- package/protocol/skills/wtfp-manage-project/SKILL.md +2 -1
- package/protocol/skills/wtfp-manage-project/references/actions.md +13 -1
- package/protocol/skills/wtfp-plan-section/references/actions.md +1 -1
- package/protocol/skills/wtfp-research-literature/references/actions.md +1 -1
- package/protocol/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/protocol/workflows/advance.md +38 -0
- package/protocol/workflows/discuss-section.md +1 -1
- package/protocol/workflows/plan-revision.md +3 -3
- package/protocol/workflows/plan-section.md +1 -1
- package/protocol/workflows/research-gap.md +3 -3
- package/protocol/workflows/verify-work.md +4 -2
- package/protocol/workflows/write-section.md +2 -2
- package/vendors/antigravity/.wtfp-generated.json +54 -42
- package/vendors/antigravity/actions/advance.json +232 -0
- package/vendors/antigravity/actions/plan-revision.json +8 -3
- package/vendors/antigravity/actions/verify-work.json +6 -2
- package/vendors/antigravity/agents/wtfp-research-synthesizer.md +1 -1
- package/vendors/antigravity/aliases.lock.json +1 -0
- package/vendors/antigravity/catalog.json +4 -2
- package/vendors/antigravity/compatibility/action-availability.json +13 -1
- package/vendors/antigravity/plugin.json +2 -2
- package/vendors/antigravity/project/README.md +2 -0
- package/vendors/antigravity/roles/research-synthesizer.md +1 -1
- package/vendors/antigravity/rules/wtfp-project-state.md +2 -0
- package/vendors/antigravity/skills/wtfp-add-todo/SKILL.md +0 -2
- package/vendors/antigravity/skills/wtfp-advance/SKILL.md +18 -0
- package/vendors/antigravity/skills/wtfp-checkpoint/SKILL.md +0 -14
- package/vendors/antigravity/skills/wtfp-create-outline/SKILL.md +0 -8
- package/vendors/antigravity/skills/wtfp-create-poster/SKILL.md +1 -6
- package/vendors/antigravity/skills/wtfp-create-slides/SKILL.md +1 -6
- package/vendors/antigravity/skills/wtfp-discuss-section/SKILL.md +1 -5
- package/vendors/antigravity/skills/wtfp-execute-outline/SKILL.md +0 -10
- package/vendors/antigravity/skills/wtfp-help/SKILL.md +1 -1
- package/vendors/antigravity/skills/wtfp-list-assumptions/SKILL.md +1 -10
- package/vendors/antigravity/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/antigravity/skills/wtfp-manage-project/references/actions.md +29 -1
- package/vendors/antigravity/skills/wtfp-pause-writing/SKILL.md +0 -6
- package/vendors/antigravity/skills/wtfp-plan-milestone-gaps/SKILL.md +0 -6
- package/vendors/antigravity/skills/wtfp-plan-revision/SKILL.md +5 -11
- package/vendors/antigravity/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/antigravity/skills/wtfp-polish-prose/SKILL.md +0 -6
- package/vendors/antigravity/skills/wtfp-progress/SKILL.md +1 -22
- package/vendors/antigravity/skills/wtfp-quick/SKILL.md +0 -4
- package/vendors/antigravity/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/antigravity/skills/wtfp-resume-writing/SKILL.md +0 -12
- package/vendors/antigravity/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/antigravity/skills/wtfp-review-section/SKILL.md +0 -8
- package/vendors/antigravity/skills/wtfp-submit-milestone/SKILL.md +0 -12
- package/vendors/antigravity/skills/wtfp-verify-work/SKILL.md +6 -4
- package/vendors/antigravity/tools/README.md +1 -1
- package/vendors/antigravity/workflows/advance.md +38 -0
- package/vendors/antigravity/workflows/discuss-section.md +1 -1
- package/vendors/antigravity/workflows/plan-revision.md +3 -3
- package/vendors/antigravity/workflows/plan-section.md +1 -1
- package/vendors/antigravity/workflows/research-gap.md +3 -3
- package/vendors/antigravity/workflows/verify-work.md +4 -2
- package/vendors/antigravity/workflows/write-section.md +2 -2
- package/vendors/claude/.claude-plugin/marketplace.json +2 -2
- package/vendors/claude/.claude-plugin/plugin.json +1 -1
- package/vendors/claude/.wtfp-generated.json +108 -92
- package/vendors/claude/actions/advance.json +232 -0
- package/vendors/claude/actions/plan-revision.json +8 -3
- package/vendors/claude/actions/verify-work.json +6 -2
- package/vendors/claude/agents/wtfp-research-synthesizer.md +1 -1
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-argument-verifier.md +4 -5
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-citation-expert.md +5 -5
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-citation-formatter.md +3 -3
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-coherence-checker.md +6 -7
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-outliner.md +3 -3
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-plan-checker.md +4 -5
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-prose-polisher.md +4 -4
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-research-synthesizer.md +6 -6
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-section-planner.md +3 -3
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-section-reviewer.md +6 -7
- package/vendors/claude/ai.iowarp.clio/agents/wtfp-section-writer.md +3 -3
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/add-todo.md +0 -2
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/advance.md +15 -0
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/analyze-bib.md +4 -8
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/audit-milestone.md +2 -16
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/check-refs.md +4 -8
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/check-todos.md +2 -0
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/checkpoint.md +2 -14
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/create-outline.md +4 -10
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/create-poster.md +3 -6
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/create-slides.md +3 -6
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/discuss-section.md +3 -5
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/execute-outline.md +4 -12
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/export-latex.md +2 -8
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/help.md +4 -1
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/insert-section.md +2 -0
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/list-assumptions.md +1 -10
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/new-paper.md +2 -0
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/pause-writing.md +0 -6
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/plan-milestone-gaps.md +2 -6
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/plan-revision.md +7 -11
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/plan-section.md +5 -15
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/polish-prose.md +4 -8
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/progress.md +3 -22
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/quick.md +4 -6
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/research-gap.md +12 -14
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/resume-writing.md +2 -12
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/review-section.md +4 -10
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/settings.md +2 -0
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/submit-milestone.md +2 -12
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/verify-work.md +8 -4
- package/vendors/claude/ai.iowarp.clio/prompts/wtfp/write-section.md +6 -14
- package/vendors/claude/aliases.lock.json +1 -0
- package/vendors/claude/catalog.json +4 -2
- package/vendors/claude/commands/add-todo.md +0 -2
- package/vendors/claude/commands/advance.md +16 -0
- package/vendors/claude/commands/analyze-bib.md +0 -6
- package/vendors/claude/commands/audit-milestone.md +0 -16
- package/vendors/claude/commands/check-refs.md +0 -6
- package/vendors/claude/commands/checkpoint.md +0 -14
- package/vendors/claude/commands/create-outline.md +0 -8
- package/vendors/claude/commands/create-poster.md +1 -6
- package/vendors/claude/commands/create-slides.md +1 -6
- package/vendors/claude/commands/discuss-section.md +1 -5
- package/vendors/claude/commands/execute-outline.md +0 -10
- package/vendors/claude/commands/export-latex.md +0 -8
- package/vendors/claude/commands/help.md +1 -1
- package/vendors/claude/commands/list-assumptions.md +1 -10
- package/vendors/claude/commands/pause-writing.md +0 -6
- package/vendors/claude/commands/plan-milestone-gaps.md +0 -6
- package/vendors/claude/commands/plan-revision.md +5 -11
- package/vendors/claude/commands/plan-section.md +1 -13
- package/vendors/claude/commands/polish-prose.md +0 -6
- package/vendors/claude/commands/progress.md +1 -22
- package/vendors/claude/commands/quick.md +0 -4
- package/vendors/claude/commands/research-gap.md +3 -11
- package/vendors/claude/commands/resume-writing.md +0 -12
- package/vendors/claude/commands/review-section.md +0 -8
- package/vendors/claude/commands/submit-milestone.md +0 -12
- package/vendors/claude/commands/verify-work.md +6 -4
- package/vendors/claude/commands/write-section.md +2 -12
- package/vendors/claude/compatibility/action-availability.json +10 -1
- package/vendors/claude/output-styles/wtfp-academic-writing.md +2 -2
- package/vendors/claude/plugin.json +15 -1
- package/vendors/claude/project/README.md +2 -0
- package/vendors/claude/roles/research-synthesizer.md +1 -1
- package/vendors/claude/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/claude/skills/wtfp-manage-project/references/actions.md +29 -1
- package/vendors/claude/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/claude/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/claude/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/claude/tools/README.md +1 -1
- package/vendors/claude/workflows/advance.md +38 -0
- package/vendors/claude/workflows/discuss-section.md +1 -1
- package/vendors/claude/workflows/plan-revision.md +3 -3
- package/vendors/claude/workflows/plan-section.md +1 -1
- package/vendors/claude/workflows/research-gap.md +3 -3
- package/vendors/claude/workflows/verify-work.md +4 -2
- package/vendors/claude/workflows/write-section.md +2 -2
- package/vendors/clio-extension/.wtfp-generated.json +56 -8
- package/vendors/clio-extension/actions/advance.json +232 -0
- package/vendors/clio-extension/actions/plan-revision.json +8 -3
- package/vendors/clio-extension/actions/verify-work.json +6 -2
- package/vendors/clio-extension/clio-coder-extension.yaml +19 -4
- package/vendors/clio-extension/compatibility/action-availability.json +9 -3
- package/vendors/clio-extension/project/templates/checkpoint.json +25 -0
- package/vendors/clio-extension/project/templates/config.json +31 -0
- package/vendors/clio-extension/project/templates/decisions.json +35 -0
- package/vendors/clio-extension/project/templates/evidence.json +18 -0
- package/vendors/clio-extension/project/templates/interaction.json +16 -0
- package/vendors/clio-extension/project/templates/manifest.json +30 -0
- package/vendors/clio-extension/project/templates/outline.json +38 -0
- package/vendors/clio-extension/project/templates/section.json +32 -0
- package/vendors/clio-extension/project/templates/source.json +20 -0
- package/vendors/clio-extension/project/templates/state.json +22 -0
- package/vendors/clio-extension/project/templates/validation.json +32 -0
- package/vendors/clio-extension/runtime/extension.test.ts +656 -6
- package/vendors/clio-extension/runtime/extension.ts +885 -41
- package/vendors/clio-extension/runtime/write-guard.json +66 -0
- package/vendors/codex/plugins/wtfp/.codex-plugin/plugin.json +1 -1
- package/vendors/codex/plugins/wtfp/.wtfp-generated.json +31 -23
- package/vendors/codex/plugins/wtfp/actions/advance.json +232 -0
- package/vendors/codex/plugins/wtfp/actions/plan-revision.json +8 -3
- package/vendors/codex/plugins/wtfp/actions/verify-work.json +6 -2
- package/vendors/codex/plugins/wtfp/agents/wtfp-research-synthesizer.toml +1 -1
- package/vendors/codex/plugins/wtfp/aliases.lock.json +1 -0
- package/vendors/codex/plugins/wtfp/catalog.json +4 -2
- package/vendors/codex/plugins/wtfp/compatibility/action-availability.json +13 -1
- package/vendors/codex/plugins/wtfp/plugin.json +1 -1
- package/vendors/codex/plugins/wtfp/project/README.md +2 -0
- package/vendors/codex/plugins/wtfp/roles/research-synthesizer.md +1 -1
- package/vendors/codex/plugins/wtfp/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/codex/plugins/wtfp/skills/wtfp-manage-project/references/actions.md +29 -1
- package/vendors/codex/plugins/wtfp/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/codex/plugins/wtfp/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/codex/plugins/wtfp/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/codex/plugins/wtfp/tools/README.md +1 -1
- package/vendors/codex/plugins/wtfp/workflows/advance.md +38 -0
- package/vendors/codex/plugins/wtfp/workflows/discuss-section.md +1 -1
- package/vendors/codex/plugins/wtfp/workflows/plan-revision.md +3 -3
- package/vendors/codex/plugins/wtfp/workflows/plan-section.md +1 -1
- package/vendors/codex/plugins/wtfp/workflows/research-gap.md +3 -3
- package/vendors/codex/plugins/wtfp/workflows/verify-work.md +4 -2
- package/vendors/codex/plugins/wtfp/workflows/write-section.md +2 -2
- package/vendors/copilot/.wtfp-generated.json +43 -31
- package/vendors/copilot/marketplace.json +2 -2
- package/vendors/copilot/plugins/wtfp/.claude-plugin/plugin.json +1 -1
- package/vendors/copilot/plugins/wtfp/.wtfp-generated.json +55 -43
- package/vendors/copilot/plugins/wtfp/actions/advance.json +232 -0
- package/vendors/copilot/plugins/wtfp/actions/plan-revision.json +8 -3
- package/vendors/copilot/plugins/wtfp/actions/verify-work.json +6 -2
- package/vendors/copilot/plugins/wtfp/agents/wtfp-research-synthesizer.md +1 -1
- package/vendors/copilot/plugins/wtfp/aliases.lock.json +1 -0
- package/vendors/copilot/plugins/wtfp/catalog.json +4 -2
- package/vendors/copilot/plugins/wtfp/commands/wtfp-add-todo.md +0 -2
- package/vendors/copilot/plugins/wtfp/commands/wtfp-advance.md +17 -0
- package/vendors/copilot/plugins/wtfp/commands/wtfp-checkpoint.md +0 -14
- package/vendors/copilot/plugins/wtfp/commands/wtfp-create-outline.md +0 -8
- package/vendors/copilot/plugins/wtfp/commands/wtfp-create-poster.md +1 -6
- package/vendors/copilot/plugins/wtfp/commands/wtfp-create-slides.md +1 -6
- package/vendors/copilot/plugins/wtfp/commands/wtfp-discuss-section.md +1 -5
- package/vendors/copilot/plugins/wtfp/commands/wtfp-execute-outline.md +0 -10
- package/vendors/copilot/plugins/wtfp/commands/wtfp-help.md +1 -1
- package/vendors/copilot/plugins/wtfp/commands/wtfp-list-assumptions.md +1 -10
- package/vendors/copilot/plugins/wtfp/commands/wtfp-pause-writing.md +0 -6
- package/vendors/copilot/plugins/wtfp/commands/wtfp-plan-milestone-gaps.md +0 -6
- package/vendors/copilot/plugins/wtfp/commands/wtfp-plan-revision.md +5 -11
- package/vendors/copilot/plugins/wtfp/commands/wtfp-plan-section.md +1 -13
- package/vendors/copilot/plugins/wtfp/commands/wtfp-polish-prose.md +0 -6
- package/vendors/copilot/plugins/wtfp/commands/wtfp-progress.md +1 -22
- package/vendors/copilot/plugins/wtfp/commands/wtfp-quick.md +0 -4
- package/vendors/copilot/plugins/wtfp/commands/wtfp-resume-writing.md +0 -12
- package/vendors/copilot/plugins/wtfp/commands/wtfp-review-section.md +0 -8
- package/vendors/copilot/plugins/wtfp/commands/wtfp-submit-milestone.md +0 -12
- package/vendors/copilot/plugins/wtfp/commands/wtfp-verify-work.md +6 -4
- package/vendors/copilot/plugins/wtfp/commands/wtfp-write-section.md +2 -12
- package/vendors/copilot/plugins/wtfp/compatibility/action-availability.json +13 -1
- package/vendors/copilot/plugins/wtfp/project/README.md +2 -0
- package/vendors/copilot/plugins/wtfp/roles/research-synthesizer.md +1 -1
- package/vendors/copilot/plugins/wtfp/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/copilot/plugins/wtfp/skills/wtfp-manage-project/references/actions.md +29 -1
- package/vendors/copilot/plugins/wtfp/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/copilot/plugins/wtfp/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/copilot/plugins/wtfp/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/copilot/plugins/wtfp/tools/README.md +1 -1
- package/vendors/copilot/plugins/wtfp/workflows/advance.md +38 -0
- package/vendors/copilot/plugins/wtfp/workflows/discuss-section.md +1 -1
- package/vendors/copilot/plugins/wtfp/workflows/plan-revision.md +3 -3
- package/vendors/copilot/plugins/wtfp/workflows/plan-section.md +1 -1
- package/vendors/copilot/plugins/wtfp/workflows/research-gap.md +3 -3
- package/vendors/copilot/plugins/wtfp/workflows/verify-work.md +4 -2
- package/vendors/copilot/plugins/wtfp/workflows/write-section.md +2 -2
- package/vendors/copilot/project/.github/agents/wtfp-research-synthesizer.agent.md +1 -1
- package/vendors/copilot/project/.github/prompts/wtfp-add-todo.prompt.md +0 -2
- package/vendors/copilot/project/.github/prompts/wtfp-advance.prompt.md +18 -0
- package/vendors/copilot/project/.github/prompts/wtfp-help.prompt.md +1 -1
- package/vendors/copilot/project/.github/prompts/wtfp-list-assumptions.prompt.md +1 -10
- package/vendors/copilot/project/.github/prompts/wtfp-pause-writing.prompt.md +0 -6
- package/vendors/copilot/project/.github/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/copilot/project/.github/skills/wtfp-manage-project/references/actions.md +25 -1
- package/vendors/copilot/project/.github/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/copilot/project/.github/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/copilot/project/.github/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/copilot/project/.github/wtfp/actions/advance.json +232 -0
- package/vendors/copilot/project/.github/wtfp/actions/plan-revision.json +8 -3
- package/vendors/copilot/project/.github/wtfp/actions/verify-work.json +6 -2
- package/vendors/copilot/project/.github/wtfp/aliases.lock.json +1 -0
- package/vendors/copilot/project/.github/wtfp/catalog.json +4 -2
- package/vendors/copilot/project/.github/wtfp/compatibility/action-availability.json +14 -1
- package/vendors/copilot/project/.github/wtfp/project/README.md +2 -0
- package/vendors/copilot/project/.github/wtfp/roles/research-synthesizer.md +1 -1
- package/vendors/copilot/project/.github/wtfp/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/copilot/project/.github/wtfp/skills/wtfp-manage-project/references/actions.md +13 -1
- package/vendors/copilot/project/.github/wtfp/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/copilot/project/.github/wtfp/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/copilot/project/.github/wtfp/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/copilot/project/.github/wtfp/workflows/advance.md +38 -0
- package/vendors/copilot/project/.github/wtfp/workflows/discuss-section.md +1 -1
- package/vendors/copilot/project/.github/wtfp/workflows/plan-revision.md +3 -3
- package/vendors/copilot/project/.github/wtfp/workflows/plan-section.md +1 -1
- package/vendors/copilot/project/.github/wtfp/workflows/research-gap.md +3 -3
- package/vendors/copilot/project/.github/wtfp/workflows/verify-work.md +4 -2
- package/vendors/copilot/project/.github/wtfp/workflows/write-section.md +2 -2
- package/vendors/copilot/project/README.md +1 -1
- package/vendors/gemini/.wtfp-generated.json +60 -48
- package/vendors/gemini/actions/advance.json +232 -0
- package/vendors/gemini/actions/plan-revision.json +8 -3
- package/vendors/gemini/actions/verify-work.json +6 -2
- package/vendors/gemini/agents/wtfp-research-synthesizer.md +1 -1
- package/vendors/gemini/aliases.lock.json +1 -0
- package/vendors/gemini/catalog.json +4 -2
- package/vendors/gemini/commands/wtfp/add-todo.toml +17 -144
- package/vendors/gemini/commands/wtfp/advance.toml +14 -0
- package/vendors/gemini/commands/wtfp/check-todos.toml +17 -2
- package/vendors/gemini/commands/wtfp/checkpoint.toml +17 -735
- package/vendors/gemini/commands/wtfp/create-outline.toml +2 -431
- package/vendors/gemini/commands/wtfp/create-poster.toml +3 -296
- package/vendors/gemini/commands/wtfp/create-slides.toml +3 -296
- package/vendors/gemini/commands/wtfp/discuss-section.toml +4 -259
- package/vendors/gemini/commands/wtfp/execute-outline.toml +2 -480
- package/vendors/gemini/commands/wtfp/help.toml +7 -3
- package/vendors/gemini/commands/wtfp/insert-section.toml +3 -1
- package/vendors/gemini/commands/wtfp/list-assumptions.toml +4 -510
- package/vendors/gemini/commands/wtfp/map-project.toml +2 -0
- package/vendors/gemini/commands/wtfp/new-paper.toml +2 -0
- package/vendors/gemini/commands/wtfp/pause-writing.toml +17 -309
- package/vendors/gemini/commands/wtfp/plan-milestone-gaps.toml +4 -369
- package/vendors/gemini/commands/wtfp/plan-revision.toml +76 -423
- package/vendors/gemini/commands/wtfp/plan-section.toml +4 -624
- package/vendors/gemini/commands/wtfp/polish-prose.toml +4 -329
- package/vendors/gemini/commands/wtfp/progress.toml +18 -1143
- package/vendors/gemini/commands/wtfp/quick.toml +2 -218
- package/vendors/gemini/commands/wtfp/resume-writing.toml +17 -698
- package/vendors/gemini/commands/wtfp/review-section.toml +4 -410
- package/vendors/gemini/commands/wtfp/settings.toml +17 -2
- package/vendors/gemini/commands/wtfp/submit-milestone.toml +2 -617
- package/vendors/gemini/commands/wtfp/verify-work.toml +123 -53
- package/vendors/gemini/commands/wtfp/write-section.toml +4 -482
- package/vendors/gemini/compatibility/action-availability.json +13 -1
- package/vendors/gemini/gemini-extension.json +1 -1
- package/vendors/gemini/project/README.md +2 -0
- package/vendors/gemini/roles/research-synthesizer.md +1 -1
- package/vendors/gemini/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/gemini/skills/wtfp-manage-project/references/actions.md +29 -1
- package/vendors/gemini/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/gemini/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/gemini/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/gemini/tools/README.md +1 -1
- package/vendors/gemini/workflows/advance.md +38 -0
- package/vendors/gemini/workflows/discuss-section.md +1 -1
- package/vendors/gemini/workflows/plan-revision.md +3 -3
- package/vendors/gemini/workflows/plan-section.md +1 -1
- package/vendors/gemini/workflows/research-gap.md +3 -3
- package/vendors/gemini/workflows/verify-work.md +4 -2
- package/vendors/gemini/workflows/write-section.md +2 -2
- package/vendors/opencode/.wtfp-generated.json +59 -47
- package/vendors/opencode/actions/advance.json +232 -0
- package/vendors/opencode/actions/plan-revision.json +8 -3
- package/vendors/opencode/actions/verify-work.json +6 -2
- package/vendors/opencode/agents/wtfp/research-synthesizer.md +1 -1
- package/vendors/opencode/aliases.lock.json +1 -0
- package/vendors/opencode/catalog.json +4 -2
- package/vendors/opencode/commands/wtfp/add-todo.md +17 -144
- package/vendors/opencode/commands/wtfp/advance.md +16 -0
- package/vendors/opencode/commands/wtfp/check-todos.md +17 -2
- package/vendors/opencode/commands/wtfp/checkpoint.md +17 -735
- package/vendors/opencode/commands/wtfp/create-outline.md +2 -431
- package/vendors/opencode/commands/wtfp/create-poster.md +3 -296
- package/vendors/opencode/commands/wtfp/create-slides.md +3 -296
- package/vendors/opencode/commands/wtfp/discuss-section.md +4 -259
- package/vendors/opencode/commands/wtfp/execute-outline.md +2 -480
- package/vendors/opencode/commands/wtfp/help.md +7 -3
- package/vendors/opencode/commands/wtfp/insert-section.md +3 -1
- package/vendors/opencode/commands/wtfp/list-assumptions.md +4 -510
- package/vendors/opencode/commands/wtfp/map-project.md +2 -0
- package/vendors/opencode/commands/wtfp/new-paper.md +2 -0
- package/vendors/opencode/commands/wtfp/pause-writing.md +17 -309
- package/vendors/opencode/commands/wtfp/plan-milestone-gaps.md +4 -369
- package/vendors/opencode/commands/wtfp/plan-revision.md +76 -423
- package/vendors/opencode/commands/wtfp/plan-section.md +4 -624
- package/vendors/opencode/commands/wtfp/polish-prose.md +4 -329
- package/vendors/opencode/commands/wtfp/progress.md +18 -1143
- package/vendors/opencode/commands/wtfp/quick.md +2 -218
- package/vendors/opencode/commands/wtfp/resume-writing.md +17 -698
- package/vendors/opencode/commands/wtfp/review-section.md +4 -410
- package/vendors/opencode/commands/wtfp/settings.md +17 -2
- package/vendors/opencode/commands/wtfp/submit-milestone.md +2 -617
- package/vendors/opencode/commands/wtfp/verify-work.md +123 -53
- package/vendors/opencode/commands/wtfp/write-section.md +4 -482
- package/vendors/opencode/compatibility/action-availability.json +13 -1
- package/vendors/opencode/project/README.md +2 -0
- package/vendors/opencode/roles/research-synthesizer.md +1 -1
- package/vendors/opencode/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/opencode/skills/wtfp-manage-project/references/actions.md +29 -1
- package/vendors/opencode/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/opencode/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/opencode/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/opencode/tools/README.md +1 -1
- package/vendors/opencode/workflows/advance.md +38 -0
- package/vendors/opencode/workflows/discuss-section.md +1 -1
- package/vendors/opencode/workflows/plan-revision.md +3 -3
- package/vendors/opencode/workflows/plan-section.md +1 -1
- package/vendors/opencode/workflows/research-gap.md +3 -3
- package/vendors/opencode/workflows/verify-work.md +4 -2
- package/vendors/opencode/workflows/write-section.md +2 -2
- package/vendors/plugin/.wtfp-generated.json +75 -63
- package/vendors/plugin/actions/advance.json +232 -0
- package/vendors/plugin/actions/plan-revision.json +8 -3
- package/vendors/plugin/actions/verify-work.json +6 -2
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-argument-verifier.md +4 -5
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-citation-expert.md +5 -5
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-citation-formatter.md +3 -3
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-coherence-checker.md +6 -7
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-outliner.md +3 -3
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-plan-checker.md +4 -5
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-prose-polisher.md +4 -4
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-research-synthesizer.md +6 -6
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-section-planner.md +3 -3
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-section-reviewer.md +6 -7
- package/vendors/plugin/ai.iowarp.clio/agents/wtfp-section-writer.md +3 -3
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/add-todo.md +7 -3
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/advance.md +101 -0
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/analyze-bib.md +11 -19
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/audit-milestone.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/check-refs.md +12 -6
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/check-todos.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/checkpoint.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/create-outline.md +11 -19
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/create-poster.md +18 -13
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/create-slides.md +18 -13
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/discuss-section.md +11 -5
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/execute-outline.md +12 -6
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/export-latex.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/help.md +4 -1
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/insert-section.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/list-assumptions.md +15 -17
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/map-project.md +7 -3
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/new-paper.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/pause-writing.md +7 -3
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/plan-milestone-gaps.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/plan-revision.md +13 -7
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/plan-section.md +13 -7
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/polish-prose.md +12 -6
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/progress.md +19 -30
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/quick.md +12 -6
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/research-gap.md +20 -10
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/resume-writing.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/review-section.md +12 -6
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/settings.md +10 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/submit-milestone.md +12 -4
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/verify-work.md +14 -6
- package/vendors/plugin/ai.iowarp.clio/prompts/wtfp/write-section.md +14 -8
- package/vendors/plugin/aliases.lock.json +1 -0
- package/vendors/plugin/catalog.json +4 -2
- package/vendors/plugin/compatibility/action-availability.json +9 -3
- package/vendors/plugin/plugin.json +15 -1
- package/vendors/plugin/project/README.md +2 -0
- package/vendors/plugin/roles/research-synthesizer.md +1 -1
- package/vendors/plugin/skills/wtfp-manage-project/SKILL.md +2 -1
- package/vendors/plugin/skills/wtfp-manage-project/references/actions.md +13 -1
- package/vendors/plugin/skills/wtfp-plan-section/references/actions.md +1 -1
- package/vendors/plugin/skills/wtfp-research-literature/references/actions.md +1 -1
- package/vendors/plugin/skills/wtfp-review-manuscript/references/actions.md +2 -1
- package/vendors/plugin/tools/README.md +1 -1
- package/vendors/plugin/workflows/advance.md +38 -0
- package/vendors/plugin/workflows/discuss-section.md +1 -1
- package/vendors/plugin/workflows/plan-revision.md +3 -3
- package/vendors/plugin/workflows/plan-section.md +1 -1
- package/vendors/plugin/workflows/research-gap.md +3 -3
- package/vendors/plugin/workflows/verify-work.md +4 -2
- package/vendors/plugin/workflows/write-section.md +2 -2
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
renameSync,
|
|
28
28
|
statSync,
|
|
29
29
|
unlinkSync,
|
|
30
|
+
writeFileSync,
|
|
30
31
|
writeSync,
|
|
31
32
|
} from "node:fs";
|
|
32
33
|
import { createRequire } from "node:module";
|
|
@@ -84,7 +85,27 @@ interface CoverageReport {
|
|
|
84
85
|
|
|
85
86
|
const PACKAGE_ROOT = fileURLToPath(new URL("../", import.meta.url));
|
|
86
87
|
const SCHEMAS = path.join(PACKAGE_ROOT, "project", "schemas");
|
|
88
|
+
const TEMPLATES = path.join(PACKAGE_ROOT, "project", "templates");
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The example record of a type, so a model creating one sees every field it
|
|
92
|
+
* needs at once instead of learning them from one refusal per call.
|
|
93
|
+
*/
|
|
94
|
+
function templateFor(type: string): string {
|
|
95
|
+
try {
|
|
96
|
+
return JSON.stringify(JSON.parse(readFileSync(path.join(TEMPLATES, `${type}.json`), "utf8")));
|
|
97
|
+
} catch {
|
|
98
|
+
return "";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function withTemplate(message: string, type: string): string {
|
|
103
|
+
const template = templateFor(type);
|
|
104
|
+
return template ? `${message}\nA ${type} record looks like this example; replace its ids, project_id and content, and omit ${CREATED_AT[type] ? `updated_at and ${CREATED_AT[type]}, which the desk sets` : "updated_at, which the desk sets"}: ${template}` : message;
|
|
105
|
+
}
|
|
87
106
|
interface GuardAction {
|
|
107
|
+
/** The Clio agent IDs of the roles the action's contract delegates to. */
|
|
108
|
+
agents: string[];
|
|
88
109
|
produces: Array<{ uri: string; mode: string }>;
|
|
89
110
|
}
|
|
90
111
|
const GUARD = JSON.parse(readFileSync(new URL("./write-guard.json", import.meta.url), "utf8")) as {
|
|
@@ -152,6 +173,8 @@ interface PlanState {
|
|
|
152
173
|
file: string | null;
|
|
153
174
|
sha256: string | null;
|
|
154
175
|
reason: string;
|
|
176
|
+
/** When the author's sealed approval of these bytes was given. */
|
|
177
|
+
approvedAt?: string;
|
|
155
178
|
}
|
|
156
179
|
|
|
157
180
|
interface SectionRow {
|
|
@@ -166,11 +189,27 @@ interface SectionRow {
|
|
|
166
189
|
claims: { total: number; verified: number; unsupported: number };
|
|
167
190
|
stages: { discuss: boolean; plan: boolean; write: boolean; review: boolean };
|
|
168
191
|
gates: Checkpoint[];
|
|
169
|
-
|
|
192
|
+
/** `claimless`: the record names no live claim that requires evidence, so coverage is vacuous. */
|
|
193
|
+
research: { required: boolean; present: boolean; claimless: boolean };
|
|
170
194
|
dependsOn: string[];
|
|
171
195
|
plan: PlanState;
|
|
172
196
|
unsupported: string[];
|
|
173
197
|
record: Json | null;
|
|
198
|
+
/** The author's acceptance after review, from verify-work and its sealed checkpoint. */
|
|
199
|
+
acceptance: Acceptance;
|
|
200
|
+
/** When the manuscript file was last written, in epoch milliseconds, or null when it does not exist. */
|
|
201
|
+
writtenAt: number | null;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
interface Acceptance {
|
|
205
|
+
/** A review validation or linked review exists for the section. */
|
|
206
|
+
reviewed: boolean;
|
|
207
|
+
/** A verify-work validation is at least as new as the latest review. */
|
|
208
|
+
verified: boolean;
|
|
209
|
+
/** The attested author answer on that validation's acceptance checkpoint, if any. */
|
|
210
|
+
decision: "accept" | "revise" | null;
|
|
211
|
+
/** The note the author attached to that answer, if any. */
|
|
212
|
+
note?: string;
|
|
174
213
|
}
|
|
175
214
|
|
|
176
215
|
interface Finding {
|
|
@@ -204,6 +243,10 @@ interface Desk {
|
|
|
204
243
|
paperExists: boolean;
|
|
205
244
|
journal: boolean;
|
|
206
245
|
coverage: CoverageReport;
|
|
246
|
+
/** The latest milestone audit: fresh when nothing the desk tracks was recorded after it; errors counts its error and blocker issues. */
|
|
247
|
+
audit: { fresh: boolean; errors: number } | null;
|
|
248
|
+
/** A passed submit-milestone validation that no later draft or record outdates. */
|
|
249
|
+
delivered: boolean;
|
|
207
250
|
/** The WTF-P plugin while Clio serves it; null when it is not installed and enabled. */
|
|
208
251
|
served: ServedPlugin;
|
|
209
252
|
}
|
|
@@ -379,6 +422,18 @@ function schemaRegistry(): InstanceType<typeof SchemaRegistry> {
|
|
|
379
422
|
return registry;
|
|
380
423
|
}
|
|
381
424
|
|
|
425
|
+
/** The top-level fields a record type's schema defines. */
|
|
426
|
+
function recordFields(schema: string): Set<string> {
|
|
427
|
+
const match = /^wtfp\.project\.([a-z][a-z0-9-]*)\/v1$/u.exec(schema);
|
|
428
|
+
if (!match) return new Set();
|
|
429
|
+
try {
|
|
430
|
+
const parsed = JSON.parse(readFileSync(path.join(SCHEMAS, `${match[1]}.schema.json`), "utf8")) as Json;
|
|
431
|
+
return new Set(Object.keys((parsed.properties as Json | undefined) ?? {}));
|
|
432
|
+
} catch {
|
|
433
|
+
return new Set();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
382
437
|
/** Schema errors for one record, as the canonical validator reports them. */
|
|
383
438
|
function validateRecord(value: unknown): string[] {
|
|
384
439
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return ["$: planning record must be a JSON object"];
|
|
@@ -456,6 +511,77 @@ function sectionGates(checkpoints: Checkpoint[], id: string, manuscript: string
|
|
|
456
511
|
);
|
|
457
512
|
}
|
|
458
513
|
|
|
514
|
+
// --- the author's acceptance after review -------------------------------------
|
|
515
|
+
|
|
516
|
+
function writtenAt(workspace: string, manuscript: string | null): number | null {
|
|
517
|
+
if (manuscript === null || contained(workspace, manuscript) === null) return null;
|
|
518
|
+
try {
|
|
519
|
+
return statSync(path.join(workspace, manuscript)).mtimeMs;
|
|
520
|
+
} catch {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* A plan the author approved after the manuscript was last written has not
|
|
527
|
+
* been applied yet: a revision plan approved for a reviewed section is drafted
|
|
528
|
+
* before anything reviews or accepts the section again. Answers are stamped to
|
|
529
|
+
* the second, so a write later in the same second counts as applying it.
|
|
530
|
+
*/
|
|
531
|
+
function unappliedPlan(section: SectionRow): boolean {
|
|
532
|
+
if (section.plan.state !== "approved" || !section.plan.approvedAt) return false;
|
|
533
|
+
const approved = Date.parse(section.plan.approvedAt);
|
|
534
|
+
return Number.isFinite(approved) && (section.writtenAt === null || section.writtenAt < approved);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
const ACCEPT = "accept";
|
|
538
|
+
const REVISE = "revise";
|
|
539
|
+
|
|
540
|
+
/** Whether a validation's subject is this section, one of its artifacts, or its manuscript. */
|
|
541
|
+
function validates(record: Json, id: string, manuscriptUri: string): boolean {
|
|
542
|
+
const subject = text(record.subject_uri);
|
|
543
|
+
const section = `project://sections/${id}`;
|
|
544
|
+
return subject === section || subject.startsWith(`${section}/`) || subject === manuscriptUri || subject.startsWith(`${manuscriptUri}/`);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Where a reviewed section stands with its author. Review is critique only;
|
|
549
|
+
* verify-work records the acceptance checks and closes with a checkpoint scoped
|
|
550
|
+
* to its validation, and only an attested answer on that checkpoint counts.
|
|
551
|
+
*/
|
|
552
|
+
/** When the desk wrote each validation record, by file time. */
|
|
553
|
+
const recordedAt = new WeakMap<Json, number>();
|
|
554
|
+
|
|
555
|
+
function acceptanceOf(validations: Json[], checkpoints: Checkpoint[], id: string, manuscriptUri: string, reviewsLinked: boolean, drafted: number | null): Acceptance {
|
|
556
|
+
const mine = validations.filter((record) => validates(record, id, manuscriptUri));
|
|
557
|
+
const latest = (action: string): Json | undefined =>
|
|
558
|
+
mine.filter((record) => record.action_id === action).sort((a, b) => text(b.executed_at).localeCompare(text(a.executed_at)))[0];
|
|
559
|
+
const review = latest("review-section");
|
|
560
|
+
const verify = latest("verify-work");
|
|
561
|
+
// A review counts only for the draft it read: a revision written after it waits for a new review.
|
|
562
|
+
const reviewed = review !== undefined ? drafted === null || (recordedAt.get(review) ?? 0) >= drafted : reviewsLinked && drafted === null;
|
|
563
|
+
const verified = verify !== undefined && (review === undefined || text(verify.executed_at) >= text(review.executed_at));
|
|
564
|
+
if (!verified || verify === undefined) return { reviewed, verified: false, decision: null };
|
|
565
|
+
const answered = checkpoints
|
|
566
|
+
.filter((checkpoint) => checkpoint.scope_uri === `project://validations/${text(verify.id)}` && checkpoint.trust === "attested" && checkpoint.status === "resolved")
|
|
567
|
+
.sort((a, b) => text(b.answer?.answered_at).localeCompare(text(a.answer?.answered_at)))[0];
|
|
568
|
+
const picked = answered?.resolution?.selected_option;
|
|
569
|
+
const note = authorNote(answered);
|
|
570
|
+
return { reviewed, verified: true, decision: picked === ACCEPT || picked === REVISE ? picked : null, ...(note ? { note } : {}) };
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/** How the desk records the text an author attaches to a gate answer, inside the checkpoint's resolution summary. */
|
|
574
|
+
const NOTE_LEAD = " The author's note: ";
|
|
575
|
+
const NOTE_LIMIT = 4000;
|
|
576
|
+
|
|
577
|
+
/** The note an author attached to an answer this desk attested; null when there is none or the answer is not the author's. */
|
|
578
|
+
function authorNote(checkpoint: Checkpoint | undefined): string | null {
|
|
579
|
+
if (!checkpoint || checkpoint.trust !== "attested") return null;
|
|
580
|
+
const summary = checkpoint.resolution?.summary ?? "";
|
|
581
|
+
const at = summary.indexOf(NOTE_LEAD);
|
|
582
|
+
return at < 0 ? null : summary.slice(at + NOTE_LEAD.length).trim() || null;
|
|
583
|
+
}
|
|
584
|
+
|
|
459
585
|
// --- the approved-plan predicate ---------------------------------------------
|
|
460
586
|
|
|
461
587
|
/**
|
|
@@ -483,12 +609,20 @@ function planState(workspace: string, id: string, record: Json | null, checkpoin
|
|
|
483
609
|
const latest = answered[0];
|
|
484
610
|
// An author's explicit answer on this plan decides even when confirm_plan is off: a rejection is never overridden by policy.
|
|
485
611
|
if (latest) {
|
|
486
|
-
if (latest.resolution?.selected_option !== APPROVE || latest.status !== "resolved")
|
|
487
|
-
|
|
612
|
+
if (latest.resolution?.selected_option !== APPROVE || latest.status !== "resolved") {
|
|
613
|
+
const note = authorNote(latest);
|
|
614
|
+
return {
|
|
615
|
+
state: "declined",
|
|
616
|
+
uri,
|
|
617
|
+
file,
|
|
618
|
+
sha256: digest,
|
|
619
|
+
reason: `the author answered "${latest.resolution?.selected_option ?? latest.status}" on ${latest.id}, not approve${note ? `, with this note for the next plan: ${note}` : ""}`,
|
|
620
|
+
};
|
|
621
|
+
}
|
|
488
622
|
const shown = ((latest.answer?.presented as Json | undefined)?.artifact as Json | undefined)?.sha256;
|
|
489
623
|
if (shown !== digest)
|
|
490
624
|
return confirmPlan ? { state: "changed", uri, file, sha256: digest, reason: `the plan changed after the author approved it on ${latest.id}` } : policy;
|
|
491
|
-
return { state: "approved", uri, file, sha256: digest, reason: `approved by the author on ${latest.id}
|
|
625
|
+
return { state: "approved", uri, file, sha256: digest, reason: `approved by the author on ${latest.id}`, approvedAt: text(latest.answer?.answered_at) };
|
|
492
626
|
}
|
|
493
627
|
if (!confirmPlan) return policy;
|
|
494
628
|
if (asked.some((checkpoint) => checkpoint.trust === "pending"))
|
|
@@ -512,11 +646,20 @@ function blockers(desk: Desk, section: SectionRow): string[] {
|
|
|
512
646
|
: `the recorded answer to ${gate.id} was not observed by this desk and must be confirmed`,
|
|
513
647
|
);
|
|
514
648
|
if (!planReady(section.plan)) reasons.push(`${section.plan.reason}`);
|
|
515
|
-
|
|
516
|
-
|
|
649
|
+
const gap = evidenceGap(section);
|
|
650
|
+
if (gap) reasons.push(`${gap}; run research-gap first`);
|
|
517
651
|
return reasons;
|
|
518
652
|
}
|
|
519
653
|
|
|
654
|
+
/** Why a literature-heavy section's evidence does not cover it yet; null when it does or when it needs no research. */
|
|
655
|
+
function evidenceGap(section: SectionRow): string | null {
|
|
656
|
+
if (!section.research.required) return null;
|
|
657
|
+
if (section.unsupported.length > 0)
|
|
658
|
+
return `${section.unsupported.length} required ${section.unsupported.length === 1 ? "claim lacks" : "claims lack"} verified evidence (${section.unsupported.slice(0, 3).join(", ")})`;
|
|
659
|
+
if (section.research.claimless) return "it requires research but records no claim that needs evidence, so no source can be shown to cover it";
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
|
|
520
663
|
// --- loading -----------------------------------------------------------------
|
|
521
664
|
|
|
522
665
|
function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
@@ -571,6 +714,15 @@ function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
|
571
714
|
const sourceRecords = indexed("sources");
|
|
572
715
|
const evidenceRecords = indexed("evidence");
|
|
573
716
|
|
|
717
|
+
const validations = listJson(workspace, ".planning/validations")
|
|
718
|
+
.map((file) => {
|
|
719
|
+
const record = readRecord(workspace, file);
|
|
720
|
+
// The desk writes every record itself, so the file's time is a clock the model cannot set.
|
|
721
|
+
if (record) recordedAt.set(record, writtenAt(workspace, file) ?? 0);
|
|
722
|
+
return record;
|
|
723
|
+
})
|
|
724
|
+
.filter((record): record is Json => record !== null);
|
|
725
|
+
|
|
574
726
|
const outlined = Array.isArray(outline?.sections) ? (outline.sections as Json[]) : [];
|
|
575
727
|
const loaded = outlined.map((entry) => {
|
|
576
728
|
const id = text(entry.id, "section");
|
|
@@ -644,11 +796,17 @@ function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
|
644
796
|
review: reviews.length > 0 || status === "complete",
|
|
645
797
|
},
|
|
646
798
|
gates: sectionGates(checkpoints, id, manuscript),
|
|
647
|
-
research: {
|
|
799
|
+
research: {
|
|
800
|
+
required: research.required === true,
|
|
801
|
+
present: readBytes(workspace, `${base}/research.md`) !== null,
|
|
802
|
+
claimless: !claims.some((claim) => claim.evidence_required === true && claim.status !== "rejected"),
|
|
803
|
+
},
|
|
648
804
|
dependsOn: Array.isArray(entry.depends_on) ? entry.depends_on.filter((dep): dep is string => typeof dep === "string") : [],
|
|
649
805
|
plan: planState(workspace, id, record, checkpoints, confirmPlan),
|
|
650
806
|
unsupported,
|
|
651
807
|
record,
|
|
808
|
+
acceptance: acceptanceOf(validations, checkpoints, id, text(artifacts.manuscript, `project://paper/${id}`), reviews.length > 0, writtenAt(workspace, manuscript)),
|
|
809
|
+
writtenAt: writtenAt(workspace, manuscript),
|
|
652
810
|
};
|
|
653
811
|
});
|
|
654
812
|
const issues = { blocker: 0, error: 0, warning: 0, info: 0 };
|
|
@@ -670,6 +828,8 @@ function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
|
670
828
|
deadline: typeof target.deadline === "string" ? target.deadline : null,
|
|
671
829
|
argument: text(manifest?.core_argument),
|
|
672
830
|
phase: text(state?.phase, manifest ? "initialized" : "none"),
|
|
831
|
+
audit: auditOf(validations, sections),
|
|
832
|
+
delivered: deliveredOf(validations, sections),
|
|
673
833
|
status: text(state?.status, "active"),
|
|
674
834
|
confirmPlan,
|
|
675
835
|
outputFormat,
|
|
@@ -1055,6 +1215,8 @@ const RECORD_URIS: ReadonlyArray<{ pattern: RegExp; type: string; file: (id: str
|
|
|
1055
1215
|
];
|
|
1056
1216
|
const REVISIONED = new Set(["state", "outline", "decisions"]);
|
|
1057
1217
|
const STAMPED = new Set(["state", "outline", "decisions", "manifest", "section"]);
|
|
1218
|
+
/** The time a record type is created at; the desk stamps it on create when the writer leaves it out, since a model has no clock. */
|
|
1219
|
+
const CREATED_AT: Readonly<Record<string, string>> = { validation: "executed_at", checkpoint: "created_at", evidence: "verified_at" };
|
|
1058
1220
|
|
|
1059
1221
|
interface RecordWrite {
|
|
1060
1222
|
uri: string;
|
|
@@ -1185,11 +1347,24 @@ interface Prepared {
|
|
|
1185
1347
|
* answers and its derived counts.
|
|
1186
1348
|
*/
|
|
1187
1349
|
function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk", armed: Armed | null): Prepared {
|
|
1350
|
+
try {
|
|
1351
|
+
return prepareRecord(workspace, input, origin, armed);
|
|
1352
|
+
} catch (error) {
|
|
1353
|
+
// A create refused for its content carries the record's example, so the next call can succeed.
|
|
1354
|
+
const route = RECORD_URIS.find((entry) => entry.pattern.test(input.uri));
|
|
1355
|
+
const creating = route !== undefined && !existsSync(path.join(workspace, route.file(route.pattern.exec(input.uri)?.[1] ?? "")));
|
|
1356
|
+
const content = error instanceof Error && /holds wtfp\.project|whose id is|project_id|belongs to project|would not validate/u.test(error.message);
|
|
1357
|
+
if (creating && content && route) throw new Error(withTemplate((error as Error).message, route.type));
|
|
1358
|
+
throw error;
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
function prepareRecord(workspace: string, input: RecordWrite, origin: "agent" | "desk", armed: Armed | null): Prepared {
|
|
1188
1363
|
const { uri } = input;
|
|
1189
1364
|
const record = input.record;
|
|
1190
1365
|
if (record === null || typeof record !== "object" || Array.isArray(record)) throw new Error(`${uri}: record must be a JSON object`);
|
|
1191
1366
|
const route = RECORD_URIS.find((entry) => entry.pattern.test(uri));
|
|
1192
|
-
if (!route) throw new Error(
|
|
1367
|
+
if (!route) throw new Error(notARecord(uri));
|
|
1193
1368
|
if (route.type === "interaction" && origin === "agent")
|
|
1194
1369
|
throw new Error(`${uri}: only the desk records an author's answer; ask with extension_wtfp__gate`);
|
|
1195
1370
|
const id = route.pattern.exec(uri)?.[1] ?? "";
|
|
@@ -1200,7 +1375,11 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1200
1375
|
const manifest = readRecord(workspace, ".planning/project.json");
|
|
1201
1376
|
const projectId = route.type === "manifest" ? record.id : record.project_id;
|
|
1202
1377
|
if (manifest && typeof manifest.id === "string" && projectId !== manifest.id)
|
|
1203
|
-
throw new Error(
|
|
1378
|
+
throw new Error(
|
|
1379
|
+
projectId === undefined
|
|
1380
|
+
? `${uri} needs project_id "${manifest.id}"`
|
|
1381
|
+
: `${uri} belongs to project ${String(projectId)}, not ${manifest.id}`,
|
|
1382
|
+
);
|
|
1204
1383
|
const bytes = readBytes(workspace, file);
|
|
1205
1384
|
if (bytes === null && existsSync(path.join(workspace, file))) throw new Error(`${file} is not a regular file the desk can replace`);
|
|
1206
1385
|
const priorSha = bytes === null ? null : sha256(bytes);
|
|
@@ -1219,7 +1398,7 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1219
1398
|
if (expectation) throw new Error(`${uri} no longer exists; read the project again before writing`);
|
|
1220
1399
|
} else if (!expectation) {
|
|
1221
1400
|
throw new Error(
|
|
1222
|
-
`${uri} already exists; read it with extension_wtfp__read_record and pass ${REVISIONED.has(route.type) ? "the revision you read as expect_revision" : "the sha256 you read as expect_sha256"} so a newer change is never overwritten`,
|
|
1401
|
+
`${uri} already exists; read it with extension_wtfp__read_record and pass ${REVISIONED.has(route.type) ? "the revision you read as expect_revision" : "the sha256 you read as expect_sha256"} so a newer change is never overwritten, then send the write again. A missing version is not a refusal and does not end the step`,
|
|
1223
1402
|
);
|
|
1224
1403
|
} else {
|
|
1225
1404
|
const byRevision = input.expect_revision !== undefined && REVISIONED.has(route.type) && input.expect_revision === priorRevision;
|
|
@@ -1227,8 +1406,8 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1227
1406
|
if (!byRevision && !bySha)
|
|
1228
1407
|
throw new Error(
|
|
1229
1408
|
REVISIONED.has(route.type) && input.expect_revision !== undefined
|
|
1230
|
-
? `${uri} is at revision ${String(priorRevision)}, not ${input.expect_revision}; read it again
|
|
1231
|
-
: `${uri} changed since it was read; read it again
|
|
1409
|
+
? `${uri} is at revision ${String(priorRevision)}, not ${input.expect_revision}; read it again and send the write again. A stale read is not a refusal and does not end the step`
|
|
1410
|
+
: `${uri} changed since it was read; read it again and send the write again. A stale read is not a refusal and does not end the step`,
|
|
1232
1411
|
);
|
|
1233
1412
|
}
|
|
1234
1413
|
if (origin === "agent" && armed && !declares(armed, uri, bytes === null ? "create" : "update"))
|
|
@@ -1248,8 +1427,15 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1248
1427
|
next.revision = revision;
|
|
1249
1428
|
}
|
|
1250
1429
|
if (STAMPED.has(route.type)) next.updated_at = timestamp();
|
|
1430
|
+
const createdAt = CREATED_AT[route.type];
|
|
1431
|
+
// A model has no clock: an invented time can order a validation before the answer it follows, so the desk's time stands.
|
|
1432
|
+
if (bytes === null && createdAt && (origin === "agent" || next[createdAt] === undefined)) next[createdAt] = timestamp();
|
|
1251
1433
|
const errors = validateRecord(next);
|
|
1252
|
-
|
|
1434
|
+
// Every error at once: a model fixing one per call resends its whole context each time.
|
|
1435
|
+
if (errors.length > 0)
|
|
1436
|
+
throw new Error(
|
|
1437
|
+
`${uri} would not validate: ${errors.slice(0, 8).join("; ")}${errors.length > 8 ? `; and ${errors.length - 8} more` : ""}. Fix these and send the write again; a record that does not validate is not a refusal and does not end the step`,
|
|
1438
|
+
);
|
|
1253
1439
|
const serialized = `${JSON.stringify(next, null, 2)}\n`;
|
|
1254
1440
|
return {
|
|
1255
1441
|
write: { uri, file, text: serialized, sha256: sha256(serialized), revision },
|
|
@@ -1275,12 +1461,19 @@ function normalizeWrites(input: Json): RecordWrite[] {
|
|
|
1275
1461
|
interface Next {
|
|
1276
1462
|
command: string | null;
|
|
1277
1463
|
reason: string;
|
|
1464
|
+
/** The catalog action this step runs, when one does. */
|
|
1465
|
+
action?: string;
|
|
1466
|
+
/** The section the action takes as its input, when it takes one. */
|
|
1467
|
+
section?: string | null;
|
|
1468
|
+
/** The checkpoint that must be answered first, when a gate holds the way. */
|
|
1469
|
+
gate?: string;
|
|
1278
1470
|
}
|
|
1279
1471
|
|
|
1280
1472
|
/** One rung of the ladder; a step only the absent plugin can run says so instead of naming it. */
|
|
1281
|
-
function step(served: ServedPlugin, action: string, args: string, reason: string): Next {
|
|
1473
|
+
function step(served: ServedPlugin, action: string, args: string, reason: string, gate?: string): Next {
|
|
1282
1474
|
const command = commandFor(served, action, args);
|
|
1283
|
-
|
|
1475
|
+
const named = { action, section: args || null, ...(gate ? { gate } : {}) };
|
|
1476
|
+
return command ? { command, reason, ...named } : { command: null, reason: `${reason} Its next step, ${action}, needs the WTF-P plugin.`, ...named };
|
|
1284
1477
|
}
|
|
1285
1478
|
|
|
1286
1479
|
function openGates(desk: Desk): Checkpoint[] {
|
|
@@ -1301,8 +1494,14 @@ function nextAction(desk: Desk): Next {
|
|
|
1301
1494
|
"check-todos",
|
|
1302
1495
|
"",
|
|
1303
1496
|
gate.trust === "pending" ? `Gate waiting on you: ${gate.request}` : `Confirm the recorded answer to ${gate.id}: ${gate.request}`,
|
|
1497
|
+
gate.id,
|
|
1304
1498
|
);
|
|
1305
1499
|
if (desk.sections.length === 0) return step(served, "create-outline", "", "No outline yet.");
|
|
1500
|
+
// new-paper writes an outline but no section records, and only create-outline
|
|
1501
|
+
// declares creating one; every later action may only update it.
|
|
1502
|
+
const unrecorded = desk.sections.filter((section) => section.record === null).map((section) => section.id);
|
|
1503
|
+
if (unrecorded.length > 0)
|
|
1504
|
+
return step(served, "create-outline", "", `The outline lists ${unrecorded.join(", ")} without a section record; create-outline creates them.`);
|
|
1306
1505
|
const complete = new Set(desk.sections.filter((section) => section.status === "complete").map((section) => section.id));
|
|
1307
1506
|
const ordered = [...desk.sections].sort((a, b) => a.wave - b.wave);
|
|
1308
1507
|
for (const section of ordered) {
|
|
@@ -1310,37 +1509,193 @@ function nextAction(desk: Desk): Next {
|
|
|
1310
1509
|
if (!section.dependsOn.every((dep) => complete.has(dep)) && section.status === "not-started") continue;
|
|
1311
1510
|
return sectionNext(served, section);
|
|
1312
1511
|
}
|
|
1313
|
-
if (desk.phase === "delivered") return { command: null, reason: "Delivered." };
|
|
1314
|
-
|
|
1512
|
+
if (desk.phase === "delivered" || desk.delivered) return { command: null, reason: "Delivered: every section is complete, audited and archived; a later change reopens review." };
|
|
1513
|
+
// audit-milestone writes only its validation, so the audit itself, not a phase it cannot set, says the draft is ready.
|
|
1514
|
+
if (desk.phase === "ready" || (desk.audit?.fresh && desk.audit.errors === 0)) return step(served, "submit-milestone", "", "Every section is complete and audited.");
|
|
1515
|
+
if (desk.audit?.fresh)
|
|
1516
|
+
return step(served, "plan-milestone-gaps", "", `The milestone audit found ${desk.audit.errors} ${desk.audit.errors === 1 ? "error" : "errors"} to close before delivery.`);
|
|
1315
1517
|
return step(served, "audit-milestone", "", "Every section is complete; audit before delivery.");
|
|
1316
1518
|
}
|
|
1317
1519
|
|
|
1520
|
+
/**
|
|
1521
|
+
* The latest audit-milestone validation, by the desk's file time. It is fresh
|
|
1522
|
+
* when no other validation and no manuscript was written after it, so an audit
|
|
1523
|
+
* of an earlier draft never stands for the current one.
|
|
1524
|
+
*/
|
|
1525
|
+
function auditOf(validations: Json[], sections: SectionRow[]): Desk["audit"] {
|
|
1526
|
+
const at = (record: Json): number => recordedAt.get(record) ?? 0;
|
|
1527
|
+
const audits = validations.filter((record) => record.action_id === "audit-milestone").sort((a, b) => at(b) - at(a));
|
|
1528
|
+
const latest = audits[0];
|
|
1529
|
+
if (!latest) return null;
|
|
1530
|
+
const later = validations.some((record) => record.action_id !== "audit-milestone" && at(record) > at(latest)) || sections.some((section) => (section.writtenAt ?? 0) > at(latest));
|
|
1531
|
+
const errors = (Array.isArray(latest.issues) ? (latest.issues as Json[]) : []).filter((issue) => issue.severity === "error" || issue.severity === "blocker").length;
|
|
1532
|
+
return { fresh: !later && latest.status !== "failed", errors: latest.status === "failed" ? Math.max(errors, 1) : errors };
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
/** Whether the latest passed milestone submission still stands: nothing but audits and submissions came after it. */
|
|
1536
|
+
function deliveredOf(validations: Json[], sections: SectionRow[]): boolean {
|
|
1537
|
+
const at = (record: Json): number => recordedAt.get(record) ?? 0;
|
|
1538
|
+
const submitted = validations.filter((record) => record.action_id === "submit-milestone" && record.status === "passed").sort((a, b) => at(b) - at(a))[0];
|
|
1539
|
+
if (!submitted) return false;
|
|
1540
|
+
const delivery = new Set(["audit-milestone", "submit-milestone"]);
|
|
1541
|
+
return !validations.some((record) => !delivery.has(text(record.action_id)) && at(record) > at(submitted)) && !sections.some((section) => (section.writtenAt ?? 0) > at(submitted));
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
/** A drafted section's next step: review the current draft, then the author's acceptance or a revision. */
|
|
1545
|
+
function reviewNext(served: ServedPlugin, section: SectionRow): Next {
|
|
1546
|
+
const id = section.id;
|
|
1547
|
+
const acceptance = section.acceptance;
|
|
1548
|
+
if (unappliedPlan(section)) return step(served, "write-section", id, `${section.title} has an approved revision plan that no draft has applied yet.`);
|
|
1549
|
+
if (!acceptance.reviewed) return step(served, "review-section", id, `${section.title} is drafted and waits for review.`);
|
|
1550
|
+
if (!acceptance.verified)
|
|
1551
|
+
return step(served, "verify-work", id, `${section.title} is reviewed; the author checks it against its plan and accepts it or sends it back.`);
|
|
1552
|
+
if (acceptance.decision === REVISE)
|
|
1553
|
+
return step(served, "plan-revision", id, `The author sent ${section.title} back for revision${acceptance.note ? `, with this note: ${acceptance.note}` : "."}`);
|
|
1554
|
+
return step(
|
|
1555
|
+
served,
|
|
1556
|
+
"verify-work",
|
|
1557
|
+
id,
|
|
1558
|
+
acceptance.decision === ACCEPT ? `The author accepted ${section.title}; verify-work marks it complete.` : `${section.title} waits for the author's acceptance.`,
|
|
1559
|
+
);
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1318
1562
|
/** The next step for one section, by the same ladder the band follows. */
|
|
1319
1563
|
function sectionNext(served: ServedPlugin, section: SectionRow): Next {
|
|
1320
1564
|
const id = section.id;
|
|
1321
|
-
if (section.gates.length > 0) return step(served, "check-todos", "", `${section.title} waits on a gate
|
|
1565
|
+
if (section.gates.length > 0) return step(served, "check-todos", "", `${section.title} waits on a gate.`, section.gates[0]?.id);
|
|
1322
1566
|
switch (section.status) {
|
|
1323
1567
|
case "complete":
|
|
1324
1568
|
return step(served, "review-section", id, `${section.title} is complete; review it again if it changed.`);
|
|
1325
1569
|
case "blocked":
|
|
1326
1570
|
return step(served, "check-todos", "", `${section.title} is blocked.`);
|
|
1327
1571
|
case "reviewing":
|
|
1328
|
-
return
|
|
1572
|
+
return reviewNext(served, section);
|
|
1329
1573
|
case "writing":
|
|
1330
1574
|
case "planned":
|
|
1331
|
-
if (section
|
|
1332
|
-
return step(served, "research-gap", id, `${section.title}
|
|
1575
|
+
if (evidenceGap(section))
|
|
1576
|
+
return step(served, "research-gap", id, `${section.title}: ${evidenceGap(section)}.`);
|
|
1333
1577
|
if (!planReady(section.plan))
|
|
1334
1578
|
return step(served, "plan-section", id, `${section.title} cannot be drafted: ${section.plan.reason}.`);
|
|
1579
|
+
// A draft written after its plan's approval is past drafting even when the record still says writing.
|
|
1580
|
+
if (section.plan.state === "approved" && section.plan.approvedAt && section.writtenAt !== null && Date.parse(section.plan.approvedAt) <= section.writtenAt)
|
|
1581
|
+
return reviewNext(served, section);
|
|
1335
1582
|
return step(served, "write-section", id, `${section.title} has an approved plan.`);
|
|
1336
1583
|
default:
|
|
1337
1584
|
if (!section.stages.discuss) return step(served, "discuss-section", id, `Settle what ${section.title} must argue.`);
|
|
1338
|
-
if (section.research.required &&
|
|
1585
|
+
if (section.research.required && !section.research.present)
|
|
1339
1586
|
return step(served, "research-gap", id, `${section.title} needs verified evidence first.`);
|
|
1587
|
+
if (evidenceGap(section))
|
|
1588
|
+
return step(served, "research-gap", id, `${section.title}: ${evidenceGap(section)}.`);
|
|
1340
1589
|
return step(served, "plan-section", id, `${section.title} is ready to plan.`);
|
|
1341
1590
|
}
|
|
1342
1591
|
}
|
|
1343
1592
|
|
|
1593
|
+
// --- driver --------------------------------------------------------------------
|
|
1594
|
+
|
|
1595
|
+
/**
|
|
1596
|
+
* The actions `/wtfp:advance` may chain. Each runs under its own contract; the
|
|
1597
|
+
* driver never runs an action that starts, maps or reshapes the project, since
|
|
1598
|
+
* those are the author's to begin.
|
|
1599
|
+
*/
|
|
1600
|
+
const DRIVEN = new Set(["create-outline", "discuss-section", "research-gap", "plan-section", "write-section", "review-section", "verify-work", "plan-revision", "audit-milestone", "submit-milestone"]);
|
|
1601
|
+
/** Steps one advance run may take before it hands the session back. */
|
|
1602
|
+
const MAX_DRIVE_STEPS = 24;
|
|
1603
|
+
|
|
1604
|
+
/** One `/wtfp:advance` run: the steps the desk armed and the gates it put to the author. */
|
|
1605
|
+
interface Drive {
|
|
1606
|
+
workspace: string;
|
|
1607
|
+
/** `finish`: the step was handed back once to record outputs it skipped. */
|
|
1608
|
+
steps: Array<{ action: string; section: string | null; fingerprint: string; finish?: boolean }>;
|
|
1609
|
+
asked: string[];
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
type DriveDecision =
|
|
1613
|
+
| { kind: "step"; action: string; section: string | null; prompt: string; reason: string; finish?: boolean }
|
|
1614
|
+
| { kind: "gate"; checkpoint: string; reason: string }
|
|
1615
|
+
| { kind: "stop"; reason: string };
|
|
1616
|
+
|
|
1617
|
+
/** What the project looks like to the ladder; an unchanged fingerprint means a step changed nothing it reads. */
|
|
1618
|
+
function driveFingerprint(desk: Desk): string {
|
|
1619
|
+
return sha256(
|
|
1620
|
+
JSON.stringify({
|
|
1621
|
+
phase: desk.phase,
|
|
1622
|
+
status: desk.status,
|
|
1623
|
+
sections: desk.sections.map((section) => [
|
|
1624
|
+
section.id,
|
|
1625
|
+
section.status,
|
|
1626
|
+
section.stages,
|
|
1627
|
+
section.plan.state,
|
|
1628
|
+
section.plan.sha256,
|
|
1629
|
+
section.unsupported,
|
|
1630
|
+
section.research,
|
|
1631
|
+
section.words,
|
|
1632
|
+
section.recorded,
|
|
1633
|
+
section.acceptance,
|
|
1634
|
+
section.gates.map((gate) => [gate.id, gate.status, gate.trust]),
|
|
1635
|
+
]),
|
|
1636
|
+
checkpoints: desk.checkpoints.map((checkpoint) => [checkpoint.id, checkpoint.status, checkpoint.trust]),
|
|
1637
|
+
sources: desk.sources,
|
|
1638
|
+
evidence: desk.evidence,
|
|
1639
|
+
}),
|
|
1640
|
+
);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/**
|
|
1644
|
+
* The driver's next move, chosen by the same ladder `progress` follows. The
|
|
1645
|
+
* desk, never the model, picks the action and section; the model only runs it.
|
|
1646
|
+
*/
|
|
1647
|
+
function driveStep(desk: Desk, drive: Drive): DriveDecision {
|
|
1648
|
+
if (!desk.present)
|
|
1649
|
+
return { kind: "stop", reason: "There is no WTF-P project here yet. Start one with new-paper, or map-project for an existing manuscript; advance continues a project, it never starts one." };
|
|
1650
|
+
const next = nextAction(desk);
|
|
1651
|
+
if (next.gate) {
|
|
1652
|
+
if (drive.asked.includes(next.gate)) return { kind: "stop", reason: `${next.gate} is still waiting on you. ${next.reason}` };
|
|
1653
|
+
return { kind: "gate", checkpoint: next.gate, reason: next.reason };
|
|
1654
|
+
}
|
|
1655
|
+
if (!next.action || next.action === "check-todos") return { kind: "stop", reason: next.reason };
|
|
1656
|
+
if (!DRIVEN.has(next.action))
|
|
1657
|
+
return { kind: "stop", reason: `${next.reason} The next action, ${next.command ?? next.action}, starts or reshapes the project, so it is yours to run.` };
|
|
1658
|
+
if (next.command === null) return { kind: "stop", reason: next.reason };
|
|
1659
|
+
if (!GUARD.actions[next.action]) return { kind: "stop", reason: `${next.action} is not available on this host, so the desk cannot arm it.` };
|
|
1660
|
+
if (drive.steps.length >= MAX_DRIVE_STEPS)
|
|
1661
|
+
return { kind: "stop", reason: `This run took ${MAX_DRIVE_STEPS} steps, its limit. Run advance again to continue from ${next.command}.` };
|
|
1662
|
+
const section = next.section ?? null;
|
|
1663
|
+
const fingerprint = driveFingerprint(desk);
|
|
1664
|
+
const last = drive.steps[drive.steps.length - 1];
|
|
1665
|
+
if (last && last.action === next.action && last.section === section && last.fingerprint === fingerprint) {
|
|
1666
|
+
// Live, review-section reported findings and skipped its review record; one hand-back names what to record.
|
|
1667
|
+
const creates = (GUARD.actions[next.action]?.produces ?? []).filter((output) => output.mode === "create").map((output) => output.uri.replace("{section}", section ?? "{section}"));
|
|
1668
|
+
if (!last.finish && creates.length > 0)
|
|
1669
|
+
return {
|
|
1670
|
+
kind: "step",
|
|
1671
|
+
action: next.action,
|
|
1672
|
+
section,
|
|
1673
|
+
prompt: `ai.iowarp.clio/prompts/wtfp/${next.action}.md`,
|
|
1674
|
+
reason: `Continue ${next.command}; it has not failed. It recorded nothing the next step depends on, so record its outputs for what it found, whatever the outcome (${creates.join(", ")}), then call extension_wtfp__next_step. Do not repeat its work.`,
|
|
1675
|
+
finish: true,
|
|
1676
|
+
};
|
|
1677
|
+
return { kind: "stop", reason: `${next.command} ran and changed nothing the next step depends on, so the desk stops instead of repeating it. ${next.reason}` };
|
|
1678
|
+
}
|
|
1679
|
+
return { kind: "step", action: next.action, section, prompt: `ai.iowarp.clio/prompts/wtfp/${next.action}.md`, reason: next.reason };
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
/**
|
|
1683
|
+
* Every next_step result ends with this rule, so a turn Clio compacted after
|
|
1684
|
+
* dropping the advance prompt can still continue from the last result alone.
|
|
1685
|
+
*/
|
|
1686
|
+
const DRIVER_RULE =
|
|
1687
|
+
"Driver rule for this /wtfp:advance run: the desk, not you, picks every step, so finish the step it armed and call extension_wtfp__next_step with after naming that step (\"start\" for the first call), call extension_wtfp__gate with the checkpoint it names and then extension_wtfp__next_step, and on a stop, a failed step or a refused call report the steps taken and end the turn without choosing another action.";
|
|
1688
|
+
|
|
1689
|
+
/** Where a step's prompt lives, stated so it survives the loss of the advance prompt's resolved plugin root. */
|
|
1690
|
+
function stepPrompt(prompt: string): string {
|
|
1691
|
+
return `<plugin root>/${prompt}, where <plugin root> is the WTF-P plugin root (two directories above the base_dir of the loaded wtfp-manage-project skill; the prompt's \${pluginRoot} paths mean that root)`;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
/** The arming of an advance run between steps: nothing may be written until the desk arms a step. */
|
|
1695
|
+
function idleArm(workspace: string): Armed {
|
|
1696
|
+
return { action: "advance", produces: [], section: null, workspace };
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1344
1699
|
function meter(words: number, target: number, cells = 8): string {
|
|
1345
1700
|
if (target <= 0) return "";
|
|
1346
1701
|
const filled = Math.max(0, Math.min(cells, Math.round((words / target) * cells)));
|
|
@@ -1743,6 +2098,11 @@ function planGate(checkpoint: Checkpoint): boolean {
|
|
|
1743
2098
|
return new RegExp(`^project://sections/${IDENTIFIER}/plans/${IDENTIFIER}$`, "u").test(checkpoint.scope_uri);
|
|
1744
2099
|
}
|
|
1745
2100
|
|
|
2101
|
+
/** verify-work's closing question: an acceptance checkpoint scoped to its validation. */
|
|
2102
|
+
function acceptanceGate(checkpoint: Checkpoint): boolean {
|
|
2103
|
+
return new RegExp(`^project://validations/${IDENTIFIER}$`, "u").test(checkpoint.scope_uri) && (checkpoint.options ?? []).some((option) => option.id === ACCEPT);
|
|
2104
|
+
}
|
|
2105
|
+
|
|
1746
2106
|
/**
|
|
1747
2107
|
* The words the author sees for an option. On a plan gate the desk owns them:
|
|
1748
2108
|
* `approve` is what authorizes drafting, so it always reads as approval and
|
|
@@ -1753,6 +2113,12 @@ function shown(checkpoint: Checkpoint, option: { id: string; label: string; impl
|
|
|
1753
2113
|
if (option.id === APPROVE) return { label: "Approve this plan as shown", detail: "Drafting may start from exactly these plan bytes; any later change asks you again." };
|
|
1754
2114
|
if (/approv/iu.test(option.label)) return { label: `Do not draft from this plan yet (${option.id})`, detail: "Any answer but approval leaves the plan unapproved." };
|
|
1755
2115
|
}
|
|
2116
|
+
// Only `accept` completes a section, so only it reads as acceptance.
|
|
2117
|
+
if (acceptanceGate(checkpoint)) {
|
|
2118
|
+
if (option.id === ACCEPT) return { label: "Accept this section as written", detail: "It is marked complete; a later change needs review and your acceptance again." };
|
|
2119
|
+
if (option.id === REVISE) return { label: "Send it back for revision", detail: "The next step plans a revision for you to approve." };
|
|
2120
|
+
if (/accept/iu.test(option.label)) return { label: `Do not accept it yet (${option.id})`, detail: "Any answer but accept leaves the section unaccepted." };
|
|
2121
|
+
}
|
|
1756
2122
|
return { label: option.label, ...(option.implication ? { detail: option.implication } : {}) };
|
|
1757
2123
|
}
|
|
1758
2124
|
|
|
@@ -1771,7 +2137,7 @@ function subjectOf(workspace: string, desk: Desk, checkpoint: Checkpoint): { uri
|
|
|
1771
2137
|
return bytes === null ? null : { uri: checkpoint.scope_uri, sha256: sha256(bytes) };
|
|
1772
2138
|
}
|
|
1773
2139
|
|
|
1774
|
-
async function ask(ctx: ExtensionContextV2, desk: Desk, checkpoint: Checkpoint): Promise<InterviewStep> {
|
|
2140
|
+
async function ask(ctx: ExtensionContextV2, desk: Desk, checkpoint: Checkpoint, hint?: string): Promise<InterviewStep> {
|
|
1775
2141
|
const nonce = randomBytes(6).toString("hex");
|
|
1776
2142
|
const artifact = subjectOf(ctx.snapshot.workspace, desk, checkpoint);
|
|
1777
2143
|
const offered = [...choices(checkpoint), { value: KEEP, label: "Keep it pending", detail: "Answer later; its writes stay blocked." }];
|
|
@@ -1795,6 +2161,7 @@ async function ask(ctx: ExtensionContextV2, desk: Desk, checkpoint: Checkpoint):
|
|
|
1795
2161
|
t: "box",
|
|
1796
2162
|
dir: "col",
|
|
1797
2163
|
children: [
|
|
2164
|
+
...(hint ? [{ t: "text", text: hint, tone: "warning", wrap: "wrap" } as View] : []),
|
|
1798
2165
|
...(checkpoint.context ? [{ t: "text", text: checkpoint.context, wrap: "wrap" } as View] : []),
|
|
1799
2166
|
...(confirming
|
|
1800
2167
|
? [{ t: "text", text: `Recorded as "${recorded}" by the author, but this desk did not see that answer. Confirm it or choose again.`, tone: "warning", wrap: "wrap" } as View]
|
|
@@ -1825,7 +2192,7 @@ type AnswerResult = { kind: "recorded" | "kept" | "stale" | "refused"; text: str
|
|
|
1825
2192
|
* author was offered for this exact checkpoint, project and subject, and only
|
|
1826
2193
|
* once: the binding is consumed before anything is written.
|
|
1827
2194
|
*/
|
|
1828
|
-
async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown): Promise<AnswerResult> {
|
|
2195
|
+
async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown, note: string | null = null): Promise<AnswerResult> {
|
|
1829
2196
|
const workspace = ctx.snapshot.workspace;
|
|
1830
2197
|
const nonce = /^gate\.([a-f0-9]{12})$/u.exec(stepKey)?.[1];
|
|
1831
2198
|
const asked = nonce ? (await ctx.state.get<Asked>(`ask:${nonce}`)).value : undefined;
|
|
@@ -1866,6 +2233,7 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1866
2233
|
key,
|
|
1867
2234
|
);
|
|
1868
2235
|
const writes: Array<{ input: RecordWrite }> = [{ input: { uri: `project://interactions/${String(interaction.id)}`, record: interaction } }];
|
|
2236
|
+
let linkedIn: string | null = null;
|
|
1869
2237
|
if (!stale && picked !== KEEP) {
|
|
1870
2238
|
const { file: _file, trust: _trust, answer: _answer, ...stored } = checkpoint;
|
|
1871
2239
|
writes.push({
|
|
@@ -1878,11 +2246,13 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1878
2246
|
resolution: {
|
|
1879
2247
|
resolved_by: "author",
|
|
1880
2248
|
...(option ? { selected_option: option.id } : {}),
|
|
1881
|
-
summary:
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
2249
|
+
summary: `${
|
|
2250
|
+
option
|
|
2251
|
+
? `The author chose "${shown(checkpoint, option).label}" at the Clio WTF-P desk.`
|
|
2252
|
+
: picked === WAIVE
|
|
2253
|
+
? "The author waived this gate at the Clio WTF-P desk."
|
|
2254
|
+
: "The author marked this done at the Clio WTF-P desk."
|
|
2255
|
+
}${note ? `${NOTE_LEAD}${note}` : ""}`,
|
|
1886
2256
|
resolved_at: now,
|
|
1887
2257
|
},
|
|
1888
2258
|
},
|
|
@@ -1898,6 +2268,30 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1898
2268
|
record: { ...state, active_checkpoint_uris: (state.active_checkpoint_uris as string[]).filter((entry) => entry !== uri) },
|
|
1899
2269
|
},
|
|
1900
2270
|
});
|
|
2271
|
+
// The author's approval links the plan in the same commit: live, the model asked the desk for its next
|
|
2272
|
+
// step before linking, and the approved plan sat unlinked while the driver planned again.
|
|
2273
|
+
const planned = option?.id === APPROVE && planGate(checkpoint) ? /^project:\/\/sections\/([^/]+)\/plans\//u.exec(checkpoint.scope_uri)?.[1] : undefined;
|
|
2274
|
+
const sectionFile = planned ? `.planning/sections/${planned}/section.json` : null;
|
|
2275
|
+
const section = sectionFile ? readRecord(workspace, sectionFile) : null;
|
|
2276
|
+
if (planned && sectionFile && section) {
|
|
2277
|
+
const artifacts = isObject(section.artifacts) ? section.artifacts : {};
|
|
2278
|
+
const plans = Array.isArray(artifacts.plans) ? (artifacts.plans as unknown[]) : [];
|
|
2279
|
+
if (plans[plans.length - 1] !== checkpoint.scope_uri) {
|
|
2280
|
+
linkedIn = `project://sections/${planned}`;
|
|
2281
|
+
const status = text(section.status, "not-started");
|
|
2282
|
+
writes.push({
|
|
2283
|
+
input: {
|
|
2284
|
+
uri: `project://sections/${planned}`,
|
|
2285
|
+
expect_sha256: sha256(readBytes(workspace, sectionFile) ?? ""),
|
|
2286
|
+
record: {
|
|
2287
|
+
...section,
|
|
2288
|
+
status: status === "not-started" ? "planned" : status,
|
|
2289
|
+
artifacts: { ...artifacts, plans: [...plans.filter((entry) => entry !== checkpoint.scope_uri), checkpoint.scope_uri] },
|
|
2290
|
+
},
|
|
2291
|
+
},
|
|
2292
|
+
});
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
1901
2295
|
}
|
|
1902
2296
|
withLock(workspace, () => {
|
|
1903
2297
|
recover(workspace);
|
|
@@ -1915,7 +2309,12 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1915
2309
|
if (picked === KEEP) return { kind: "kept", text: `${checkpoint.id}: kept pending`, checkpoint: checkpoint.id };
|
|
1916
2310
|
return {
|
|
1917
2311
|
kind: "recorded",
|
|
1918
|
-
text: option ? `${checkpoint.id}: ${shown(checkpoint, option).label}` : `${checkpoint.id}: ${picked === WAIVE ? "waived" : "done"}
|
|
2312
|
+
text: `${option ? `${checkpoint.id}: ${shown(checkpoint, option).label}` : `${checkpoint.id}: ${picked === WAIVE ? "waived" : "done"}`}${
|
|
2313
|
+
linkedIn ? `. The desk linked ${checkpoint.scope_uri} in ${linkedIn} with this answer; do not link it again` : ""
|
|
2314
|
+
}. The desk wrote ${writes
|
|
2315
|
+
.slice(1)
|
|
2316
|
+
.map((entry) => entry.input.uri)
|
|
2317
|
+
.join(", ")}; read any of them again before writing it`,
|
|
1919
2318
|
checkpoint: checkpoint.id,
|
|
1920
2319
|
};
|
|
1921
2320
|
}
|
|
@@ -1941,6 +2340,31 @@ function choiceOf(answers: Record<string, string | string[]>): unknown {
|
|
|
1941
2340
|
return Array.isArray(choice) ? (choice.length === 1 ? choice[0] : undefined) : choice;
|
|
1942
2341
|
}
|
|
1943
2342
|
|
|
2343
|
+
/** The text the author attached to their chosen option, bounded; null when none. */
|
|
2344
|
+
function noteOf(event: { notes?: Record<string, string> }): string | null {
|
|
2345
|
+
const note = event.notes?.choice?.replace(/\s+/gu, " ").trim() ?? "";
|
|
2346
|
+
return note ? note.slice(0, NOTE_LIMIT) : null;
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
const FREE_TEXT = "A typed answer names no option, so nothing was recorded. Choose an option and attach your text to it with [n] note.";
|
|
2350
|
+
|
|
2351
|
+
/**
|
|
2352
|
+
* A gate answered with free text instead of an option. Nothing is recorded and
|
|
2353
|
+
* the question's binding is spent; the text goes back with how to send it.
|
|
2354
|
+
*/
|
|
2355
|
+
async function freeText(ctx: ExtensionContextV2, event: { step: string; answers: Record<string, string | string[]>; other?: Record<string, true> }): Promise<AnswerResult | null> {
|
|
2356
|
+
if (event.other?.choice !== true) return null;
|
|
2357
|
+
const nonce = /^gate\.([a-f0-9]{12})$/u.exec(event.step)?.[1];
|
|
2358
|
+
const asked = nonce ? (await ctx.state.get<Asked>(`ask:${nonce}`)).value : undefined;
|
|
2359
|
+
if (nonce) await ctx.state.delete(`ask:${nonce}`);
|
|
2360
|
+
const typed = String(choiceOf(event.answers) ?? "").replace(/\s+/gu, " ").trim().slice(0, NOTE_LIMIT);
|
|
2361
|
+
return {
|
|
2362
|
+
kind: "refused",
|
|
2363
|
+
text: `The author typed an answer instead of choosing an option, so nothing was recorded and the gate stays pending. Ask again; the author chooses an option and attaches their text with [n] note.${typed ? ` They wrote: "${typed}"` : ""}`,
|
|
2364
|
+
...(asked ? { checkpoint: asked.checkpoint } : {}),
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
|
|
1944
2368
|
// --- confirmations of weakening record writes --------------------------------
|
|
1945
2369
|
|
|
1946
2370
|
interface PendingConfirm {
|
|
@@ -2002,6 +2426,20 @@ async function armedFor(ctx: ExtensionContextV2): Promise<Armed | null> {
|
|
|
2002
2426
|
async function recordTool(ctx: ExtensionContextV2, input: Json): Promise<{ text: string; data?: unknown; isError?: boolean; interview?: { id: string; title: string; total: number; step: InterviewStep } }> {
|
|
2003
2427
|
const workspace = ctx.snapshot.workspace;
|
|
2004
2428
|
const armed = await armedFor(ctx);
|
|
2429
|
+
// The manifest lets unknown top-level keys through so the desk, not the gateway, can say where they belong:
|
|
2430
|
+
// a long record whose object closed early leaves its last fields beside it.
|
|
2431
|
+
const stray = Object.keys(input).filter((key) => !["uri", "record", "expect_revision", "expect_sha256", "writes"].includes(key));
|
|
2432
|
+
let folded: string[] = [];
|
|
2433
|
+
if (stray.length > 0) {
|
|
2434
|
+
const record = input.record !== null && typeof input.record === "object" && !Array.isArray(input.record) ? (input.record as Json) : null;
|
|
2435
|
+
const fields = record ? recordFields(text(record.schema)) : new Set<string>();
|
|
2436
|
+
// Fields the record's own schema defines and the record lacks are folded in; validation still judges the result.
|
|
2437
|
+
if (!record || stray.some((key) => !fields.has(key) || key in record))
|
|
2438
|
+
throw new Error(`${stray.join(", ")} ${stray.length === 1 ? "is not a record tool argument" : "are not record tool arguments"}; if ${stray.length === 1 ? "it is a field" : "they are fields"} of the record, put ${stray.length === 1 ? "it" : "them"} inside record and send the call again`);
|
|
2439
|
+
input = { ...input, record: { ...record, ...Object.fromEntries(stray.map((key) => [key, input[key]])) } };
|
|
2440
|
+
for (const key of stray) delete input[key];
|
|
2441
|
+
folded = stray;
|
|
2442
|
+
}
|
|
2005
2443
|
const writes = normalizeWrites(input);
|
|
2006
2444
|
const uris = writes.map((write) => write.uri);
|
|
2007
2445
|
if (new Set(uris).size !== uris.length) throw new Error("each record may appear once in writes");
|
|
@@ -2027,6 +2465,7 @@ async function recordTool(ctx: ExtensionContextV2, input: Json): Promise<{ text:
|
|
|
2027
2465
|
return {
|
|
2028
2466
|
text: [
|
|
2029
2467
|
...(recovered ? [recovered] : []),
|
|
2468
|
+
...(folded.length > 0 ? [`${folded.join(", ")} arrived beside record and were moved inside it; send record fields inside record.`] : []),
|
|
2030
2469
|
...done.map((write) => `Wrote ${write.uri}${write.revision === null ? "" : ` at revision ${write.revision}`}; it validated and read back (sha256 ${write.sha256}).`),
|
|
2031
2470
|
...(done.length > 1 ? ["They committed together."] : []),
|
|
2032
2471
|
].join(" "),
|
|
@@ -2037,15 +2476,100 @@ async function recordTool(ctx: ExtensionContextV2, input: Json): Promise<{ text:
|
|
|
2037
2476
|
};
|
|
2038
2477
|
}
|
|
2039
2478
|
|
|
2479
|
+
/**
|
|
2480
|
+
* Authored artifacts keep their own format and are read and written with
|
|
2481
|
+
* Clio's file tools; a refusal names the conventional file so the model does
|
|
2482
|
+
* not search the workspace for it.
|
|
2483
|
+
*/
|
|
2484
|
+
const ARTIFACT_URIS: ReadonlyArray<{ pattern: RegExp; file: (match: RegExpExecArray) => string }> = [
|
|
2485
|
+
{ pattern: new RegExp(`^project://sections/(${IDENTIFIER})/(context|research|summary|handoff)$`, "u"), file: (m) => `.planning/sections/${m[1]}/${m[2]}.md` },
|
|
2486
|
+
{ pattern: new RegExp(`^project://sections/(${IDENTIFIER})/(plans|reviews)/(${IDENTIFIER})$`, "u"), file: (m) => `.planning/sections/${m[1]}/${m[2]}/${m[3]}.md` },
|
|
2487
|
+
{ pattern: /^project:\/\/paper\/([^\s]+)$/u, file: (m) => `paper/${m[1]}` },
|
|
2488
|
+
];
|
|
2489
|
+
|
|
2490
|
+
function notARecord(uri: string): string {
|
|
2491
|
+
for (const artifact of ARTIFACT_URIS) {
|
|
2492
|
+
const match = artifact.pattern.exec(uri);
|
|
2493
|
+
if (match) return `${uri} is an authored artifact, not a JSON record; read or write ${artifact.file(match)} with the file tools`;
|
|
2494
|
+
}
|
|
2495
|
+
const family = /^project:\/\/(sections|sources|evidence|checkpoints|validations)\/([^/]+)$/u.exec(uri);
|
|
2496
|
+
if (family && !new RegExp(`^${IDENTIFIER}$`, "u").test(family[2] ?? ""))
|
|
2497
|
+
return `${uri} has an invalid id; record ids are lowercase letters and digits joined by single hyphens, such as ${(family[2] ?? "").toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-+|-+$/gu, "") || "outline-gate"}`;
|
|
2498
|
+
return `${uri} is not a logical record URI this adapter maps`;
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/** How much record JSON one family read returns before it names the rest by id. */
|
|
2502
|
+
const FAMILY_LIMIT = 48 * 1024;
|
|
2503
|
+
|
|
2504
|
+
/**
|
|
2505
|
+
* Every record of one family, such as `project://sources`, in one call: each
|
|
2506
|
+
* as a single read returns it, until the family outgrows FAMILY_LIMIT; the
|
|
2507
|
+
* rest are named so they can be read one at a time.
|
|
2508
|
+
*/
|
|
2509
|
+
function readFamily(ctx: ExtensionContextV2, desk: Desk, collection: string, after: string | null = null): { text: string; data: unknown } {
|
|
2510
|
+
const workspace = ctx.snapshot.workspace;
|
|
2511
|
+
const identifier = new RegExp(`^${IDENTIFIER}$`, "u");
|
|
2512
|
+
let ids: string[];
|
|
2513
|
+
if (collection === "sections") {
|
|
2514
|
+
const directory = contained(workspace, ".planning/sections");
|
|
2515
|
+
ids =
|
|
2516
|
+
directory === null || !existsSync(directory) || !lstatSync(directory).isDirectory()
|
|
2517
|
+
? []
|
|
2518
|
+
: readdirSync(directory, { withFileTypes: true })
|
|
2519
|
+
.filter((entry) => entry.isDirectory() && identifier.test(entry.name) && readBytes(workspace, `.planning/sections/${entry.name}/section.json`) !== null)
|
|
2520
|
+
.map((entry) => entry.name)
|
|
2521
|
+
.sort();
|
|
2522
|
+
} else ids = listJson(workspace, `.planning/${collection}`).map((file) => path.posix.basename(file, ".json")).filter((id) => identifier.test(id));
|
|
2523
|
+
const records: unknown[] = [];
|
|
2524
|
+
const omitted: string[] = [];
|
|
2525
|
+
const failed: string[] = [];
|
|
2526
|
+
let size = 0;
|
|
2527
|
+
const total = ids.length;
|
|
2528
|
+
if (after !== null) ids = ids.filter((id) => id > after);
|
|
2529
|
+
for (const id of ids) {
|
|
2530
|
+
if (omitted.length > 0) {
|
|
2531
|
+
omitted.push(id);
|
|
2532
|
+
continue;
|
|
2533
|
+
}
|
|
2534
|
+
let one: { data: unknown };
|
|
2535
|
+
try {
|
|
2536
|
+
one = readTool(ctx, desk, `project://${collection}/${id}`);
|
|
2537
|
+
} catch (error) {
|
|
2538
|
+
failed.push(`${id} (${error instanceof Error ? error.message : String(error)})`);
|
|
2539
|
+
continue;
|
|
2540
|
+
}
|
|
2541
|
+
const length = JSON.stringify(one.data).length;
|
|
2542
|
+
if (records.length > 0 && size + length > FAMILY_LIMIT) {
|
|
2543
|
+
omitted.push(id);
|
|
2544
|
+
continue;
|
|
2545
|
+
}
|
|
2546
|
+
records.push(one.data);
|
|
2547
|
+
size += length;
|
|
2548
|
+
}
|
|
2549
|
+
const uri = `project://${collection}`;
|
|
2550
|
+
return {
|
|
2551
|
+
text: [
|
|
2552
|
+
total === 0 ? `${uri} holds no records yet.` : `${uri} holds ${total} ${total === 1 ? "record" : "records"}; ${records.length}${after !== null ? ` after ${after}` : ""} returned in full, each with the revision and sha256 to pass back to record.`,
|
|
2553
|
+
omitted.length > 0 ? `${omitted.length} more not returned, to keep this read small; read the next page with ${uri}?after=${String((records[records.length - 1] as Json | undefined)?.uri ?? "").split("/").pop()}.` : "",
|
|
2554
|
+
failed.length > 0 ? `Not readable: ${failed.join("; ")}.` : "",
|
|
2555
|
+
]
|
|
2556
|
+
.filter(Boolean)
|
|
2557
|
+
.join(" "),
|
|
2558
|
+
data: { uri, records, omitted, ...(failed.length > 0 ? { failed } : {}) },
|
|
2559
|
+
};
|
|
2560
|
+
}
|
|
2561
|
+
|
|
2040
2562
|
function readTool(ctx: ExtensionContextV2, desk: Desk, uri: string): { text: string; data: unknown } {
|
|
2041
2563
|
const workspace = ctx.snapshot.workspace;
|
|
2564
|
+
const family = new RegExp(`^project://(sections|sources|evidence|checkpoints|validations|interactions)/?\\*?(?:\\?after=(${IDENTIFIER}))?$`, "u").exec(uri);
|
|
2565
|
+
if (family) return readFamily(ctx, desk, family[1] as string, family[2] ?? null);
|
|
2042
2566
|
const route = RECORD_URIS.find((entry) => entry.pattern.test(uri));
|
|
2043
|
-
if (!route) throw new Error(
|
|
2567
|
+
if (!route) throw new Error(notARecord(uri));
|
|
2044
2568
|
const file = route.file(route.pattern.exec(uri)?.[1] ?? "");
|
|
2045
2569
|
const bytes = readBytes(workspace, file);
|
|
2046
2570
|
if (bytes === null) {
|
|
2047
2571
|
if (contained(workspace, file) === null) throw new Error(`${uri} is reached through a symbolic link; the desk does not follow links`);
|
|
2048
|
-
return { text: `${uri} does not exist yet; create it without expect_revision or expect_sha256.`, data: { uri, file, exists: false } };
|
|
2572
|
+
return { text: withTemplate(`${uri} does not exist yet; create it without expect_revision or expect_sha256.`, route.type), data: { uri, file, exists: false } };
|
|
2049
2573
|
}
|
|
2050
2574
|
let record: unknown;
|
|
2051
2575
|
try {
|
|
@@ -2061,7 +2585,57 @@ function readTool(ctx: ExtensionContextV2, desk: Desk, uri: string): { text: str
|
|
|
2061
2585
|
};
|
|
2062
2586
|
}
|
|
2063
2587
|
|
|
2064
|
-
|
|
2588
|
+
/**
|
|
2589
|
+
* An immutable milestone snapshot: every `.planning` file outside the archives
|
|
2590
|
+
* and every `paper/` file, copied byte for byte under
|
|
2591
|
+
* `.planning/archives/<archive>/` beside a manifest of their sha256 digests.
|
|
2592
|
+
* Live, a model could not copy a whole project by hand within a turn. Only an
|
|
2593
|
+
* armed action that declares the archive may make one, links are never
|
|
2594
|
+
* followed, and an existing archive is never touched.
|
|
2595
|
+
*/
|
|
2596
|
+
function archiveProject(workspace: string, archive: string, armed: Armed | null, projectId: string | null): { uri: string; files: number; manifest: string; sha256: string } {
|
|
2597
|
+
if (!new RegExp(`^${IDENTIFIER}$`, "u").test(archive)) throw new Error(`${archive} is not a valid archive id; use lowercase letters and digits joined by single hyphens`);
|
|
2598
|
+
const uri = `project://archives/${archive}`;
|
|
2599
|
+
if (!armed || !declares(armed, `${uri}/manifest.json`, "archive"))
|
|
2600
|
+
throw new Error(`${armed ? armed.action : "nothing armed"} does not declare archiving ${uri}; only the action that owns a milestone archive may make one`);
|
|
2601
|
+
return withLock(workspace, () => {
|
|
2602
|
+
recover(workspace);
|
|
2603
|
+
const target = `.planning/archives/${archive}`;
|
|
2604
|
+
const destination = contained(workspace, target);
|
|
2605
|
+
if (destination === null) throw new Error(`${target} is reached through a symbolic link; the desk does not follow links`);
|
|
2606
|
+
if (existsSync(destination)) throw new Error(`${uri} already exists, and an archive is immutable; choose another id`);
|
|
2607
|
+
const files: Array<{ path: string; sha256: string; bytes: number }> = [];
|
|
2608
|
+
const walk = (relative: string): void => {
|
|
2609
|
+
const directory = contained(workspace, relative);
|
|
2610
|
+
if (directory === null || !existsSync(directory) || !lstatSync(directory).isDirectory()) return;
|
|
2611
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
2612
|
+
const child = path.posix.join(relative, entry.name);
|
|
2613
|
+
if (entry.name.startsWith(".") || child === ".planning/archives" || entry.isSymbolicLink()) continue;
|
|
2614
|
+
if (entry.isDirectory()) walk(child);
|
|
2615
|
+
else if (entry.isFile()) {
|
|
2616
|
+
const bytes = readBytes(workspace, child);
|
|
2617
|
+
if (bytes === null) throw new Error(`${child} could not be read whole, so the archive would be incomplete`);
|
|
2618
|
+
files.push({ path: child, sha256: sha256(bytes), bytes: bytes.length });
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
};
|
|
2622
|
+
walk(".planning");
|
|
2623
|
+
walk("paper");
|
|
2624
|
+
const staging = `${destination}.staging-${randomBytes(4).toString("hex")}`;
|
|
2625
|
+
mkdirSync(staging, { recursive: true });
|
|
2626
|
+
for (const file of files) {
|
|
2627
|
+
const out = path.join(staging, file.path);
|
|
2628
|
+
mkdirSync(path.dirname(out), { recursive: true });
|
|
2629
|
+
writeFileSync(out, readFileSync(path.join(workspace, file.path)));
|
|
2630
|
+
}
|
|
2631
|
+
const manifest = `${JSON.stringify({ archive: uri, project_id: projectId, created_at: timestamp(), files }, null, 2)}\n`;
|
|
2632
|
+
writeFileSync(path.join(staging, "manifest.json"), manifest);
|
|
2633
|
+
renameSync(staging, destination);
|
|
2634
|
+
return { uri, files: files.length, manifest: `${target}/manifest.json`, sha256: sha256(manifest) };
|
|
2635
|
+
});
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
function measureSection(workspace: string, sectionId: string, key: Buffer | null, armed: Armed | null): { words: number; target: number; file: string | null; total: number; recorded: boolean } {
|
|
2065
2639
|
return withLock(workspace, () => {
|
|
2066
2640
|
recover(workspace);
|
|
2067
2641
|
const desk = loadDesk(workspace, key);
|
|
@@ -2081,9 +2655,12 @@ function measureSection(workspace: string, sectionId: string, key: Buffer | null
|
|
|
2081
2655
|
expect_revision: typeof state.revision === "number" ? state.revision : 0,
|
|
2082
2656
|
record: { ...state, progress: { ...(state.progress as Json), word_count: recorded } },
|
|
2083
2657
|
});
|
|
2658
|
+
// An action that may not update these records still gets the desk's count, so it never counts by hand.
|
|
2659
|
+
if (armed && !writes.every((write) => declares(armed, write.uri, "update")))
|
|
2660
|
+
return { words: section.words, target: section.target, file: section.manuscript, total: recorded, recorded: false };
|
|
2084
2661
|
const prepared = writes.map((write) => prepare(workspace, write, "agent", armed));
|
|
2085
2662
|
commit(workspace, prepared.map((entry) => entry.write));
|
|
2086
|
-
return { words: section.words, target: section.target, file: section.manuscript, total: recorded };
|
|
2663
|
+
return { words: section.words, target: section.target, file: section.manuscript, total: recorded, recorded: true };
|
|
2087
2664
|
});
|
|
2088
2665
|
}
|
|
2089
2666
|
|
|
@@ -2166,6 +2743,71 @@ function progressText(desk: Desk): string {
|
|
|
2166
2743
|
].join("\n");
|
|
2167
2744
|
}
|
|
2168
2745
|
|
|
2746
|
+
/**
|
|
2747
|
+
* The project as one compact record for an agent: what an action would
|
|
2748
|
+
* otherwise reconstruct from many record reads. It reports, never decides;
|
|
2749
|
+
* an action still reads the records it will change or quote.
|
|
2750
|
+
*/
|
|
2751
|
+
function statusDigest(desk: Desk): Json {
|
|
2752
|
+
const next = nextAction(desk);
|
|
2753
|
+
return {
|
|
2754
|
+
present: desk.present,
|
|
2755
|
+
...(desk.present
|
|
2756
|
+
? {
|
|
2757
|
+
project: { id: desk.projectId, title: desk.title, document_type: desk.documentType, venue: desk.venue, deadline: desk.deadline, argument: desk.argument },
|
|
2758
|
+
phase: desk.phase,
|
|
2759
|
+
status: desk.status,
|
|
2760
|
+
words: { total: totalWords(desk), target: desk.targetWords, method: WORD_METHOD },
|
|
2761
|
+
sections: desk.sections.map((section) => ({
|
|
2762
|
+
id: section.id,
|
|
2763
|
+
title: section.title,
|
|
2764
|
+
wave: section.wave,
|
|
2765
|
+
status: section.status,
|
|
2766
|
+
depends_on: section.dependsOn,
|
|
2767
|
+
words: section.words,
|
|
2768
|
+
target: section.target,
|
|
2769
|
+
manuscript: section.manuscript,
|
|
2770
|
+
stages: section.stages,
|
|
2771
|
+
plan: { state: section.plan.state, uri: section.plan.uri, reason: section.plan.reason },
|
|
2772
|
+
research_required: section.research.required,
|
|
2773
|
+
claims: section.claims,
|
|
2774
|
+
unsupported_claims: section.unsupported,
|
|
2775
|
+
blockers: blockers(desk, section),
|
|
2776
|
+
})),
|
|
2777
|
+
open_gates: openGates(desk).map((gate) => ({ id: gate.id, kind: gate.kind, scope: gate.scope_uri, request: gate.request, trust: gate.trust })),
|
|
2778
|
+
evidence: { sources: desk.sources, evidence: desk.evidence },
|
|
2779
|
+
issues: desk.issues,
|
|
2780
|
+
invalid_records: desk.invalid.map((entry) => entry.file),
|
|
2781
|
+
interrupted_write: desk.journal,
|
|
2782
|
+
}
|
|
2783
|
+
: {}),
|
|
2784
|
+
next: { action: next.action ?? null, section: next.section ?? null, gate: next.gate ?? null, command: next.command, reason: next.reason },
|
|
2785
|
+
};
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
/** Clio refuses effect text longer than this many UTF-16 code units. */
|
|
2789
|
+
const EFFECT_TEXT_LIMIT = 2000;
|
|
2790
|
+
|
|
2791
|
+
/** Text cut to Clio's effect limit with `tail` appended, never splitting a surrogate pair. */
|
|
2792
|
+
function clip(message: string, tail: string): string {
|
|
2793
|
+
if (message.length <= EFFECT_TEXT_LIMIT) return message;
|
|
2794
|
+
let end = EFFECT_TEXT_LIMIT - tail.length;
|
|
2795
|
+
const last = message.charCodeAt(end - 1);
|
|
2796
|
+
if (last >= 0xd800 && last <= 0xdbff) end -= 1;
|
|
2797
|
+
return `${message.slice(0, end)}${tail}`;
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
/** The desk's status as one reminder within Clio's effect limit. */
|
|
2801
|
+
function statusReminder(desk: Desk): string {
|
|
2802
|
+
const gates = openGates(desk);
|
|
2803
|
+
const lines = [
|
|
2804
|
+
"WTF-P desk status at the start of this turn (extension_wtfp__status returns it as structured data):",
|
|
2805
|
+
progressText(desk),
|
|
2806
|
+
...(gates.length > 0 ? [`Open gates: ${gates.map((gate) => `${gate.id} (${gate.scope_uri.replace(/^project:\/\//u, "")})`).join(", ")}`] : []),
|
|
2807
|
+
];
|
|
2808
|
+
return clip(lines.join("\n"), "\n… (truncated; call extension_wtfp__status)");
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2169
2811
|
function helpCard(served: ServedPlugin): { text: string; card: View } {
|
|
2170
2812
|
const availability = JSON.parse(
|
|
2171
2813
|
readFileSync(path.join(PACKAGE_ROOT, "compatibility", "action-availability.json"), "utf8"),
|
|
@@ -2528,7 +3170,9 @@ async function guardWrite(ctx: ExtensionContextV2, target: string, host?: HostTa
|
|
|
2528
3170
|
const roots = writeRoots(desk, armed);
|
|
2529
3171
|
if (!roots.some((allowed) => under(allowed, relative)))
|
|
2530
3172
|
return block(
|
|
2531
|
-
|
|
3173
|
+
armed.action === "advance"
|
|
3174
|
+
? `WTF-P write guard: nothing is armed between /wtfp:advance steps; refused ${relative}. Call extension_wtfp__next_step; it arms the step that may write, and that step's own prompt says what it writes.`
|
|
3175
|
+
: `WTF-P write guard: ${actionName(served, armed.action)}${armed.section ? ` ${armed.section}` : ""} may write only under ${roots.join(", ") || "nothing (it declares no file outputs)"}; refused ${relative}. Record other changes as a handoff instead.`,
|
|
2532
3176
|
);
|
|
2533
3177
|
}
|
|
2534
3178
|
for (const section of desk.sections) {
|
|
@@ -2697,6 +3341,13 @@ async function guardDispatch(ctx: ExtensionContextV2, args: Json, host?: HostDis
|
|
|
2697
3341
|
return {};
|
|
2698
3342
|
}
|
|
2699
3343
|
const name = actionName(served, armed.action);
|
|
3344
|
+
// Inside an action that delegates, a writing worker is one of its roles; a call without agent falls to Clio's default worker.
|
|
3345
|
+
const agents = GUARD.actions[armed.action]?.agents ?? [];
|
|
3346
|
+
const stranger = agents.length > 0 ? entries.find((entry) => !entry.readOnly && !agents.includes(entry.agent)) : undefined;
|
|
3347
|
+
if (stranger)
|
|
3348
|
+
return block(
|
|
3349
|
+
`WTF-P dispatch guard: ${name} delegates only to ${agents.join(", ")}, and this call would start ${stranger.agent}; name the role with agent (for example agent: "${agents.find((agent) => GUARD.paperWriters.includes(agent)) ?? agents[0]}").`,
|
|
3350
|
+
);
|
|
2700
3351
|
// A worker never gets a root that holds records: the record tool is the only way records change.
|
|
2701
3352
|
const base = writeRoots(desk, armed).filter((root) => ![".", ".planning", ".planning/sections"].includes(root.replace(/\/$/u, "")));
|
|
2702
3353
|
const held = heldManuscripts(desk);
|
|
@@ -2720,7 +3371,9 @@ async function guardDispatch(ctx: ExtensionContextV2, args: Json, host?: HostDis
|
|
|
2720
3371
|
const roots = entry.roots === null ? allowed : narrow(entry.roots, allowed);
|
|
2721
3372
|
if (paperWriters.has(entry.agent) && !roots.some((root) => root.startsWith("paper/")))
|
|
2722
3373
|
throw new Error(
|
|
2723
|
-
|
|
3374
|
+
entry.roots !== null && allowed.some((root) => root.startsWith("paper/"))
|
|
3375
|
+
? `WTF-P dispatch guard: ${entry.agent} names write_roots ${entry.roots.join(", ")}, which reach no manuscript ${name} may write; give it intent.write_roots ${allowed.join(", ")} (workspace paths, not project:// URIs).`
|
|
3376
|
+
: `WTF-P dispatch guard: ${entry.agent} would have no manuscript it may write. ${notes.length > 0 ? notes.join(" · ") : "Name the section and approve its plan first."}`,
|
|
2724
3377
|
);
|
|
2725
3378
|
if (roots.length > 0) return roots;
|
|
2726
3379
|
// Clio reads an empty write_roots as no boundary at all, so an empty list is refused, never sent.
|
|
@@ -2748,6 +3401,16 @@ async function guardDispatch(ctx: ExtensionContextV2, args: Json, host?: HostDis
|
|
|
2748
3401
|
.map((entry, index) => `task ${index + 1} (${entry.agent}): ${(narrowed[index] ?? []).join(", ") || "none, it only reads"}`)
|
|
2749
3402
|
.join("; ")}.`,
|
|
2750
3403
|
);
|
|
3404
|
+
// Clio admits an extension's rewrite only as a narrowing. A declared intent without write roots is an empty
|
|
3405
|
+
// write ceiling there, although the worker itself treats it as no boundary, so the desk cannot fill the roots in.
|
|
3406
|
+
const declaresEmpty = (item: unknown): boolean =>
|
|
3407
|
+
isObject(item) && isObject(item.intent) && (!Array.isArray(item.intent.write_roots) || item.intent.write_roots.length === 0);
|
|
3408
|
+
if (declaresEmpty(args) || (Array.isArray(args.tasks) && args.tasks.some(declaresEmpty)))
|
|
3409
|
+
return block(
|
|
3410
|
+
`WTF-P dispatch guard: an intent without write_roots bounds nothing for the worker, and Clio will not let the desk fill them in. Send ${entries
|
|
3411
|
+
.map((entry, index) => `${entries.length > 1 ? `task ${index + 1} (${entry.agent}) ` : ""}intent.write_roots ${(needed[index] ?? []).join(", ") || "omitted, since it only reads"}`)
|
|
3412
|
+
.join("; ")} in that intent.`,
|
|
3413
|
+
);
|
|
2751
3414
|
const rewritten = confineCall(args, needed);
|
|
2752
3415
|
return {
|
|
2753
3416
|
effects: [
|
|
@@ -2764,6 +3427,31 @@ const BASH_DESK_PATHS = /\.planning\/(?:interactions\b|\.wtfp-)/u;
|
|
|
2764
3427
|
/** Tools that run a command or script; the desk can only refuse ones that name its own records. */
|
|
2765
3428
|
const COMMAND_TOOLS = new Set(["bash", "run_script", "job"]);
|
|
2766
3429
|
|
|
3430
|
+
/**
|
|
3431
|
+
* Inside a WTF-P action every question is the author's. Clio answers an
|
|
3432
|
+
* unanswered `ask_user` round with its recommended option after
|
|
3433
|
+
* `safety.unattendedAfterSeconds`, unless the question is `operator_only`, so
|
|
3434
|
+
* the desk marks a lone question that way and refuses a round that would need
|
|
3435
|
+
* splitting, since an `operator_only` question is asked alone.
|
|
3436
|
+
*/
|
|
3437
|
+
async function guardQuestions(ctx: ExtensionContextV2, input: Json): Promise<ExtensionHookResult> {
|
|
3438
|
+
if (input.action === "complete") return {};
|
|
3439
|
+
const questions = Array.isArray(input.questions) ? (input.questions as unknown[]) : [];
|
|
3440
|
+
if (questions.length === 0 || questions.every((question) => (question as Json | null)?.operator_only === true)) return {};
|
|
3441
|
+
if (!(await armedFor(ctx))) return {};
|
|
3442
|
+
if (questions.length > 1)
|
|
3443
|
+
return block("WTF-P: inside a WTF-P action each question is the author's to answer. Ask them one call at a time, each with operator_only: true and its own options, so Clio never answers one for an absent author.");
|
|
3444
|
+
return {
|
|
3445
|
+
effects: [
|
|
3446
|
+
{
|
|
3447
|
+
kind: "rewrite_tool_input",
|
|
3448
|
+
args: { ...input, questions: [{ ...(questions[0] as Json), operator_only: true }] },
|
|
3449
|
+
reason: "WTF-P asks the author, and only the author may answer: Clio never takes a recommended option for this question.",
|
|
3450
|
+
},
|
|
3451
|
+
],
|
|
3452
|
+
};
|
|
3453
|
+
}
|
|
3454
|
+
|
|
2767
3455
|
async function guard(ctx: ExtensionContextV2, tool: string, args: unknown, event: unknown = {}): Promise<ExtensionHookResult> {
|
|
2768
3456
|
const input = args !== null && typeof args === "object" ? (args as Json) : {};
|
|
2769
3457
|
const effects: ExtensionEffect[] = [];
|
|
@@ -2778,6 +3466,7 @@ async function guard(ctx: ExtensionContextV2, tool: string, args: unknown, event
|
|
|
2778
3466
|
// A host that sends facts once sends them for every call it can resolve, so a later call without them failed in Clio.
|
|
2779
3467
|
if ((host.target || host.dispatch) && !(await ctx.state.get<boolean>("host-facts")).value) await ctx.state.set("host-facts", true);
|
|
2780
3468
|
if (tool === "dispatch") result = await guardDispatch(ctx, input, host.dispatch, host.malformed);
|
|
3469
|
+
else if (tool === "ask_user") result = await guardQuestions(ctx, input);
|
|
2781
3470
|
else if (COMMAND_TOOLS.has(tool)) {
|
|
2782
3471
|
if (BASH_DESK_PATHS.test(JSON.stringify(input))) result = block("WTF-P write guard: commands may not touch the desk's own records under .planning.");
|
|
2783
3472
|
} else {
|
|
@@ -2792,9 +3481,48 @@ async function guard(ctx: ExtensionContextV2, tool: string, args: unknown, event
|
|
|
2792
3481
|
return effects.length === 0 ? result : { ...result, effects: [...effects, ...(result.effects ?? [])] };
|
|
2793
3482
|
}
|
|
2794
3483
|
|
|
3484
|
+
/**
|
|
3485
|
+
* A note on a successful write or edit that changed a manuscript the armed
|
|
3486
|
+
* action may measure: its recorded word count is stale until measure_section
|
|
3487
|
+
* runs. It rides on the tool result, so it spends none of the turn's shared
|
|
3488
|
+
* continuation budget, and it reaches a dispatched worker too, whose writes
|
|
3489
|
+
* Clio hooks, so it says whose call the measurement is. Each section is noted
|
|
3490
|
+
* once until it is measured again.
|
|
3491
|
+
*/
|
|
3492
|
+
async function noteManuscriptWrite(ctx: ExtensionContextV2, event: unknown): Promise<ExtensionHookResult> {
|
|
3493
|
+
const armed = await armedFor(ctx);
|
|
3494
|
+
if (!armed || !armed.produces.some((output) => output.uri.startsWith("project://paper/"))) return {};
|
|
3495
|
+
const target = hostLanding(event).target;
|
|
3496
|
+
if (!target) return {};
|
|
3497
|
+
const landed = writeLanding("", ctx.snapshot.workspace, target);
|
|
3498
|
+
if ("refused" in landed || landed.relative === null || !under("paper", landed.relative)) return {};
|
|
3499
|
+
const desk = loadDesk(ctx.snapshot.workspace);
|
|
3500
|
+
const noted = (await ctx.state.get<string[]>("measure-noted")).value ?? [];
|
|
3501
|
+
const sections = sectionsForPaper(desk, landed.relative)
|
|
3502
|
+
.map((section) => section.id)
|
|
3503
|
+
.filter((id) => !noted.includes(id) && declares(armed, `project://sections/${id}`, "update"));
|
|
3504
|
+
if (sections.length === 0) return {};
|
|
3505
|
+
await ctx.state.set("measure-noted", [...noted, ...sections]);
|
|
3506
|
+
const calls = sections.map((id) => `gateway(op="call", capability="extension_wtfp__measure_section", args={section: "${id}"})`).join(" and ");
|
|
3507
|
+
return {
|
|
3508
|
+
effects: [
|
|
3509
|
+
{
|
|
3510
|
+
kind: "annotate_tool_result",
|
|
3511
|
+
severity: "info",
|
|
3512
|
+
message: clip(
|
|
3513
|
+
`WTF-P: ${landed.relative} is the manuscript of ${sections.join(", ")}, so the desk's recorded word count is stale. When drafting it is done, the WTF-P action records the count with ${calls}; never count words by hand. A dispatched worker leaves this call to the action that dispatched it.`,
|
|
3514
|
+
"…",
|
|
3515
|
+
),
|
|
3516
|
+
},
|
|
3517
|
+
],
|
|
3518
|
+
};
|
|
3519
|
+
}
|
|
3520
|
+
|
|
2795
3521
|
function arm(text: string, desk: Desk, workspace: string): Armed | null {
|
|
2796
3522
|
const match = /^\s*\/wtfp:([a-z][a-z0-9-]*)(?:\s+(\S+))?/u.exec(text);
|
|
2797
3523
|
if (!match) return null;
|
|
3524
|
+
// The driver arms nothing itself; next_step arms each step it selects.
|
|
3525
|
+
if (match[1] === "advance") return GUARD.actions.advance ? idleArm(workspace) : null;
|
|
2798
3526
|
const action = GUARD.actions[match[1] as string];
|
|
2799
3527
|
if (!action) return null;
|
|
2800
3528
|
const candidate = match[2] ?? "";
|
|
@@ -2830,6 +3558,12 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2830
3558
|
return next.command ? { text: next.command, prompt: { fill: next.command } } : { text: next.reason, toast: { text: next.reason } };
|
|
2831
3559
|
});
|
|
2832
3560
|
api.action("gates", async (_event, ctx) => startGates(ctx));
|
|
3561
|
+
api.action("advance", async (_event, ctx) => {
|
|
3562
|
+
const command = commandFor(ctx.snapshot.plugin ?? null, "advance");
|
|
3563
|
+
return command
|
|
3564
|
+
? { text: command, prompt: { fill: command } }
|
|
3565
|
+
: { text: "advance needs the WTF-P plugin.", toast: { text: "advance needs the WTF-P plugin." } };
|
|
3566
|
+
});
|
|
2833
3567
|
api.action("validate", async (_event, ctx) => validateAll(ctx));
|
|
2834
3568
|
api.action("help", async (_event, ctx) => helpCard(ctx.snapshot.plugin ?? null));
|
|
2835
3569
|
api.action("section", async (event, ctx) => {
|
|
@@ -2851,6 +3585,10 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2851
3585
|
return { text: failure("Not written", error), isError: true };
|
|
2852
3586
|
}
|
|
2853
3587
|
});
|
|
3588
|
+
api.tool("status", async (_input, ctx) => {
|
|
3589
|
+
const desk = await deskFor(ctx);
|
|
3590
|
+
return { text: progressText(desk), data: statusDigest(desk) };
|
|
3591
|
+
});
|
|
2854
3592
|
api.tool("read_record", async (input, ctx) => {
|
|
2855
3593
|
try {
|
|
2856
3594
|
return readTool(ctx, await deskFor(ctx), String((input as Json).uri ?? ""));
|
|
@@ -2872,18 +3610,72 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2872
3610
|
return { text: `No readiness: ${error instanceof Error ? error.message : String(error)}`, isError: true };
|
|
2873
3611
|
}
|
|
2874
3612
|
});
|
|
3613
|
+
api.tool("archive", async (input, ctx) => {
|
|
3614
|
+
try {
|
|
3615
|
+
const desk = await deskFor(ctx);
|
|
3616
|
+
const made = archiveProject(ctx.snapshot.workspace, String((input as Json).archive ?? ""), await armedFor(ctx), desk.projectId);
|
|
3617
|
+
return {
|
|
3618
|
+
text: `Archived ${made.files} files to ${made.uri}; its manifest ${made.manifest} has sha256 ${made.sha256} and lists each file's sha256. Record the archive in the manifest and state as the procedure says.`,
|
|
3619
|
+
data: made,
|
|
3620
|
+
};
|
|
3621
|
+
} catch (error) {
|
|
3622
|
+
return { text: failure("Not archived", error), isError: true };
|
|
3623
|
+
}
|
|
3624
|
+
});
|
|
2875
3625
|
api.tool("measure_section", async (input, ctx) => {
|
|
2876
3626
|
try {
|
|
2877
|
-
const
|
|
3627
|
+
const sectionId = String((input as Json).section ?? "");
|
|
3628
|
+
const measured = measureSection(ctx.snapshot.workspace, sectionId, await storedKey(ctx, false), await armedFor(ctx));
|
|
3629
|
+
const noted = (await ctx.state.get<string[]>("measure-noted")).value ?? [];
|
|
3630
|
+
if (noted.includes(sectionId)) await ctx.state.set("measure-noted", noted.filter((id) => id !== sectionId));
|
|
2878
3631
|
const share = measured.target > 0 ? Math.round((measured.words / measured.target) * 100) : null;
|
|
2879
3632
|
return {
|
|
2880
|
-
text: `${measured.file ?? "the manuscript"} has ${measured.words} body words${share === null ? "" : ` (${share}% of ${measured.target}; within 15% counts as on target)`}. Recorded in the section and state records, which committed together; the paper totals ${measured.total}. ${WORD_METHOD}`,
|
|
3633
|
+
text: `${measured.file ?? "the manuscript"} has ${measured.words} body words${share === null ? "" : ` (${share}% of ${measured.target}; within 15% counts as on target)`}. ${measured.recorded ? `Recorded in the section and state records, which committed together; the paper totals ${measured.total}.` : `Not recorded: ${actionName(ctx.snapshot.plugin ?? null, (await armedFor(ctx))?.action ?? "this action")} does not update the section's word count; use this count instead of counting by hand.`} ${WORD_METHOD}`,
|
|
2881
3634
|
data: measured,
|
|
2882
3635
|
};
|
|
2883
3636
|
} catch (error) {
|
|
2884
3637
|
return { text: failure("Not measured", error), isError: true };
|
|
2885
3638
|
}
|
|
2886
3639
|
});
|
|
3640
|
+
api.tool("next_step", async (_input, ctx) => {
|
|
3641
|
+
const workspace = ctx.snapshot.workspace;
|
|
3642
|
+
const drive = (await ctx.state.get<Drive>("drive")).value;
|
|
3643
|
+
if (!drive || drive.workspace !== workspace)
|
|
3644
|
+
return { text: "Only a /wtfp:advance turn can ask the desk for its next step; nothing was armed.", isError: true };
|
|
3645
|
+
let desk = await deskFor(ctx);
|
|
3646
|
+
let recovered: string | null = null;
|
|
3647
|
+
if (desk.journal) {
|
|
3648
|
+
try {
|
|
3649
|
+
recovered = withLock(workspace, () => recover(workspace));
|
|
3650
|
+
} catch (error) {
|
|
3651
|
+
await ctx.state.set("armed", idleArm(workspace));
|
|
3652
|
+
return { text: `${failure("An interrupted record write could not be completed, so the run stops", error)} ${DRIVER_RULE}`, data: { kind: "stop" }, isError: true };
|
|
3653
|
+
}
|
|
3654
|
+
desk = await deskFor(ctx);
|
|
3655
|
+
}
|
|
3656
|
+
const decision = driveStep(desk, drive);
|
|
3657
|
+
const lead = recovered ? `${recovered} ` : "";
|
|
3658
|
+
if (decision.kind !== "step") {
|
|
3659
|
+
// Between steps and after the last one, nothing stays armed for writing.
|
|
3660
|
+
await ctx.state.set("armed", idleArm(workspace));
|
|
3661
|
+
if (decision.kind === "gate") {
|
|
3662
|
+
await ctx.state.set("drive", { ...drive, asked: [...drive.asked, decision.checkpoint] } satisfies Drive);
|
|
3663
|
+
return { text: `${lead}Gate ${decision.checkpoint}: ${decision.reason} Call extension_wtfp__gate with checkpoint ${decision.checkpoint}. ${DRIVER_RULE}`, data: decision };
|
|
3664
|
+
}
|
|
3665
|
+
return { text: `${lead}Stop: ${decision.reason} ${DRIVER_RULE}`, data: decision };
|
|
3666
|
+
}
|
|
3667
|
+
const contract = GUARD.actions[decision.action] as GuardAction;
|
|
3668
|
+
await ctx.state.set("armed", { action: decision.action, produces: contract.produces, section: decision.section, workspace } satisfies Armed);
|
|
3669
|
+
await ctx.state.set("drive", {
|
|
3670
|
+
...drive,
|
|
3671
|
+
steps: [...drive.steps, { action: decision.action, section: decision.section, fingerprint: driveFingerprint(desk), ...(decision.finish ? { finish: true } : {}) }],
|
|
3672
|
+
} satisfies Drive);
|
|
3673
|
+
const invocation = `/wtfp:${decision.action}${decision.section ? ` ${decision.section}` : ""}`;
|
|
3674
|
+
return {
|
|
3675
|
+
text: `${lead}Step ${drive.steps.length + 1}: ${invocation}. ${decision.reason} The write guard is armed for ${decision.action}${decision.section ? ` ${decision.section}` : ""} only. Read and follow ${stepPrompt(decision.prompt)} with ${decision.section ? `invocation input ${decision.section}` : "no invocation input"}. ${DRIVER_RULE}`,
|
|
3676
|
+
data: decision,
|
|
3677
|
+
};
|
|
3678
|
+
});
|
|
2887
3679
|
api.tool("gate", async (input, ctx) => {
|
|
2888
3680
|
const id = String((input as Json).checkpoint ?? "");
|
|
2889
3681
|
const desk = await deskFor(ctx);
|
|
@@ -2902,7 +3694,13 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2902
3694
|
: "The author did not answer; the gate stays pending.",
|
|
2903
3695
|
};
|
|
2904
3696
|
try {
|
|
2905
|
-
const
|
|
3697
|
+
const typed = await freeText(ctx, event);
|
|
3698
|
+
if (typed?.checkpoint) {
|
|
3699
|
+
const desk = await deskFor(ctx);
|
|
3700
|
+
const current = desk.checkpoints.find((entry) => entry.id === typed.checkpoint);
|
|
3701
|
+
if (current && askable(desk, []).includes(current)) return { step: await ask(ctx, desk, current, FREE_TEXT), total: 1 };
|
|
3702
|
+
}
|
|
3703
|
+
const result = typed ?? (await answer(ctx, event.step, choiceOf(event.answers), noteOf(event)));
|
|
2906
3704
|
if (result.kind === "stale" && result.checkpoint) {
|
|
2907
3705
|
const desk = await deskFor(ctx);
|
|
2908
3706
|
const current = desk.checkpoints.find((entry) => entry.id === result.checkpoint);
|
|
@@ -2927,7 +3725,14 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2927
3725
|
const recorded = (await ctx.state.get<string[]>("gate-recorded")).value ?? [];
|
|
2928
3726
|
let note = "";
|
|
2929
3727
|
try {
|
|
2930
|
-
const
|
|
3728
|
+
const typed = await freeText(ctx, event);
|
|
3729
|
+
if (typed?.checkpoint) {
|
|
3730
|
+
const desk = await deskFor(ctx);
|
|
3731
|
+
const current = desk.checkpoints.find((entry) => entry.id === typed.checkpoint);
|
|
3732
|
+
const remaining = askable(desk, kept);
|
|
3733
|
+
if (current && remaining.includes(current)) return { step: await ask(ctx, desk, current, FREE_TEXT), total: remaining.length + recorded.length + kept.length };
|
|
3734
|
+
}
|
|
3735
|
+
const result = typed ?? (await answer(ctx, event.step, choiceOf(event.answers), noteOf(event)));
|
|
2931
3736
|
if (result.kind === "recorded") recorded.push(result.text);
|
|
2932
3737
|
else if (result.kind === "kept" && result.checkpoint) kept.push(result.checkpoint);
|
|
2933
3738
|
else if (result.kind === "refused") {
|
|
@@ -3008,14 +3813,39 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
3008
3813
|
});
|
|
3009
3814
|
|
|
3010
3815
|
api.hook("prompt_submit", async (event, ctx) => {
|
|
3816
|
+
// Clio continuing a stopped yolo turn (tool budget, loop guard, a failure) resumes that turn's drive and armed step.
|
|
3817
|
+
const held = (await ctx.state.get<{ armed?: Armed; drive?: Drive; workspace: string }>("held")).value;
|
|
3818
|
+
await ctx.state.delete("held");
|
|
3819
|
+
if (event.point === "prompt_submit" && (event as { origin?: string }).origin === "continuation") {
|
|
3820
|
+
if (held && held.workspace === ctx.snapshot.workspace) {
|
|
3821
|
+
if (held.armed) await ctx.state.set("armed", held.armed);
|
|
3822
|
+
if (held.drive) await ctx.state.set("drive", held.drive);
|
|
3823
|
+
}
|
|
3824
|
+
return {};
|
|
3825
|
+
}
|
|
3011
3826
|
const typed = event.point === "prompt_submit" ? (event.text ?? "") : "";
|
|
3012
3827
|
const desk = loadDesk(ctx.snapshot.workspace);
|
|
3013
3828
|
const armed = arm(typed, desk, ctx.snapshot.workspace);
|
|
3829
|
+
// Only a prompt that starts an advance run starts a drive; any other prompt ends one.
|
|
3830
|
+
await ctx.state.delete("drive");
|
|
3831
|
+
await ctx.state.delete("measure-noted");
|
|
3014
3832
|
if (!armed) {
|
|
3015
3833
|
await ctx.state.delete("armed");
|
|
3016
3834
|
return {};
|
|
3017
3835
|
}
|
|
3018
3836
|
await ctx.state.set("armed", armed);
|
|
3837
|
+
if (armed.action === "advance") {
|
|
3838
|
+
await ctx.state.set("drive", { workspace: ctx.snapshot.workspace, steps: [], asked: [] } satisfies Drive);
|
|
3839
|
+
return {
|
|
3840
|
+
effects: [
|
|
3841
|
+
{
|
|
3842
|
+
kind: "notify_operator",
|
|
3843
|
+
key: "wtfp-guard",
|
|
3844
|
+
message: "WTF-P driver armed: the desk picks each step from the project and confines it to that action's contract; it stops at the first gate only you can answer.",
|
|
3845
|
+
},
|
|
3846
|
+
],
|
|
3847
|
+
};
|
|
3848
|
+
}
|
|
3019
3849
|
const roots = writeRoots(desk, armed);
|
|
3020
3850
|
return {
|
|
3021
3851
|
effects: [
|
|
@@ -3028,6 +3858,14 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
3028
3858
|
};
|
|
3029
3859
|
});
|
|
3030
3860
|
api.hook("before_tool", async (event, ctx) => (event.point === "before_tool" ? guard(ctx, event.tool, event.args, event) : {}));
|
|
3861
|
+
api.hook("after_tool", async (event, ctx) => (event.point === "after_tool" && event.outcome === "ok" ? noteManuscriptWrite(ctx, event) : {}));
|
|
3862
|
+
// A WTF-P turn starts from the desk's picture of the project, so the action need not rebuild it from records.
|
|
3863
|
+
api.hook("turn_start", async (event, ctx) => {
|
|
3864
|
+
if (event.point !== "turn_start" || !(await armedFor(ctx))) return {};
|
|
3865
|
+
const desk = await deskFor(ctx);
|
|
3866
|
+
if (!desk.present) return {};
|
|
3867
|
+
return { effects: [{ kind: "inject_reminder", audience: "model", severity: "info", message: statusReminder(desk) }] };
|
|
3868
|
+
});
|
|
3031
3869
|
|
|
3032
3870
|
api.on("session_open", async (_event, ctx) => {
|
|
3033
3871
|
const workspace = ctx.snapshot.workspace;
|
|
@@ -3040,8 +3878,14 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
3040
3878
|
return { text: recovered ?? "", ...(recovered ? { toast: { text: recovered, tone: "warning" as const } } : {}), ...(await picture(ctx)) };
|
|
3041
3879
|
});
|
|
3042
3880
|
api.on("turn_end", async (_event, ctx) => {
|
|
3043
|
-
// An action arms for the turn its command starts; nothing it allowed outlives that turn.
|
|
3881
|
+
// An action arms for the turn its command starts; nothing it allowed outlives that turn. Clio's own
|
|
3882
|
+
// continuation of the turn may resume it, so the desk holds what it had until the next prompt says whose it is.
|
|
3883
|
+
const armed = (await ctx.state.get<Armed>("armed")).value;
|
|
3884
|
+
const drive = (await ctx.state.get<Drive>("drive")).value;
|
|
3885
|
+
if (armed || drive) await ctx.state.set("held", { ...(armed ? { armed } : {}), ...(drive ? { drive } : {}), workspace: ctx.snapshot.workspace });
|
|
3044
3886
|
await ctx.state.delete("armed");
|
|
3887
|
+
await ctx.state.delete("drive");
|
|
3888
|
+
await ctx.state.delete("measure-noted");
|
|
3045
3889
|
return undefined;
|
|
3046
3890
|
});
|
|
3047
3891
|
api.on("workspace_enter", async (_event, ctx) => ({ text: "", ...(await picture(ctx)) }));
|