wtf-p 0.8.1 → 0.8.3
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 +274 -56
- 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/review-section.md +2 -2
- package/protocol/workflows/verify-work.md +4 -2
- package/protocol/workflows/write-section.md +2 -2
- package/vendors/antigravity/.wtfp-generated.json +55 -43
- 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 +2 -10
- 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/review-section.md +2 -2
- 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 +109 -93
- 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 +5 -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 +6 -12
- 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 +2 -10
- 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/review-section.md +2 -2
- 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 +724 -6
- package/vendors/clio-extension/runtime/extension.ts +1028 -42
- 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 +32 -24
- 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/review-section.md +2 -2
- 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 +44 -32
- 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 +56 -44
- 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 +2 -10
- 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/review-section.md +2 -2
- 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/review-section.md +2 -2
- 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 +61 -49
- 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 +6 -412
- 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/review-section.md +2 -2
- package/vendors/gemini/workflows/verify-work.md +4 -2
- package/vendors/gemini/workflows/write-section.md +2 -2
- package/vendors/opencode/.wtfp-generated.json +60 -48
- 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 +6 -412
- 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/review-section.md +2 -2
- package/vendors/opencode/workflows/verify-work.md +4 -2
- package/vendors/opencode/workflows/write-section.md +2 -2
- package/vendors/plugin/.wtfp-generated.json +76 -64
- 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 +5 -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 +14 -8
- 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 +15 -9
- 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/review-section.md +2 -2
- 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,29 @@ 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
|
+
/** When write-section last validated a draft of this section, in epoch milliseconds, or null. */
|
|
203
|
+
writeValidatedAt: number | null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
interface Acceptance {
|
|
207
|
+
/** A review validation or linked review exists for the section. */
|
|
208
|
+
reviewed: boolean;
|
|
209
|
+
/** A verify-work validation is at least as new as the latest review. */
|
|
210
|
+
verified: boolean;
|
|
211
|
+
/** The attested author answer on that validation's acceptance checkpoint, if any. */
|
|
212
|
+
decision: "accept" | "revise" | null;
|
|
213
|
+
/** The note the author attached to that answer, if any. */
|
|
214
|
+
note?: string;
|
|
174
215
|
}
|
|
175
216
|
|
|
176
217
|
interface Finding {
|
|
@@ -204,6 +245,10 @@ interface Desk {
|
|
|
204
245
|
paperExists: boolean;
|
|
205
246
|
journal: boolean;
|
|
206
247
|
coverage: CoverageReport;
|
|
248
|
+
/** The latest milestone audit: fresh when nothing the desk tracks was recorded after it; errors counts its error and blocker issues. */
|
|
249
|
+
audit: { fresh: boolean; errors: number } | null;
|
|
250
|
+
/** A passed submit-milestone validation that no later draft or record outdates. */
|
|
251
|
+
delivered: boolean;
|
|
207
252
|
/** The WTF-P plugin while Clio serves it; null when it is not installed and enabled. */
|
|
208
253
|
served: ServedPlugin;
|
|
209
254
|
}
|
|
@@ -379,6 +424,18 @@ function schemaRegistry(): InstanceType<typeof SchemaRegistry> {
|
|
|
379
424
|
return registry;
|
|
380
425
|
}
|
|
381
426
|
|
|
427
|
+
/** The top-level fields a record type's schema defines. */
|
|
428
|
+
function recordFields(schema: string): Set<string> {
|
|
429
|
+
const match = /^wtfp\.project\.([a-z][a-z0-9-]*)\/v1$/u.exec(schema);
|
|
430
|
+
if (!match) return new Set();
|
|
431
|
+
try {
|
|
432
|
+
const parsed = JSON.parse(readFileSync(path.join(SCHEMAS, `${match[1]}.schema.json`), "utf8")) as Json;
|
|
433
|
+
return new Set(Object.keys((parsed.properties as Json | undefined) ?? {}));
|
|
434
|
+
} catch {
|
|
435
|
+
return new Set();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
382
439
|
/** Schema errors for one record, as the canonical validator reports them. */
|
|
383
440
|
function validateRecord(value: unknown): string[] {
|
|
384
441
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return ["$: planning record must be a JSON object"];
|
|
@@ -456,6 +513,97 @@ function sectionGates(checkpoints: Checkpoint[], id: string, manuscript: string
|
|
|
456
513
|
);
|
|
457
514
|
}
|
|
458
515
|
|
|
516
|
+
// --- the author's acceptance after review -------------------------------------
|
|
517
|
+
|
|
518
|
+
function writtenAt(workspace: string, manuscript: string | null): number | null {
|
|
519
|
+
if (manuscript === null || contained(workspace, manuscript) === null) return null;
|
|
520
|
+
try {
|
|
521
|
+
return statSync(path.join(workspace, manuscript)).mtimeMs;
|
|
522
|
+
} catch {
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* A plan the author approved after the manuscript was last written has not
|
|
529
|
+
* been applied yet: a revision plan approved for a reviewed section is drafted
|
|
530
|
+
* before anything reviews or accepts the section again. Answers are stamped to
|
|
531
|
+
* the second, so a write later in the same second counts as applying it.
|
|
532
|
+
*/
|
|
533
|
+
function unappliedPlan(section: SectionRow): boolean {
|
|
534
|
+
if (section.plan.state !== "approved" || !section.plan.approvedAt) return false;
|
|
535
|
+
const approved = Date.parse(section.plan.approvedAt);
|
|
536
|
+
if (!Number.isFinite(approved)) return false;
|
|
537
|
+
if (section.writtenAt === null || section.writtenAt < approved) return true;
|
|
538
|
+
// Saving the manuscript is not drafting it: write-section ends on its validation, after the measured
|
|
539
|
+
// count and summary. Live, a writer saved the revision, could not count it, and the section went to review.
|
|
540
|
+
return section.writeValidatedAt === null || section.writeValidatedAt < Math.floor(approved / 1000) * 1000;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
/** Why write-section is next for a section whose approved plan is not applied: no draft yet, or a saved draft write-section has not finished. */
|
|
544
|
+
function unappliedReason(section: SectionRow): string {
|
|
545
|
+
const approved = Date.parse(section.plan.approvedAt ?? "");
|
|
546
|
+
if (section.writtenAt === null || !(section.writtenAt >= approved)) return `${section.title} has an approved revision plan that no draft has applied yet.`;
|
|
547
|
+
return `${section.title}'s draft for its approved plan is saved, but write-section has not finished it: measure it, write the summary with that count, record its validation and set the section status, without redrafting it.`;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** When write-section last recorded a validation for this section, from its executed_at, or null. */
|
|
551
|
+
function writeValidatedAt(validations: Json[], id: string, manuscriptUri: string): number | null {
|
|
552
|
+
const times = validations
|
|
553
|
+
.filter((record) => record.action_id === "write-section" && validates(record, id, manuscriptUri))
|
|
554
|
+
.map((record) => Date.parse(text(record.executed_at)))
|
|
555
|
+
.filter(Number.isFinite);
|
|
556
|
+
return times.length > 0 ? Math.max(...times) : null;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const ACCEPT = "accept";
|
|
560
|
+
const REVISE = "revise";
|
|
561
|
+
|
|
562
|
+
/** Whether a validation's subject is this section, one of its artifacts, or its manuscript. */
|
|
563
|
+
function validates(record: Json, id: string, manuscriptUri: string): boolean {
|
|
564
|
+
const subject = text(record.subject_uri);
|
|
565
|
+
const section = `project://sections/${id}`;
|
|
566
|
+
return subject === section || subject.startsWith(`${section}/`) || subject === manuscriptUri || subject.startsWith(`${manuscriptUri}/`);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Where a reviewed section stands with its author. Review is critique only;
|
|
571
|
+
* verify-work records the acceptance checks and closes with a checkpoint scoped
|
|
572
|
+
* to its validation, and only an attested answer on that checkpoint counts.
|
|
573
|
+
*/
|
|
574
|
+
/** When the desk wrote each validation record, by file time. */
|
|
575
|
+
const recordedAt = new WeakMap<Json, number>();
|
|
576
|
+
|
|
577
|
+
function acceptanceOf(validations: Json[], checkpoints: Checkpoint[], id: string, manuscriptUri: string, reviewsLinked: boolean, drafted: number | null): Acceptance {
|
|
578
|
+
const mine = validations.filter((record) => validates(record, id, manuscriptUri));
|
|
579
|
+
const latest = (action: string): Json | undefined =>
|
|
580
|
+
mine.filter((record) => record.action_id === action).sort((a, b) => text(b.executed_at).localeCompare(text(a.executed_at)))[0];
|
|
581
|
+
const review = latest("review-section");
|
|
582
|
+
const verify = latest("verify-work");
|
|
583
|
+
// A review counts only for the draft it read: a revision written after it waits for a new review.
|
|
584
|
+
const reviewed = review !== undefined ? drafted === null || (recordedAt.get(review) ?? 0) >= drafted : reviewsLinked && drafted === null;
|
|
585
|
+
const verified = verify !== undefined && (review === undefined || text(verify.executed_at) >= text(review.executed_at));
|
|
586
|
+
if (!verified || verify === undefined) return { reviewed, verified: false, decision: null };
|
|
587
|
+
const answered = checkpoints
|
|
588
|
+
.filter((checkpoint) => checkpoint.scope_uri === `project://validations/${text(verify.id)}` && checkpoint.trust === "attested" && checkpoint.status === "resolved")
|
|
589
|
+
.sort((a, b) => text(b.answer?.answered_at).localeCompare(text(a.answer?.answered_at)))[0];
|
|
590
|
+
const picked = answered?.resolution?.selected_option;
|
|
591
|
+
const note = authorNote(answered);
|
|
592
|
+
return { reviewed, verified: true, decision: picked === ACCEPT || picked === REVISE ? picked : null, ...(note ? { note } : {}) };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** How the desk records the text an author attaches to a gate answer, inside the checkpoint's resolution summary. */
|
|
596
|
+
const NOTE_LEAD = " The author's note: ";
|
|
597
|
+
const NOTE_LIMIT = 4000;
|
|
598
|
+
|
|
599
|
+
/** The note an author attached to an answer this desk attested; null when there is none or the answer is not the author's. */
|
|
600
|
+
function authorNote(checkpoint: Checkpoint | undefined): string | null {
|
|
601
|
+
if (!checkpoint || checkpoint.trust !== "attested") return null;
|
|
602
|
+
const summary = checkpoint.resolution?.summary ?? "";
|
|
603
|
+
const at = summary.indexOf(NOTE_LEAD);
|
|
604
|
+
return at < 0 ? null : summary.slice(at + NOTE_LEAD.length).trim() || null;
|
|
605
|
+
}
|
|
606
|
+
|
|
459
607
|
// --- the approved-plan predicate ---------------------------------------------
|
|
460
608
|
|
|
461
609
|
/**
|
|
@@ -483,12 +631,20 @@ function planState(workspace: string, id: string, record: Json | null, checkpoin
|
|
|
483
631
|
const latest = answered[0];
|
|
484
632
|
// An author's explicit answer on this plan decides even when confirm_plan is off: a rejection is never overridden by policy.
|
|
485
633
|
if (latest) {
|
|
486
|
-
if (latest.resolution?.selected_option !== APPROVE || latest.status !== "resolved")
|
|
487
|
-
|
|
634
|
+
if (latest.resolution?.selected_option !== APPROVE || latest.status !== "resolved") {
|
|
635
|
+
const note = authorNote(latest);
|
|
636
|
+
return {
|
|
637
|
+
state: "declined",
|
|
638
|
+
uri,
|
|
639
|
+
file,
|
|
640
|
+
sha256: digest,
|
|
641
|
+
reason: `the author answered "${latest.resolution?.selected_option ?? latest.status}" on ${latest.id}, not approve${note ? `, with this note for the next plan: ${note}` : ""}`,
|
|
642
|
+
};
|
|
643
|
+
}
|
|
488
644
|
const shown = ((latest.answer?.presented as Json | undefined)?.artifact as Json | undefined)?.sha256;
|
|
489
645
|
if (shown !== digest)
|
|
490
646
|
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}
|
|
647
|
+
return { state: "approved", uri, file, sha256: digest, reason: `approved by the author on ${latest.id}`, approvedAt: text(latest.answer?.answered_at) };
|
|
492
648
|
}
|
|
493
649
|
if (!confirmPlan) return policy;
|
|
494
650
|
if (asked.some((checkpoint) => checkpoint.trust === "pending"))
|
|
@@ -512,11 +668,20 @@ function blockers(desk: Desk, section: SectionRow): string[] {
|
|
|
512
668
|
: `the recorded answer to ${gate.id} was not observed by this desk and must be confirmed`,
|
|
513
669
|
);
|
|
514
670
|
if (!planReady(section.plan)) reasons.push(`${section.plan.reason}`);
|
|
515
|
-
|
|
516
|
-
|
|
671
|
+
const gap = evidenceGap(section);
|
|
672
|
+
if (gap) reasons.push(`${gap}; run research-gap first`);
|
|
517
673
|
return reasons;
|
|
518
674
|
}
|
|
519
675
|
|
|
676
|
+
/** Why a literature-heavy section's evidence does not cover it yet; null when it does or when it needs no research. */
|
|
677
|
+
function evidenceGap(section: SectionRow): string | null {
|
|
678
|
+
if (!section.research.required) return null;
|
|
679
|
+
if (section.unsupported.length > 0)
|
|
680
|
+
return `${section.unsupported.length} required ${section.unsupported.length === 1 ? "claim lacks" : "claims lack"} verified evidence (${section.unsupported.slice(0, 3).join(", ")})`;
|
|
681
|
+
if (section.research.claimless) return "it requires research but records no claim that needs evidence, so no source can be shown to cover it";
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
684
|
+
|
|
520
685
|
// --- loading -----------------------------------------------------------------
|
|
521
686
|
|
|
522
687
|
function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
@@ -571,6 +736,15 @@ function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
|
571
736
|
const sourceRecords = indexed("sources");
|
|
572
737
|
const evidenceRecords = indexed("evidence");
|
|
573
738
|
|
|
739
|
+
const validations = listJson(workspace, ".planning/validations")
|
|
740
|
+
.map((file) => {
|
|
741
|
+
const record = readRecord(workspace, file);
|
|
742
|
+
// The desk writes every record itself, so the file's time is a clock the model cannot set.
|
|
743
|
+
if (record) recordedAt.set(record, writtenAt(workspace, file) ?? 0);
|
|
744
|
+
return record;
|
|
745
|
+
})
|
|
746
|
+
.filter((record): record is Json => record !== null);
|
|
747
|
+
|
|
574
748
|
const outlined = Array.isArray(outline?.sections) ? (outline.sections as Json[]) : [];
|
|
575
749
|
const loaded = outlined.map((entry) => {
|
|
576
750
|
const id = text(entry.id, "section");
|
|
@@ -644,11 +818,18 @@ function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
|
644
818
|
review: reviews.length > 0 || status === "complete",
|
|
645
819
|
},
|
|
646
820
|
gates: sectionGates(checkpoints, id, manuscript),
|
|
647
|
-
research: {
|
|
821
|
+
research: {
|
|
822
|
+
required: research.required === true,
|
|
823
|
+
present: readBytes(workspace, `${base}/research.md`) !== null,
|
|
824
|
+
claimless: !claims.some((claim) => claim.evidence_required === true && claim.status !== "rejected"),
|
|
825
|
+
},
|
|
648
826
|
dependsOn: Array.isArray(entry.depends_on) ? entry.depends_on.filter((dep): dep is string => typeof dep === "string") : [],
|
|
649
827
|
plan: planState(workspace, id, record, checkpoints, confirmPlan),
|
|
650
828
|
unsupported,
|
|
651
829
|
record,
|
|
830
|
+
acceptance: acceptanceOf(validations, checkpoints, id, text(artifacts.manuscript, `project://paper/${id}`), reviews.length > 0, writtenAt(workspace, manuscript)),
|
|
831
|
+
writtenAt: writtenAt(workspace, manuscript),
|
|
832
|
+
writeValidatedAt: writeValidatedAt(validations, id, text(artifacts.manuscript, `project://paper/${id}`)),
|
|
652
833
|
};
|
|
653
834
|
});
|
|
654
835
|
const issues = { blocker: 0, error: 0, warning: 0, info: 0 };
|
|
@@ -670,6 +851,8 @@ function loadDesk(workspace: string, key: Buffer | null = null): Desk {
|
|
|
670
851
|
deadline: typeof target.deadline === "string" ? target.deadline : null,
|
|
671
852
|
argument: text(manifest?.core_argument),
|
|
672
853
|
phase: text(state?.phase, manifest ? "initialized" : "none"),
|
|
854
|
+
audit: auditOf(validations, sections),
|
|
855
|
+
delivered: deliveredOf(validations, sections),
|
|
673
856
|
status: text(state?.status, "active"),
|
|
674
857
|
confirmPlan,
|
|
675
858
|
outputFormat,
|
|
@@ -1055,6 +1238,8 @@ const RECORD_URIS: ReadonlyArray<{ pattern: RegExp; type: string; file: (id: str
|
|
|
1055
1238
|
];
|
|
1056
1239
|
const REVISIONED = new Set(["state", "outline", "decisions"]);
|
|
1057
1240
|
const STAMPED = new Set(["state", "outline", "decisions", "manifest", "section"]);
|
|
1241
|
+
/** 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. */
|
|
1242
|
+
const CREATED_AT: Readonly<Record<string, string>> = { validation: "executed_at", checkpoint: "created_at", evidence: "verified_at" };
|
|
1058
1243
|
|
|
1059
1244
|
interface RecordWrite {
|
|
1060
1245
|
uri: string;
|
|
@@ -1185,11 +1370,24 @@ interface Prepared {
|
|
|
1185
1370
|
* answers and its derived counts.
|
|
1186
1371
|
*/
|
|
1187
1372
|
function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk", armed: Armed | null): Prepared {
|
|
1373
|
+
try {
|
|
1374
|
+
return prepareRecord(workspace, input, origin, armed);
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
// A create refused for its content carries the record's example, so the next call can succeed.
|
|
1377
|
+
const route = RECORD_URIS.find((entry) => entry.pattern.test(input.uri));
|
|
1378
|
+
const creating = route !== undefined && !existsSync(path.join(workspace, route.file(route.pattern.exec(input.uri)?.[1] ?? "")));
|
|
1379
|
+
const content = error instanceof Error && /holds wtfp\.project|whose id is|project_id|belongs to project|would not validate/u.test(error.message);
|
|
1380
|
+
if (creating && content && route) throw new Error(withTemplate((error as Error).message, route.type));
|
|
1381
|
+
throw error;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
function prepareRecord(workspace: string, input: RecordWrite, origin: "agent" | "desk", armed: Armed | null): Prepared {
|
|
1188
1386
|
const { uri } = input;
|
|
1189
1387
|
const record = input.record;
|
|
1190
1388
|
if (record === null || typeof record !== "object" || Array.isArray(record)) throw new Error(`${uri}: record must be a JSON object`);
|
|
1191
1389
|
const route = RECORD_URIS.find((entry) => entry.pattern.test(uri));
|
|
1192
|
-
if (!route) throw new Error(
|
|
1390
|
+
if (!route) throw new Error(notARecord(uri));
|
|
1193
1391
|
if (route.type === "interaction" && origin === "agent")
|
|
1194
1392
|
throw new Error(`${uri}: only the desk records an author's answer; ask with extension_wtfp__gate`);
|
|
1195
1393
|
const id = route.pattern.exec(uri)?.[1] ?? "";
|
|
@@ -1200,7 +1398,11 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1200
1398
|
const manifest = readRecord(workspace, ".planning/project.json");
|
|
1201
1399
|
const projectId = route.type === "manifest" ? record.id : record.project_id;
|
|
1202
1400
|
if (manifest && typeof manifest.id === "string" && projectId !== manifest.id)
|
|
1203
|
-
throw new Error(
|
|
1401
|
+
throw new Error(
|
|
1402
|
+
projectId === undefined
|
|
1403
|
+
? `${uri} needs project_id "${manifest.id}"`
|
|
1404
|
+
: `${uri} belongs to project ${String(projectId)}, not ${manifest.id}`,
|
|
1405
|
+
);
|
|
1204
1406
|
const bytes = readBytes(workspace, file);
|
|
1205
1407
|
if (bytes === null && existsSync(path.join(workspace, file))) throw new Error(`${file} is not a regular file the desk can replace`);
|
|
1206
1408
|
const priorSha = bytes === null ? null : sha256(bytes);
|
|
@@ -1219,7 +1421,7 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1219
1421
|
if (expectation) throw new Error(`${uri} no longer exists; read the project again before writing`);
|
|
1220
1422
|
} else if (!expectation) {
|
|
1221
1423
|
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`,
|
|
1424
|
+
`${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
1425
|
);
|
|
1224
1426
|
} else {
|
|
1225
1427
|
const byRevision = input.expect_revision !== undefined && REVISIONED.has(route.type) && input.expect_revision === priorRevision;
|
|
@@ -1227,8 +1429,8 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1227
1429
|
if (!byRevision && !bySha)
|
|
1228
1430
|
throw new Error(
|
|
1229
1431
|
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
|
|
1432
|
+
? `${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`
|
|
1433
|
+
: `${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
1434
|
);
|
|
1233
1435
|
}
|
|
1234
1436
|
if (origin === "agent" && armed && !declares(armed, uri, bytes === null ? "create" : "update"))
|
|
@@ -1248,8 +1450,15 @@ function prepare(workspace: string, input: RecordWrite, origin: "agent" | "desk"
|
|
|
1248
1450
|
next.revision = revision;
|
|
1249
1451
|
}
|
|
1250
1452
|
if (STAMPED.has(route.type)) next.updated_at = timestamp();
|
|
1453
|
+
const createdAt = CREATED_AT[route.type];
|
|
1454
|
+
// A model has no clock: an invented time can order a validation before the answer it follows, so the desk's time stands.
|
|
1455
|
+
if (bytes === null && createdAt && (origin === "agent" || next[createdAt] === undefined)) next[createdAt] = timestamp();
|
|
1251
1456
|
const errors = validateRecord(next);
|
|
1252
|
-
|
|
1457
|
+
// Every error at once: a model fixing one per call resends its whole context each time.
|
|
1458
|
+
if (errors.length > 0)
|
|
1459
|
+
throw new Error(
|
|
1460
|
+
`${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`,
|
|
1461
|
+
);
|
|
1253
1462
|
const serialized = `${JSON.stringify(next, null, 2)}\n`;
|
|
1254
1463
|
return {
|
|
1255
1464
|
write: { uri, file, text: serialized, sha256: sha256(serialized), revision },
|
|
@@ -1275,12 +1484,19 @@ function normalizeWrites(input: Json): RecordWrite[] {
|
|
|
1275
1484
|
interface Next {
|
|
1276
1485
|
command: string | null;
|
|
1277
1486
|
reason: string;
|
|
1487
|
+
/** The catalog action this step runs, when one does. */
|
|
1488
|
+
action?: string;
|
|
1489
|
+
/** The section the action takes as its input, when it takes one. */
|
|
1490
|
+
section?: string | null;
|
|
1491
|
+
/** The checkpoint that must be answered first, when a gate holds the way. */
|
|
1492
|
+
gate?: string;
|
|
1278
1493
|
}
|
|
1279
1494
|
|
|
1280
1495
|
/** 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 {
|
|
1496
|
+
function step(served: ServedPlugin, action: string, args: string, reason: string, gate?: string): Next {
|
|
1282
1497
|
const command = commandFor(served, action, args);
|
|
1283
|
-
|
|
1498
|
+
const named = { action, section: args || null, ...(gate ? { gate } : {}) };
|
|
1499
|
+
return command ? { command, reason, ...named } : { command: null, reason: `${reason} Its next step, ${action}, needs the WTF-P plugin.`, ...named };
|
|
1284
1500
|
}
|
|
1285
1501
|
|
|
1286
1502
|
function openGates(desk: Desk): Checkpoint[] {
|
|
@@ -1301,8 +1517,14 @@ function nextAction(desk: Desk): Next {
|
|
|
1301
1517
|
"check-todos",
|
|
1302
1518
|
"",
|
|
1303
1519
|
gate.trust === "pending" ? `Gate waiting on you: ${gate.request}` : `Confirm the recorded answer to ${gate.id}: ${gate.request}`,
|
|
1520
|
+
gate.id,
|
|
1304
1521
|
);
|
|
1305
1522
|
if (desk.sections.length === 0) return step(served, "create-outline", "", "No outline yet.");
|
|
1523
|
+
// new-paper writes an outline but no section records, and only create-outline
|
|
1524
|
+
// declares creating one; every later action may only update it.
|
|
1525
|
+
const unrecorded = desk.sections.filter((section) => section.record === null).map((section) => section.id);
|
|
1526
|
+
if (unrecorded.length > 0)
|
|
1527
|
+
return step(served, "create-outline", "", `The outline lists ${unrecorded.join(", ")} without a section record; create-outline creates them.`);
|
|
1306
1528
|
const complete = new Set(desk.sections.filter((section) => section.status === "complete").map((section) => section.id));
|
|
1307
1529
|
const ordered = [...desk.sections].sort((a, b) => a.wave - b.wave);
|
|
1308
1530
|
for (const section of ordered) {
|
|
@@ -1310,37 +1532,208 @@ function nextAction(desk: Desk): Next {
|
|
|
1310
1532
|
if (!section.dependsOn.every((dep) => complete.has(dep)) && section.status === "not-started") continue;
|
|
1311
1533
|
return sectionNext(served, section);
|
|
1312
1534
|
}
|
|
1313
|
-
if (desk.phase === "delivered") return { command: null, reason: "Delivered." };
|
|
1314
|
-
|
|
1535
|
+
if (desk.phase === "delivered" || desk.delivered) return { command: null, reason: "Delivered: every section is complete, audited and archived; a later change reopens review." };
|
|
1536
|
+
// audit-milestone writes only its validation, so the audit itself, not a phase it cannot set, says the draft is ready.
|
|
1537
|
+
if (desk.phase === "ready" || (desk.audit?.fresh && desk.audit.errors === 0)) return step(served, "submit-milestone", "", "Every section is complete and audited.");
|
|
1538
|
+
if (desk.audit?.fresh)
|
|
1539
|
+
return step(served, "plan-milestone-gaps", "", `The milestone audit found ${desk.audit.errors} ${desk.audit.errors === 1 ? "error" : "errors"} to close before delivery.`);
|
|
1315
1540
|
return step(served, "audit-milestone", "", "Every section is complete; audit before delivery.");
|
|
1316
1541
|
}
|
|
1317
1542
|
|
|
1543
|
+
/**
|
|
1544
|
+
* The latest audit-milestone validation, by the desk's file time. It is fresh
|
|
1545
|
+
* when no other validation and no manuscript was written after it, so an audit
|
|
1546
|
+
* of an earlier draft never stands for the current one.
|
|
1547
|
+
*/
|
|
1548
|
+
function auditOf(validations: Json[], sections: SectionRow[]): Desk["audit"] {
|
|
1549
|
+
const at = (record: Json): number => recordedAt.get(record) ?? 0;
|
|
1550
|
+
const audits = validations.filter((record) => record.action_id === "audit-milestone").sort((a, b) => at(b) - at(a));
|
|
1551
|
+
const latest = audits[0];
|
|
1552
|
+
if (!latest) return null;
|
|
1553
|
+
const later = validations.some((record) => record.action_id !== "audit-milestone" && at(record) > at(latest)) || sections.some((section) => (section.writtenAt ?? 0) > at(latest));
|
|
1554
|
+
const errors = (Array.isArray(latest.issues) ? (latest.issues as Json[]) : []).filter((issue) => issue.severity === "error" || issue.severity === "blocker").length;
|
|
1555
|
+
return { fresh: !later && latest.status !== "failed", errors: latest.status === "failed" ? Math.max(errors, 1) : errors };
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/** Whether the latest passed milestone submission still stands: nothing but audits and submissions came after it. */
|
|
1559
|
+
function deliveredOf(validations: Json[], sections: SectionRow[]): boolean {
|
|
1560
|
+
const at = (record: Json): number => recordedAt.get(record) ?? 0;
|
|
1561
|
+
const submitted = validations.filter((record) => record.action_id === "submit-milestone" && record.status === "passed").sort((a, b) => at(b) - at(a))[0];
|
|
1562
|
+
if (!submitted) return false;
|
|
1563
|
+
const delivery = new Set(["audit-milestone", "submit-milestone"]);
|
|
1564
|
+
return !validations.some((record) => !delivery.has(text(record.action_id)) && at(record) > at(submitted)) && !sections.some((section) => (section.writtenAt ?? 0) > at(submitted));
|
|
1565
|
+
}
|
|
1566
|
+
|
|
1567
|
+
/** A drafted section's next step: review the current draft, then the author's acceptance or a revision. */
|
|
1568
|
+
function reviewNext(served: ServedPlugin, section: SectionRow): Next {
|
|
1569
|
+
const id = section.id;
|
|
1570
|
+
const acceptance = section.acceptance;
|
|
1571
|
+
if (unappliedPlan(section)) return step(served, "write-section", id, unappliedReason(section));
|
|
1572
|
+
if (!acceptance.reviewed) return step(served, "review-section", id, `${section.title} is drafted and waits for review.`);
|
|
1573
|
+
if (!acceptance.verified)
|
|
1574
|
+
return step(served, "verify-work", id, `${section.title} is reviewed; the author checks it against its plan and accepts it or sends it back.`);
|
|
1575
|
+
if (acceptance.decision === REVISE)
|
|
1576
|
+
return step(served, "plan-revision", id, `The author sent ${section.title} back for revision${acceptance.note ? `, with this note: ${acceptance.note}` : "."}`);
|
|
1577
|
+
return step(
|
|
1578
|
+
served,
|
|
1579
|
+
"verify-work",
|
|
1580
|
+
id,
|
|
1581
|
+
acceptance.decision === ACCEPT ? `The author accepted ${section.title}; verify-work marks it complete.` : `${section.title} waits for the author's acceptance.`,
|
|
1582
|
+
);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1318
1585
|
/** The next step for one section, by the same ladder the band follows. */
|
|
1319
1586
|
function sectionNext(served: ServedPlugin, section: SectionRow): Next {
|
|
1320
1587
|
const id = section.id;
|
|
1321
|
-
if (section.gates.length > 0) return step(served, "check-todos", "", `${section.title} waits on a gate
|
|
1588
|
+
if (section.gates.length > 0) return step(served, "check-todos", "", `${section.title} waits on a gate.`, section.gates[0]?.id);
|
|
1322
1589
|
switch (section.status) {
|
|
1323
1590
|
case "complete":
|
|
1324
1591
|
return step(served, "review-section", id, `${section.title} is complete; review it again if it changed.`);
|
|
1325
1592
|
case "blocked":
|
|
1326
1593
|
return step(served, "check-todos", "", `${section.title} is blocked.`);
|
|
1327
1594
|
case "reviewing":
|
|
1328
|
-
return
|
|
1595
|
+
return reviewNext(served, section);
|
|
1329
1596
|
case "writing":
|
|
1330
1597
|
case "planned":
|
|
1331
|
-
if (section
|
|
1332
|
-
return step(served, "research-gap", id, `${section.title}
|
|
1598
|
+
if (evidenceGap(section))
|
|
1599
|
+
return step(served, "research-gap", id, `${section.title}: ${evidenceGap(section)}.`);
|
|
1333
1600
|
if (!planReady(section.plan))
|
|
1334
1601
|
return step(served, "plan-section", id, `${section.title} cannot be drafted: ${section.plan.reason}.`);
|
|
1335
|
-
|
|
1602
|
+
// A draft written and validated after its plan's approval is past drafting even when the record still says writing.
|
|
1603
|
+
if (section.plan.state === "approved" && section.plan.approvedAt && !unappliedPlan(section)) return reviewNext(served, section);
|
|
1604
|
+
return step(served, "write-section", id, section.plan.state === "approved" && section.writtenAt !== null && section.plan.approvedAt && section.writtenAt >= Date.parse(section.plan.approvedAt) ? unappliedReason(section) : `${section.title} has an approved plan.`);
|
|
1336
1605
|
default:
|
|
1337
1606
|
if (!section.stages.discuss) return step(served, "discuss-section", id, `Settle what ${section.title} must argue.`);
|
|
1338
|
-
if (section.research.required &&
|
|
1607
|
+
if (section.research.required && !section.research.present)
|
|
1339
1608
|
return step(served, "research-gap", id, `${section.title} needs verified evidence first.`);
|
|
1609
|
+
if (evidenceGap(section))
|
|
1610
|
+
return step(served, "research-gap", id, `${section.title}: ${evidenceGap(section)}.`);
|
|
1340
1611
|
return step(served, "plan-section", id, `${section.title} is ready to plan.`);
|
|
1341
1612
|
}
|
|
1342
1613
|
}
|
|
1343
1614
|
|
|
1615
|
+
// --- driver --------------------------------------------------------------------
|
|
1616
|
+
|
|
1617
|
+
/**
|
|
1618
|
+
* The actions `/wtfp:advance` may chain. Each runs under its own contract; the
|
|
1619
|
+
* driver never runs an action that starts, maps or reshapes the project, since
|
|
1620
|
+
* those are the author's to begin.
|
|
1621
|
+
*/
|
|
1622
|
+
const DRIVEN = new Set(["create-outline", "discuss-section", "research-gap", "plan-section", "write-section", "review-section", "verify-work", "plan-revision", "audit-milestone", "submit-milestone"]);
|
|
1623
|
+
/** Steps one advance run may take before it hands the session back. */
|
|
1624
|
+
const MAX_DRIVE_STEPS = 24;
|
|
1625
|
+
|
|
1626
|
+
/** One `/wtfp:advance` run: the steps the desk armed and the gates it put to the author. */
|
|
1627
|
+
interface Drive {
|
|
1628
|
+
workspace: string;
|
|
1629
|
+
/** `finish`: the step was handed back once to record outputs it skipped. */
|
|
1630
|
+
steps: Array<{ action: string; section: string | null; fingerprint: string; finish?: boolean }>;
|
|
1631
|
+
asked: string[];
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
type DriveDecision =
|
|
1635
|
+
| { kind: "step"; action: string; section: string | null; prompt: string; reason: string; finish?: boolean }
|
|
1636
|
+
| { kind: "gate"; checkpoint: string; reason: string }
|
|
1637
|
+
| { kind: "stop"; reason: string };
|
|
1638
|
+
|
|
1639
|
+
/** What the project looks like to the ladder; an unchanged fingerprint means a step changed nothing it reads. */
|
|
1640
|
+
function driveFingerprint(desk: Desk): string {
|
|
1641
|
+
return sha256(
|
|
1642
|
+
JSON.stringify({
|
|
1643
|
+
phase: desk.phase,
|
|
1644
|
+
status: desk.status,
|
|
1645
|
+
sections: desk.sections.map((section) => [
|
|
1646
|
+
section.id,
|
|
1647
|
+
section.status,
|
|
1648
|
+
section.stages,
|
|
1649
|
+
section.plan.state,
|
|
1650
|
+
section.plan.sha256,
|
|
1651
|
+
section.unsupported,
|
|
1652
|
+
section.research,
|
|
1653
|
+
section.words,
|
|
1654
|
+
section.recorded,
|
|
1655
|
+
section.acceptance,
|
|
1656
|
+
section.gates.map((gate) => [gate.id, gate.status, gate.trust]),
|
|
1657
|
+
]),
|
|
1658
|
+
checkpoints: desk.checkpoints.map((checkpoint) => [checkpoint.id, checkpoint.status, checkpoint.trust]),
|
|
1659
|
+
sources: desk.sources,
|
|
1660
|
+
evidence: desk.evidence,
|
|
1661
|
+
}),
|
|
1662
|
+
);
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
/**
|
|
1666
|
+
* The driver's next move, chosen by the same ladder `progress` follows. The
|
|
1667
|
+
* desk, never the model, picks the action and section; the model only runs it.
|
|
1668
|
+
*/
|
|
1669
|
+
function driveStep(desk: Desk, drive: Drive): DriveDecision {
|
|
1670
|
+
if (!desk.present)
|
|
1671
|
+
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." };
|
|
1672
|
+
const next = nextAction(desk);
|
|
1673
|
+
if (next.gate) {
|
|
1674
|
+
if (drive.asked.includes(next.gate)) return { kind: "stop", reason: `${next.gate} is still waiting on you. ${next.reason}` };
|
|
1675
|
+
return { kind: "gate", checkpoint: next.gate, reason: next.reason };
|
|
1676
|
+
}
|
|
1677
|
+
if (!next.action || next.action === "check-todos") return { kind: "stop", reason: next.reason };
|
|
1678
|
+
if (!DRIVEN.has(next.action))
|
|
1679
|
+
return { kind: "stop", reason: `${next.reason} The next action, ${next.command ?? next.action}, starts or reshapes the project, so it is yours to run.` };
|
|
1680
|
+
if (next.command === null) return { kind: "stop", reason: next.reason };
|
|
1681
|
+
if (!GUARD.actions[next.action]) return { kind: "stop", reason: `${next.action} is not available on this host, so the desk cannot arm it.` };
|
|
1682
|
+
if (drive.steps.length >= MAX_DRIVE_STEPS)
|
|
1683
|
+
return { kind: "stop", reason: `This run took ${MAX_DRIVE_STEPS} steps, its limit. Run advance again to continue from ${next.command}.` };
|
|
1684
|
+
const section = next.section ?? null;
|
|
1685
|
+
const fingerprint = driveFingerprint(desk);
|
|
1686
|
+
const last = drive.steps[drive.steps.length - 1];
|
|
1687
|
+
if (last && last.action === next.action && last.section === section && last.fingerprint === fingerprint) {
|
|
1688
|
+
// Live, review-section reported findings and skipped its review record; one hand-back names what to record.
|
|
1689
|
+
const creates = (GUARD.actions[next.action]?.produces ?? []).filter((output) => output.mode === "create").map((output) => output.uri.replace("{section}", section ?? "{section}"));
|
|
1690
|
+
if (!last.finish && creates.length > 0)
|
|
1691
|
+
return {
|
|
1692
|
+
kind: "step",
|
|
1693
|
+
action: next.action,
|
|
1694
|
+
section,
|
|
1695
|
+
prompt: `ai.iowarp.clio/prompts/wtfp/${next.action}.md`,
|
|
1696
|
+
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.`,
|
|
1697
|
+
finish: true,
|
|
1698
|
+
};
|
|
1699
|
+
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}` };
|
|
1700
|
+
}
|
|
1701
|
+
// Live, write-section measured its draft and the desk armed it again with the same words, which the model took for a loop.
|
|
1702
|
+
if (last && last.action === next.action && last.section === section)
|
|
1703
|
+
return {
|
|
1704
|
+
kind: "step",
|
|
1705
|
+
action: next.action,
|
|
1706
|
+
section,
|
|
1707
|
+
prompt: `ai.iowarp.clio/prompts/wtfp/${next.action}.md`,
|
|
1708
|
+
reason: `Continue ${next.command}: it made progress but has not finished, so the desk arms it again on purpose; this is not a loop. ${next.reason}`,
|
|
1709
|
+
};
|
|
1710
|
+
return { kind: "step", action: next.action, section, prompt: `ai.iowarp.clio/prompts/wtfp/${next.action}.md`, reason: next.reason };
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Every next_step result ends with this rule, so a turn Clio compacted after
|
|
1715
|
+
* dropping the advance prompt can still continue from the last result alone.
|
|
1716
|
+
*/
|
|
1717
|
+
const DRIVER_RULE =
|
|
1718
|
+
"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.";
|
|
1719
|
+
|
|
1720
|
+
/**
|
|
1721
|
+
* Live on Clio 0.8.3, the model looked for a capability named after the step's action, found none in the
|
|
1722
|
+
* turn's list, and stopped the drive as if the step were forbidden.
|
|
1723
|
+
*/
|
|
1724
|
+
const STEP_IS_A_PROCEDURE =
|
|
1725
|
+
"A step is a procedure, not a capability: there is no tool named after its action, so do it with this turn's tools as its prompt says.";
|
|
1726
|
+
|
|
1727
|
+
/** Where a step's prompt lives, stated so it survives the loss of the advance prompt's resolved plugin root. */
|
|
1728
|
+
function stepPrompt(prompt: string): string {
|
|
1729
|
+
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)`;
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
/** The arming of an advance run between steps: nothing may be written until the desk arms a step. */
|
|
1733
|
+
function idleArm(workspace: string): Armed {
|
|
1734
|
+
return { action: "advance", produces: [], section: null, workspace };
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1344
1737
|
function meter(words: number, target: number, cells = 8): string {
|
|
1345
1738
|
if (target <= 0) return "";
|
|
1346
1739
|
const filled = Math.max(0, Math.min(cells, Math.round((words / target) * cells)));
|
|
@@ -1743,6 +2136,11 @@ function planGate(checkpoint: Checkpoint): boolean {
|
|
|
1743
2136
|
return new RegExp(`^project://sections/${IDENTIFIER}/plans/${IDENTIFIER}$`, "u").test(checkpoint.scope_uri);
|
|
1744
2137
|
}
|
|
1745
2138
|
|
|
2139
|
+
/** verify-work's closing question: an acceptance checkpoint scoped to its validation. */
|
|
2140
|
+
function acceptanceGate(checkpoint: Checkpoint): boolean {
|
|
2141
|
+
return new RegExp(`^project://validations/${IDENTIFIER}$`, "u").test(checkpoint.scope_uri) && (checkpoint.options ?? []).some((option) => option.id === ACCEPT);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
1746
2144
|
/**
|
|
1747
2145
|
* The words the author sees for an option. On a plan gate the desk owns them:
|
|
1748
2146
|
* `approve` is what authorizes drafting, so it always reads as approval and
|
|
@@ -1753,6 +2151,12 @@ function shown(checkpoint: Checkpoint, option: { id: string; label: string; impl
|
|
|
1753
2151
|
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
2152
|
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
2153
|
}
|
|
2154
|
+
// Only `accept` completes a section, so only it reads as acceptance.
|
|
2155
|
+
if (acceptanceGate(checkpoint)) {
|
|
2156
|
+
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." };
|
|
2157
|
+
if (option.id === REVISE) return { label: "Send it back for revision", detail: "The next step plans a revision for you to approve." };
|
|
2158
|
+
if (/accept/iu.test(option.label)) return { label: `Do not accept it yet (${option.id})`, detail: "Any answer but accept leaves the section unaccepted." };
|
|
2159
|
+
}
|
|
1756
2160
|
return { label: option.label, ...(option.implication ? { detail: option.implication } : {}) };
|
|
1757
2161
|
}
|
|
1758
2162
|
|
|
@@ -1771,7 +2175,7 @@ function subjectOf(workspace: string, desk: Desk, checkpoint: Checkpoint): { uri
|
|
|
1771
2175
|
return bytes === null ? null : { uri: checkpoint.scope_uri, sha256: sha256(bytes) };
|
|
1772
2176
|
}
|
|
1773
2177
|
|
|
1774
|
-
async function ask(ctx: ExtensionContextV2, desk: Desk, checkpoint: Checkpoint): Promise<InterviewStep> {
|
|
2178
|
+
async function ask(ctx: ExtensionContextV2, desk: Desk, checkpoint: Checkpoint, hint?: string): Promise<InterviewStep> {
|
|
1775
2179
|
const nonce = randomBytes(6).toString("hex");
|
|
1776
2180
|
const artifact = subjectOf(ctx.snapshot.workspace, desk, checkpoint);
|
|
1777
2181
|
const offered = [...choices(checkpoint), { value: KEEP, label: "Keep it pending", detail: "Answer later; its writes stay blocked." }];
|
|
@@ -1795,6 +2199,7 @@ async function ask(ctx: ExtensionContextV2, desk: Desk, checkpoint: Checkpoint):
|
|
|
1795
2199
|
t: "box",
|
|
1796
2200
|
dir: "col",
|
|
1797
2201
|
children: [
|
|
2202
|
+
...(hint ? [{ t: "text", text: hint, tone: "warning", wrap: "wrap" } as View] : []),
|
|
1798
2203
|
...(checkpoint.context ? [{ t: "text", text: checkpoint.context, wrap: "wrap" } as View] : []),
|
|
1799
2204
|
...(confirming
|
|
1800
2205
|
? [{ 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 +2230,7 @@ type AnswerResult = { kind: "recorded" | "kept" | "stale" | "refused"; text: str
|
|
|
1825
2230
|
* author was offered for this exact checkpoint, project and subject, and only
|
|
1826
2231
|
* once: the binding is consumed before anything is written.
|
|
1827
2232
|
*/
|
|
1828
|
-
async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown): Promise<AnswerResult> {
|
|
2233
|
+
async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown, note: string | null = null): Promise<AnswerResult> {
|
|
1829
2234
|
const workspace = ctx.snapshot.workspace;
|
|
1830
2235
|
const nonce = /^gate\.([a-f0-9]{12})$/u.exec(stepKey)?.[1];
|
|
1831
2236
|
const asked = nonce ? (await ctx.state.get<Asked>(`ask:${nonce}`)).value : undefined;
|
|
@@ -1866,6 +2271,7 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1866
2271
|
key,
|
|
1867
2272
|
);
|
|
1868
2273
|
const writes: Array<{ input: RecordWrite }> = [{ input: { uri: `project://interactions/${String(interaction.id)}`, record: interaction } }];
|
|
2274
|
+
let linkedIn: string | null = null;
|
|
1869
2275
|
if (!stale && picked !== KEEP) {
|
|
1870
2276
|
const { file: _file, trust: _trust, answer: _answer, ...stored } = checkpoint;
|
|
1871
2277
|
writes.push({
|
|
@@ -1878,11 +2284,13 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1878
2284
|
resolution: {
|
|
1879
2285
|
resolved_by: "author",
|
|
1880
2286
|
...(option ? { selected_option: option.id } : {}),
|
|
1881
|
-
summary:
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
2287
|
+
summary: `${
|
|
2288
|
+
option
|
|
2289
|
+
? `The author chose "${shown(checkpoint, option).label}" at the Clio WTF-P desk.`
|
|
2290
|
+
: picked === WAIVE
|
|
2291
|
+
? "The author waived this gate at the Clio WTF-P desk."
|
|
2292
|
+
: "The author marked this done at the Clio WTF-P desk."
|
|
2293
|
+
}${note ? `${NOTE_LEAD}${note}` : ""}`,
|
|
1886
2294
|
resolved_at: now,
|
|
1887
2295
|
},
|
|
1888
2296
|
},
|
|
@@ -1898,6 +2306,30 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1898
2306
|
record: { ...state, active_checkpoint_uris: (state.active_checkpoint_uris as string[]).filter((entry) => entry !== uri) },
|
|
1899
2307
|
},
|
|
1900
2308
|
});
|
|
2309
|
+
// The author's approval links the plan in the same commit: live, the model asked the desk for its next
|
|
2310
|
+
// step before linking, and the approved plan sat unlinked while the driver planned again.
|
|
2311
|
+
const planned = option?.id === APPROVE && planGate(checkpoint) ? /^project:\/\/sections\/([^/]+)\/plans\//u.exec(checkpoint.scope_uri)?.[1] : undefined;
|
|
2312
|
+
const sectionFile = planned ? `.planning/sections/${planned}/section.json` : null;
|
|
2313
|
+
const section = sectionFile ? readRecord(workspace, sectionFile) : null;
|
|
2314
|
+
if (planned && sectionFile && section) {
|
|
2315
|
+
const artifacts = isObject(section.artifacts) ? section.artifacts : {};
|
|
2316
|
+
const plans = Array.isArray(artifacts.plans) ? (artifacts.plans as unknown[]) : [];
|
|
2317
|
+
if (plans[plans.length - 1] !== checkpoint.scope_uri) {
|
|
2318
|
+
linkedIn = `project://sections/${planned}`;
|
|
2319
|
+
const status = text(section.status, "not-started");
|
|
2320
|
+
writes.push({
|
|
2321
|
+
input: {
|
|
2322
|
+
uri: `project://sections/${planned}`,
|
|
2323
|
+
expect_sha256: sha256(readBytes(workspace, sectionFile) ?? ""),
|
|
2324
|
+
record: {
|
|
2325
|
+
...section,
|
|
2326
|
+
status: status === "not-started" ? "planned" : status,
|
|
2327
|
+
artifacts: { ...artifacts, plans: [...plans.filter((entry) => entry !== checkpoint.scope_uri), checkpoint.scope_uri] },
|
|
2328
|
+
},
|
|
2329
|
+
},
|
|
2330
|
+
});
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
1901
2333
|
}
|
|
1902
2334
|
withLock(workspace, () => {
|
|
1903
2335
|
recover(workspace);
|
|
@@ -1915,7 +2347,12 @@ async function answer(ctx: ExtensionContextV2, stepKey: string, picked: unknown)
|
|
|
1915
2347
|
if (picked === KEEP) return { kind: "kept", text: `${checkpoint.id}: kept pending`, checkpoint: checkpoint.id };
|
|
1916
2348
|
return {
|
|
1917
2349
|
kind: "recorded",
|
|
1918
|
-
text: option ? `${checkpoint.id}: ${shown(checkpoint, option).label}` : `${checkpoint.id}: ${picked === WAIVE ? "waived" : "done"}
|
|
2350
|
+
text: `${option ? `${checkpoint.id}: ${shown(checkpoint, option).label}` : `${checkpoint.id}: ${picked === WAIVE ? "waived" : "done"}`}${
|
|
2351
|
+
linkedIn ? `. The desk linked ${checkpoint.scope_uri} in ${linkedIn} with this answer; do not link it again` : ""
|
|
2352
|
+
}. The desk wrote ${writes
|
|
2353
|
+
.slice(1)
|
|
2354
|
+
.map((entry) => entry.input.uri)
|
|
2355
|
+
.join(", ")}; read any of them again before writing it`,
|
|
1919
2356
|
checkpoint: checkpoint.id,
|
|
1920
2357
|
};
|
|
1921
2358
|
}
|
|
@@ -1941,6 +2378,31 @@ function choiceOf(answers: Record<string, string | string[]>): unknown {
|
|
|
1941
2378
|
return Array.isArray(choice) ? (choice.length === 1 ? choice[0] : undefined) : choice;
|
|
1942
2379
|
}
|
|
1943
2380
|
|
|
2381
|
+
/** The text the author attached to their chosen option, bounded; null when none. */
|
|
2382
|
+
function noteOf(event: { notes?: Record<string, string> }): string | null {
|
|
2383
|
+
const note = event.notes?.choice?.replace(/\s+/gu, " ").trim() ?? "";
|
|
2384
|
+
return note ? note.slice(0, NOTE_LIMIT) : null;
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
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.";
|
|
2388
|
+
|
|
2389
|
+
/**
|
|
2390
|
+
* A gate answered with free text instead of an option. Nothing is recorded and
|
|
2391
|
+
* the question's binding is spent; the text goes back with how to send it.
|
|
2392
|
+
*/
|
|
2393
|
+
async function freeText(ctx: ExtensionContextV2, event: { step: string; answers: Record<string, string | string[]>; other?: Record<string, true> }): Promise<AnswerResult | null> {
|
|
2394
|
+
if (event.other?.choice !== true) return null;
|
|
2395
|
+
const nonce = /^gate\.([a-f0-9]{12})$/u.exec(event.step)?.[1];
|
|
2396
|
+
const asked = nonce ? (await ctx.state.get<Asked>(`ask:${nonce}`)).value : undefined;
|
|
2397
|
+
if (nonce) await ctx.state.delete(`ask:${nonce}`);
|
|
2398
|
+
const typed = String(choiceOf(event.answers) ?? "").replace(/\s+/gu, " ").trim().slice(0, NOTE_LIMIT);
|
|
2399
|
+
return {
|
|
2400
|
+
kind: "refused",
|
|
2401
|
+
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}"` : ""}`,
|
|
2402
|
+
...(asked ? { checkpoint: asked.checkpoint } : {}),
|
|
2403
|
+
};
|
|
2404
|
+
}
|
|
2405
|
+
|
|
1944
2406
|
// --- confirmations of weakening record writes --------------------------------
|
|
1945
2407
|
|
|
1946
2408
|
interface PendingConfirm {
|
|
@@ -2002,6 +2464,20 @@ async function armedFor(ctx: ExtensionContextV2): Promise<Armed | null> {
|
|
|
2002
2464
|
async function recordTool(ctx: ExtensionContextV2, input: Json): Promise<{ text: string; data?: unknown; isError?: boolean; interview?: { id: string; title: string; total: number; step: InterviewStep } }> {
|
|
2003
2465
|
const workspace = ctx.snapshot.workspace;
|
|
2004
2466
|
const armed = await armedFor(ctx);
|
|
2467
|
+
// The manifest lets unknown top-level keys through so the desk, not the gateway, can say where they belong:
|
|
2468
|
+
// a long record whose object closed early leaves its last fields beside it.
|
|
2469
|
+
const stray = Object.keys(input).filter((key) => !["uri", "record", "expect_revision", "expect_sha256", "writes"].includes(key));
|
|
2470
|
+
let folded: string[] = [];
|
|
2471
|
+
if (stray.length > 0) {
|
|
2472
|
+
const record = input.record !== null && typeof input.record === "object" && !Array.isArray(input.record) ? (input.record as Json) : null;
|
|
2473
|
+
const fields = record ? recordFields(text(record.schema)) : new Set<string>();
|
|
2474
|
+
// Fields the record's own schema defines and the record lacks are folded in; validation still judges the result.
|
|
2475
|
+
if (!record || stray.some((key) => !fields.has(key) || key in record))
|
|
2476
|
+
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`);
|
|
2477
|
+
input = { ...input, record: { ...record, ...Object.fromEntries(stray.map((key) => [key, input[key]])) } };
|
|
2478
|
+
for (const key of stray) delete input[key];
|
|
2479
|
+
folded = stray;
|
|
2480
|
+
}
|
|
2005
2481
|
const writes = normalizeWrites(input);
|
|
2006
2482
|
const uris = writes.map((write) => write.uri);
|
|
2007
2483
|
if (new Set(uris).size !== uris.length) throw new Error("each record may appear once in writes");
|
|
@@ -2027,6 +2503,7 @@ async function recordTool(ctx: ExtensionContextV2, input: Json): Promise<{ text:
|
|
|
2027
2503
|
return {
|
|
2028
2504
|
text: [
|
|
2029
2505
|
...(recovered ? [recovered] : []),
|
|
2506
|
+
...(folded.length > 0 ? [`${folded.join(", ")} arrived beside record and were moved inside it; send record fields inside record.`] : []),
|
|
2030
2507
|
...done.map((write) => `Wrote ${write.uri}${write.revision === null ? "" : ` at revision ${write.revision}`}; it validated and read back (sha256 ${write.sha256}).`),
|
|
2031
2508
|
...(done.length > 1 ? ["They committed together."] : []),
|
|
2032
2509
|
].join(" "),
|
|
@@ -2037,15 +2514,204 @@ async function recordTool(ctx: ExtensionContextV2, input: Json): Promise<{ text:
|
|
|
2037
2514
|
};
|
|
2038
2515
|
}
|
|
2039
2516
|
|
|
2517
|
+
/**
|
|
2518
|
+
* Authored artifacts keep their own format and are read and written with
|
|
2519
|
+
* Clio's file tools; a refusal names the conventional file so the model does
|
|
2520
|
+
* not search the workspace for it.
|
|
2521
|
+
*/
|
|
2522
|
+
const ARTIFACT_URIS: ReadonlyArray<{ pattern: RegExp; file: (match: RegExpExecArray) => string }> = [
|
|
2523
|
+
{ pattern: new RegExp(`^project://sections/(${IDENTIFIER})/(context|research|summary|handoff)$`, "u"), file: (m) => `.planning/sections/${m[1]}/${m[2]}.md` },
|
|
2524
|
+
{ pattern: new RegExp(`^project://sections/(${IDENTIFIER})/(plans|reviews)/(${IDENTIFIER})$`, "u"), file: (m) => `.planning/sections/${m[1]}/${m[2]}/${m[3]}.md` },
|
|
2525
|
+
{ pattern: /^project:\/\/paper\/([^\s]+)$/u, file: (m) => `paper/${m[1]}` },
|
|
2526
|
+
];
|
|
2527
|
+
|
|
2528
|
+
function notARecord(uri: string): string {
|
|
2529
|
+
for (const artifact of ARTIFACT_URIS) {
|
|
2530
|
+
const match = artifact.pattern.exec(uri);
|
|
2531
|
+
if (match) return `${uri} is an authored artifact, not a JSON record; read or write ${artifact.file(match)} with the file tools`;
|
|
2532
|
+
}
|
|
2533
|
+
const family = /^project:\/\/(sections|sources|evidence|checkpoints|validations)\/([^/]+)$/u.exec(uri);
|
|
2534
|
+
if (family && !new RegExp(`^${IDENTIFIER}$`, "u").test(family[2] ?? ""))
|
|
2535
|
+
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"}`;
|
|
2536
|
+
return `${uri} is not a logical record URI this adapter maps`;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
/** How much record JSON one family read returns before it names the rest by id. */
|
|
2540
|
+
const FAMILY_LIMIT = 48 * 1024;
|
|
2541
|
+
|
|
2542
|
+
/**
|
|
2543
|
+
* How much record JSON a family read returns in full. Live, audit-milestone
|
|
2544
|
+
* and submit-milestone read every validation of a delivered paper in full,
|
|
2545
|
+
* over 100 KB, which every later call of the turn resent; past this budget a
|
|
2546
|
+
* family read lists one digest row per record instead.
|
|
2547
|
+
*/
|
|
2548
|
+
const FAMILY_FULL_LIMIT = 16 * 1024;
|
|
2549
|
+
|
|
2550
|
+
const FAMILIES = ["sections", "sources", "evidence", "checkpoints", "validations", "interactions"] as const;
|
|
2551
|
+
const FAMILY_URI = new RegExp(`^project://(${FAMILIES.join("|")})/?\\*?(?:\\?(.*))?$`, "u");
|
|
2552
|
+
|
|
2553
|
+
/** A family read's query: `section` narrows it to one section's records, `after` pages past a record id. */
|
|
2554
|
+
function familyQuery(uri: string, query: string | undefined): { section: string | null; after: string | null } {
|
|
2555
|
+
const parsed: { section: string | null; after: string | null } = { section: null, after: null };
|
|
2556
|
+
for (const pair of (query ?? "").split("&").filter(Boolean)) {
|
|
2557
|
+
const [key, value = ""] = pair.split("=");
|
|
2558
|
+
if ((key !== "section" && key !== "after") || !new RegExp(`^${IDENTIFIER}$`, "u").test(value))
|
|
2559
|
+
throw new Error(`${uri} has an unknown query; a family read takes section=<section id> and after=<record id>, such as project://validations?section=introduction`);
|
|
2560
|
+
parsed[key] = value;
|
|
2561
|
+
}
|
|
2562
|
+
return parsed;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
/** The URIs a section owns, and its claims, so a family read can keep only the records about it. */
|
|
2566
|
+
function sectionReach(workspace: string, desk: Desk, section: string): { prefix: string; owned: string[]; claims: Set<string>; evidence: Set<string> } {
|
|
2567
|
+
const row = desk.sections.find((entry) => entry.id === section);
|
|
2568
|
+
if (!row && readBytes(workspace, `.planning/sections/${section}/section.json`) === null)
|
|
2569
|
+
throw new Error(`there is no section ${section}; read project://sections for the section ids`);
|
|
2570
|
+
const record = readRecord(workspace, `.planning/sections/${section}/section.json`);
|
|
2571
|
+
const claims = Array.isArray(record?.claims) ? (record.claims as Json[]) : [];
|
|
2572
|
+
return {
|
|
2573
|
+
prefix: `project://sections/${section}`,
|
|
2574
|
+
owned: scopes(section, row?.manuscript ?? null),
|
|
2575
|
+
claims: new Set(claims.map((claim) => text(claim.id)).filter(Boolean)),
|
|
2576
|
+
evidence: new Set(claims.flatMap((claim) => (Array.isArray(claim.evidence_uris) ? claim.evidence_uris.map(String) : []))),
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
function within(uri: unknown, reach: { prefix: string; owned: string[] }): boolean {
|
|
2581
|
+
const value = text(uri);
|
|
2582
|
+
return value === reach.prefix || value.startsWith(`${reach.prefix}/`) || reach.owned.includes(value);
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
/** One line of a family listed by digest: what the record is and its outcome, with the version to write it back. */
|
|
2586
|
+
function digestRow(collection: string, read: Json): Json {
|
|
2587
|
+
const record = (read.record ?? {}) as Json;
|
|
2588
|
+
const row: Json = { uri: read.uri, ...(read.revision === null ? {} : { revision: read.revision }), sha256: read.sha256 };
|
|
2589
|
+
const pick = (...keys: string[]) => {
|
|
2590
|
+
for (const key of keys) {
|
|
2591
|
+
const value = record[key];
|
|
2592
|
+
if (value !== undefined && value !== null) row[key] = typeof value === "string" && value.length > 160 ? `${value.slice(0, 159)}…` : value;
|
|
2593
|
+
}
|
|
2594
|
+
};
|
|
2595
|
+
if (collection === "validations") {
|
|
2596
|
+
pick("action_id", "validator_role", "subject_uri", "status", "executed_at");
|
|
2597
|
+
const checks = Array.isArray(record.checks) ? (record.checks as Json[]) : [];
|
|
2598
|
+
row.failed_checks = checks.filter((check) => check.status !== "passed").map((check) => check.id);
|
|
2599
|
+
row.issues = Array.isArray(record.issues) ? record.issues.length : 0;
|
|
2600
|
+
} else if (collection === "checkpoints") {
|
|
2601
|
+
pick("kind", "scope_uri", "status", "blocking", "created_at");
|
|
2602
|
+
if (read.trust !== undefined) row.trust = read.trust;
|
|
2603
|
+
} else if (collection === "sections") pick("title", "status", "word_count", "word_target", "wave");
|
|
2604
|
+
else if (collection === "sources") pick("citation_key", "title", "year", "kind", "status");
|
|
2605
|
+
else if (collection === "evidence") pick("claim_id", "source_uri", "relation", "confidence", "verified_at");
|
|
2606
|
+
else pick("kind", "subject_uri", "outcome", "selected_option", "answered_at");
|
|
2607
|
+
return row;
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
/**
|
|
2611
|
+
* The records of one family, such as `project://sources`, in one call: in
|
|
2612
|
+
* full while they fit FAMILY_FULL_LIMIT, otherwise one digest row each, so a
|
|
2613
|
+
* grown family never floods the turn. `?section=` keeps only one section's
|
|
2614
|
+
* records; `?after=` pages past FAMILY_LIMIT.
|
|
2615
|
+
*/
|
|
2616
|
+
function readFamily(ctx: ExtensionContextV2, desk: Desk, collection: string, query: { section: string | null; after: string | null }): { text: string; data: unknown } {
|
|
2617
|
+
const workspace = ctx.snapshot.workspace;
|
|
2618
|
+
const identifier = new RegExp(`^${IDENTIFIER}$`, "u");
|
|
2619
|
+
const reach = query.section === null ? null : sectionReach(workspace, desk, query.section);
|
|
2620
|
+
let ids: string[];
|
|
2621
|
+
if (collection === "sections") {
|
|
2622
|
+
const directory = contained(workspace, ".planning/sections");
|
|
2623
|
+
ids =
|
|
2624
|
+
directory === null || !existsSync(directory) || !lstatSync(directory).isDirectory()
|
|
2625
|
+
? []
|
|
2626
|
+
: readdirSync(directory, { withFileTypes: true })
|
|
2627
|
+
.filter((entry) => entry.isDirectory() && identifier.test(entry.name) && readBytes(workspace, `.planning/sections/${entry.name}/section.json`) !== null)
|
|
2628
|
+
.map((entry) => entry.name)
|
|
2629
|
+
.sort();
|
|
2630
|
+
} else ids = listJson(workspace, `.planning/${collection}`).map((file) => path.posix.basename(file, ".json")).filter((id) => identifier.test(id));
|
|
2631
|
+
const reads: Json[] = [];
|
|
2632
|
+
const failed: string[] = [];
|
|
2633
|
+
for (const id of ids) {
|
|
2634
|
+
try {
|
|
2635
|
+
reads.push(readTool(ctx, desk, `project://${collection}/${id}`).data as Json);
|
|
2636
|
+
} catch (error) {
|
|
2637
|
+
failed.push(`${id} (${error instanceof Error ? error.message : String(error)})`);
|
|
2638
|
+
}
|
|
2639
|
+
}
|
|
2640
|
+
// Interactions answer checkpoints, so a section's interactions are those about its checkpoints.
|
|
2641
|
+
const sectionCheckpoints =
|
|
2642
|
+
reach && collection === "interactions"
|
|
2643
|
+
? new Set(listJson(workspace, ".planning/checkpoints").flatMap((file) => {
|
|
2644
|
+
const checkpoint = readRecord(workspace, file);
|
|
2645
|
+
return checkpoint && within(checkpoint.scope_uri, reach) ? [`project://checkpoints/${path.posix.basename(file, ".json")}`] : [];
|
|
2646
|
+
}))
|
|
2647
|
+
: null;
|
|
2648
|
+
const sectionSources =
|
|
2649
|
+
reach && collection === "sources"
|
|
2650
|
+
? new Set(listJson(workspace, ".planning/evidence").flatMap((file) => {
|
|
2651
|
+
const evidence = readRecord(workspace, file);
|
|
2652
|
+
const uri = `project://evidence/${path.posix.basename(file, ".json")}`;
|
|
2653
|
+
return evidence && (reach.claims.has(text(evidence.claim_id)) || reach.evidence.has(uri)) ? [text(evidence.source_uri)] : [];
|
|
2654
|
+
}))
|
|
2655
|
+
: null;
|
|
2656
|
+
const about = (read: Json): boolean => {
|
|
2657
|
+
if (!reach) return true;
|
|
2658
|
+
const record = (read.record ?? {}) as Json;
|
|
2659
|
+
if (collection === "sections") return read.uri === reach.prefix;
|
|
2660
|
+
if (collection === "validations") return within(record.subject_uri, reach);
|
|
2661
|
+
if (collection === "checkpoints") return within(record.scope_uri, reach);
|
|
2662
|
+
if (collection === "evidence") return reach.claims.has(text(record.claim_id)) || reach.evidence.has(text(read.uri));
|
|
2663
|
+
if (collection === "sources") return sectionSources?.has(text(read.uri)) ?? false;
|
|
2664
|
+
return within(record.subject_uri, reach) || (sectionCheckpoints?.has(text(record.subject_uri)) ?? false);
|
|
2665
|
+
};
|
|
2666
|
+
const selected = reads.filter(about);
|
|
2667
|
+
const total = selected.length;
|
|
2668
|
+
const fullSize = selected.reduce((sum, read) => sum + JSON.stringify(read).length, 0);
|
|
2669
|
+
const digest = fullSize > FAMILY_FULL_LIMIT;
|
|
2670
|
+
const pending = query.after === null ? selected : selected.filter((read) => String(read.uri).split("/").pop()! > (query.after as string));
|
|
2671
|
+
const records: Json[] = [];
|
|
2672
|
+
const omitted: string[] = [];
|
|
2673
|
+
let size = 0;
|
|
2674
|
+
for (const read of pending) {
|
|
2675
|
+
const entry = digest ? digestRow(collection, read) : read;
|
|
2676
|
+
const length = JSON.stringify(entry).length;
|
|
2677
|
+
if (omitted.length > 0 || (records.length > 0 && size + length > FAMILY_LIMIT)) {
|
|
2678
|
+
omitted.push(String(read.uri).split("/").pop() ?? "");
|
|
2679
|
+
continue;
|
|
2680
|
+
}
|
|
2681
|
+
records.push(entry);
|
|
2682
|
+
size += length;
|
|
2683
|
+
}
|
|
2684
|
+
const uri = `project://${collection}`;
|
|
2685
|
+
const scope = query.section === null ? uri : `${uri}?section=${query.section}`;
|
|
2686
|
+
const next = [query.section === null ? "" : `section=${query.section}`, `after=${String(records[records.length - 1]?.uri ?? "").split("/").pop()}`].filter(Boolean).join("&");
|
|
2687
|
+
const held = query.section === null ? "" : ` about section ${query.section}`;
|
|
2688
|
+
return {
|
|
2689
|
+
text: [
|
|
2690
|
+
total === 0
|
|
2691
|
+
? `${uri} holds no records${held} yet.`
|
|
2692
|
+
: digest
|
|
2693
|
+
? `${uri} holds ${total} ${total === 1 ? "record" : "records"}${held}, ${Math.round(fullSize / 1024)} KB in full, so this read lists ${records.length}${query.after !== null ? ` after ${query.after}` : ""} as one digest row each: what it is, its outcome, and the version to pass back to record. Read a record at its uri for every field${query.section === null ? ", or keep one section's records with ?section=<section id>" : ""}.`
|
|
2694
|
+
: `${uri} holds ${total} ${total === 1 ? "record" : "records"}${held}; ${records.length}${query.after !== null ? ` after ${query.after}` : ""} returned in full, each with the revision and sha256 to pass back to record.`,
|
|
2695
|
+
omitted.length > 0 ? `${omitted.length} more not returned, to keep this read small; read the next page with ${uri}?${next}.` : "",
|
|
2696
|
+
failed.length > 0 ? `Not readable: ${failed.join("; ")}.` : "",
|
|
2697
|
+
]
|
|
2698
|
+
.filter(Boolean)
|
|
2699
|
+
.join(" "),
|
|
2700
|
+
data: { uri: scope, form: digest ? "digest" : "full", records, omitted, ...(failed.length > 0 ? { failed } : {}) },
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2703
|
+
|
|
2040
2704
|
function readTool(ctx: ExtensionContextV2, desk: Desk, uri: string): { text: string; data: unknown } {
|
|
2041
2705
|
const workspace = ctx.snapshot.workspace;
|
|
2706
|
+
const family = FAMILY_URI.exec(uri);
|
|
2707
|
+
if (family) return readFamily(ctx, desk, family[1] as string, familyQuery(uri, family[2]));
|
|
2042
2708
|
const route = RECORD_URIS.find((entry) => entry.pattern.test(uri));
|
|
2043
|
-
if (!route) throw new Error(
|
|
2709
|
+
if (!route) throw new Error(notARecord(uri));
|
|
2044
2710
|
const file = route.file(route.pattern.exec(uri)?.[1] ?? "");
|
|
2045
2711
|
const bytes = readBytes(workspace, file);
|
|
2046
2712
|
if (bytes === null) {
|
|
2047
2713
|
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 } };
|
|
2714
|
+
return { text: withTemplate(`${uri} does not exist yet; create it without expect_revision or expect_sha256.`, route.type), data: { uri, file, exists: false } };
|
|
2049
2715
|
}
|
|
2050
2716
|
let record: unknown;
|
|
2051
2717
|
try {
|
|
@@ -2061,7 +2727,57 @@ function readTool(ctx: ExtensionContextV2, desk: Desk, uri: string): { text: str
|
|
|
2061
2727
|
};
|
|
2062
2728
|
}
|
|
2063
2729
|
|
|
2064
|
-
|
|
2730
|
+
/**
|
|
2731
|
+
* An immutable milestone snapshot: every `.planning` file outside the archives
|
|
2732
|
+
* and every `paper/` file, copied byte for byte under
|
|
2733
|
+
* `.planning/archives/<archive>/` beside a manifest of their sha256 digests.
|
|
2734
|
+
* Live, a model could not copy a whole project by hand within a turn. Only an
|
|
2735
|
+
* armed action that declares the archive may make one, links are never
|
|
2736
|
+
* followed, and an existing archive is never touched.
|
|
2737
|
+
*/
|
|
2738
|
+
function archiveProject(workspace: string, archive: string, armed: Armed | null, projectId: string | null): { uri: string; files: number; manifest: string; sha256: string } {
|
|
2739
|
+
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`);
|
|
2740
|
+
const uri = `project://archives/${archive}`;
|
|
2741
|
+
if (!armed || !declares(armed, `${uri}/manifest.json`, "archive"))
|
|
2742
|
+
throw new Error(`${armed ? armed.action : "nothing armed"} does not declare archiving ${uri}; only the action that owns a milestone archive may make one`);
|
|
2743
|
+
return withLock(workspace, () => {
|
|
2744
|
+
recover(workspace);
|
|
2745
|
+
const target = `.planning/archives/${archive}`;
|
|
2746
|
+
const destination = contained(workspace, target);
|
|
2747
|
+
if (destination === null) throw new Error(`${target} is reached through a symbolic link; the desk does not follow links`);
|
|
2748
|
+
if (existsSync(destination)) throw new Error(`${uri} already exists, and an archive is immutable; choose another id`);
|
|
2749
|
+
const files: Array<{ path: string; sha256: string; bytes: number }> = [];
|
|
2750
|
+
const walk = (relative: string): void => {
|
|
2751
|
+
const directory = contained(workspace, relative);
|
|
2752
|
+
if (directory === null || !existsSync(directory) || !lstatSync(directory).isDirectory()) return;
|
|
2753
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
2754
|
+
const child = path.posix.join(relative, entry.name);
|
|
2755
|
+
if (entry.name.startsWith(".") || child === ".planning/archives" || entry.isSymbolicLink()) continue;
|
|
2756
|
+
if (entry.isDirectory()) walk(child);
|
|
2757
|
+
else if (entry.isFile()) {
|
|
2758
|
+
const bytes = readBytes(workspace, child);
|
|
2759
|
+
if (bytes === null) throw new Error(`${child} could not be read whole, so the archive would be incomplete`);
|
|
2760
|
+
files.push({ path: child, sha256: sha256(bytes), bytes: bytes.length });
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
};
|
|
2764
|
+
walk(".planning");
|
|
2765
|
+
walk("paper");
|
|
2766
|
+
const staging = `${destination}.staging-${randomBytes(4).toString("hex")}`;
|
|
2767
|
+
mkdirSync(staging, { recursive: true });
|
|
2768
|
+
for (const file of files) {
|
|
2769
|
+
const out = path.join(staging, file.path);
|
|
2770
|
+
mkdirSync(path.dirname(out), { recursive: true });
|
|
2771
|
+
writeFileSync(out, readFileSync(path.join(workspace, file.path)));
|
|
2772
|
+
}
|
|
2773
|
+
const manifest = `${JSON.stringify({ archive: uri, project_id: projectId, created_at: timestamp(), files }, null, 2)}\n`;
|
|
2774
|
+
writeFileSync(path.join(staging, "manifest.json"), manifest);
|
|
2775
|
+
renameSync(staging, destination);
|
|
2776
|
+
return { uri, files: files.length, manifest: `${target}/manifest.json`, sha256: sha256(manifest) };
|
|
2777
|
+
});
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
function measureSection(workspace: string, sectionId: string, key: Buffer | null, armed: Armed | null): { words: number; target: number; file: string | null; total: number; recorded: boolean } {
|
|
2065
2781
|
return withLock(workspace, () => {
|
|
2066
2782
|
recover(workspace);
|
|
2067
2783
|
const desk = loadDesk(workspace, key);
|
|
@@ -2081,9 +2797,12 @@ function measureSection(workspace: string, sectionId: string, key: Buffer | null
|
|
|
2081
2797
|
expect_revision: typeof state.revision === "number" ? state.revision : 0,
|
|
2082
2798
|
record: { ...state, progress: { ...(state.progress as Json), word_count: recorded } },
|
|
2083
2799
|
});
|
|
2800
|
+
// An action that may not update these records still gets the desk's count, so it never counts by hand.
|
|
2801
|
+
if (armed && !writes.every((write) => declares(armed, write.uri, "update")))
|
|
2802
|
+
return { words: section.words, target: section.target, file: section.manuscript, total: recorded, recorded: false };
|
|
2084
2803
|
const prepared = writes.map((write) => prepare(workspace, write, "agent", armed));
|
|
2085
2804
|
commit(workspace, prepared.map((entry) => entry.write));
|
|
2086
|
-
return { words: section.words, target: section.target, file: section.manuscript, total: recorded };
|
|
2805
|
+
return { words: section.words, target: section.target, file: section.manuscript, total: recorded, recorded: true };
|
|
2087
2806
|
});
|
|
2088
2807
|
}
|
|
2089
2808
|
|
|
@@ -2166,6 +2885,71 @@ function progressText(desk: Desk): string {
|
|
|
2166
2885
|
].join("\n");
|
|
2167
2886
|
}
|
|
2168
2887
|
|
|
2888
|
+
/**
|
|
2889
|
+
* The project as one compact record for an agent: what an action would
|
|
2890
|
+
* otherwise reconstruct from many record reads. It reports, never decides;
|
|
2891
|
+
* an action still reads the records it will change or quote.
|
|
2892
|
+
*/
|
|
2893
|
+
function statusDigest(desk: Desk): Json {
|
|
2894
|
+
const next = nextAction(desk);
|
|
2895
|
+
return {
|
|
2896
|
+
present: desk.present,
|
|
2897
|
+
...(desk.present
|
|
2898
|
+
? {
|
|
2899
|
+
project: { id: desk.projectId, title: desk.title, document_type: desk.documentType, venue: desk.venue, deadline: desk.deadline, argument: desk.argument },
|
|
2900
|
+
phase: desk.phase,
|
|
2901
|
+
status: desk.status,
|
|
2902
|
+
words: { total: totalWords(desk), target: desk.targetWords, method: WORD_METHOD },
|
|
2903
|
+
sections: desk.sections.map((section) => ({
|
|
2904
|
+
id: section.id,
|
|
2905
|
+
title: section.title,
|
|
2906
|
+
wave: section.wave,
|
|
2907
|
+
status: section.status,
|
|
2908
|
+
depends_on: section.dependsOn,
|
|
2909
|
+
words: section.words,
|
|
2910
|
+
target: section.target,
|
|
2911
|
+
manuscript: section.manuscript,
|
|
2912
|
+
stages: section.stages,
|
|
2913
|
+
plan: { state: section.plan.state, uri: section.plan.uri, reason: section.plan.reason },
|
|
2914
|
+
research_required: section.research.required,
|
|
2915
|
+
claims: section.claims,
|
|
2916
|
+
unsupported_claims: section.unsupported,
|
|
2917
|
+
blockers: blockers(desk, section),
|
|
2918
|
+
})),
|
|
2919
|
+
open_gates: openGates(desk).map((gate) => ({ id: gate.id, kind: gate.kind, scope: gate.scope_uri, request: gate.request, trust: gate.trust })),
|
|
2920
|
+
evidence: { sources: desk.sources, evidence: desk.evidence },
|
|
2921
|
+
issues: desk.issues,
|
|
2922
|
+
invalid_records: desk.invalid.map((entry) => entry.file),
|
|
2923
|
+
interrupted_write: desk.journal,
|
|
2924
|
+
}
|
|
2925
|
+
: {}),
|
|
2926
|
+
next: { action: next.action ?? null, section: next.section ?? null, gate: next.gate ?? null, command: next.command, reason: next.reason },
|
|
2927
|
+
};
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
/** Clio refuses effect text longer than this many UTF-16 code units. */
|
|
2931
|
+
const EFFECT_TEXT_LIMIT = 2000;
|
|
2932
|
+
|
|
2933
|
+
/** Text cut to Clio's effect limit with `tail` appended, never splitting a surrogate pair. */
|
|
2934
|
+
function clip(message: string, tail: string): string {
|
|
2935
|
+
if (message.length <= EFFECT_TEXT_LIMIT) return message;
|
|
2936
|
+
let end = EFFECT_TEXT_LIMIT - tail.length;
|
|
2937
|
+
const last = message.charCodeAt(end - 1);
|
|
2938
|
+
if (last >= 0xd800 && last <= 0xdbff) end -= 1;
|
|
2939
|
+
return `${message.slice(0, end)}${tail}`;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
/** The desk's status as one reminder within Clio's effect limit. */
|
|
2943
|
+
function statusReminder(desk: Desk): string {
|
|
2944
|
+
const gates = openGates(desk);
|
|
2945
|
+
const lines = [
|
|
2946
|
+
"WTF-P desk status at the start of this turn (extension_wtfp__status returns it as structured data):",
|
|
2947
|
+
progressText(desk),
|
|
2948
|
+
...(gates.length > 0 ? [`Open gates: ${gates.map((gate) => `${gate.id} (${gate.scope_uri.replace(/^project:\/\//u, "")})`).join(", ")}`] : []),
|
|
2949
|
+
];
|
|
2950
|
+
return clip(lines.join("\n"), "\n… (truncated; call extension_wtfp__status)");
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2169
2953
|
function helpCard(served: ServedPlugin): { text: string; card: View } {
|
|
2170
2954
|
const availability = JSON.parse(
|
|
2171
2955
|
readFileSync(path.join(PACKAGE_ROOT, "compatibility", "action-availability.json"), "utf8"),
|
|
@@ -2528,7 +3312,9 @@ async function guardWrite(ctx: ExtensionContextV2, target: string, host?: HostTa
|
|
|
2528
3312
|
const roots = writeRoots(desk, armed);
|
|
2529
3313
|
if (!roots.some((allowed) => under(allowed, relative)))
|
|
2530
3314
|
return block(
|
|
2531
|
-
|
|
3315
|
+
armed.action === "advance"
|
|
3316
|
+
? `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.`
|
|
3317
|
+
: `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
3318
|
);
|
|
2533
3319
|
}
|
|
2534
3320
|
for (const section of desk.sections) {
|
|
@@ -2697,6 +3483,13 @@ async function guardDispatch(ctx: ExtensionContextV2, args: Json, host?: HostDis
|
|
|
2697
3483
|
return {};
|
|
2698
3484
|
}
|
|
2699
3485
|
const name = actionName(served, armed.action);
|
|
3486
|
+
// Inside an action that delegates, a writing worker is one of its roles; a call without agent falls to Clio's default worker.
|
|
3487
|
+
const agents = GUARD.actions[armed.action]?.agents ?? [];
|
|
3488
|
+
const stranger = agents.length > 0 ? entries.find((entry) => !entry.readOnly && !agents.includes(entry.agent)) : undefined;
|
|
3489
|
+
if (stranger)
|
|
3490
|
+
return block(
|
|
3491
|
+
`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]}").`,
|
|
3492
|
+
);
|
|
2700
3493
|
// A worker never gets a root that holds records: the record tool is the only way records change.
|
|
2701
3494
|
const base = writeRoots(desk, armed).filter((root) => ![".", ".planning", ".planning/sections"].includes(root.replace(/\/$/u, "")));
|
|
2702
3495
|
const held = heldManuscripts(desk);
|
|
@@ -2720,7 +3513,9 @@ async function guardDispatch(ctx: ExtensionContextV2, args: Json, host?: HostDis
|
|
|
2720
3513
|
const roots = entry.roots === null ? allowed : narrow(entry.roots, allowed);
|
|
2721
3514
|
if (paperWriters.has(entry.agent) && !roots.some((root) => root.startsWith("paper/")))
|
|
2722
3515
|
throw new Error(
|
|
2723
|
-
|
|
3516
|
+
entry.roots !== null && allowed.some((root) => root.startsWith("paper/"))
|
|
3517
|
+
? `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).`
|
|
3518
|
+
: `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
3519
|
);
|
|
2725
3520
|
if (roots.length > 0) return roots;
|
|
2726
3521
|
// Clio reads an empty write_roots as no boundary at all, so an empty list is refused, never sent.
|
|
@@ -2748,6 +3543,16 @@ async function guardDispatch(ctx: ExtensionContextV2, args: Json, host?: HostDis
|
|
|
2748
3543
|
.map((entry, index) => `task ${index + 1} (${entry.agent}): ${(narrowed[index] ?? []).join(", ") || "none, it only reads"}`)
|
|
2749
3544
|
.join("; ")}.`,
|
|
2750
3545
|
);
|
|
3546
|
+
// Clio admits an extension's rewrite only as a narrowing. A declared intent without write roots is an empty
|
|
3547
|
+
// write ceiling there, although the worker itself treats it as no boundary, so the desk cannot fill the roots in.
|
|
3548
|
+
const declaresEmpty = (item: unknown): boolean =>
|
|
3549
|
+
isObject(item) && isObject(item.intent) && (!Array.isArray(item.intent.write_roots) || item.intent.write_roots.length === 0);
|
|
3550
|
+
if (declaresEmpty(args) || (Array.isArray(args.tasks) && args.tasks.some(declaresEmpty)))
|
|
3551
|
+
return block(
|
|
3552
|
+
`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
|
|
3553
|
+
.map((entry, index) => `${entries.length > 1 ? `task ${index + 1} (${entry.agent}) ` : ""}intent.write_roots ${(needed[index] ?? []).join(", ") || "omitted, since it only reads"}`)
|
|
3554
|
+
.join("; ")} in that intent.`,
|
|
3555
|
+
);
|
|
2751
3556
|
const rewritten = confineCall(args, needed);
|
|
2752
3557
|
return {
|
|
2753
3558
|
effects: [
|
|
@@ -2764,6 +3569,31 @@ const BASH_DESK_PATHS = /\.planning\/(?:interactions\b|\.wtfp-)/u;
|
|
|
2764
3569
|
/** Tools that run a command or script; the desk can only refuse ones that name its own records. */
|
|
2765
3570
|
const COMMAND_TOOLS = new Set(["bash", "run_script", "job"]);
|
|
2766
3571
|
|
|
3572
|
+
/**
|
|
3573
|
+
* Inside a WTF-P action every question is the author's. Clio answers an
|
|
3574
|
+
* unanswered `ask_user` round with its recommended option after
|
|
3575
|
+
* `safety.unattendedAfterSeconds`, unless the question is `operator_only`, so
|
|
3576
|
+
* the desk marks a lone question that way and refuses a round that would need
|
|
3577
|
+
* splitting, since an `operator_only` question is asked alone.
|
|
3578
|
+
*/
|
|
3579
|
+
async function guardQuestions(ctx: ExtensionContextV2, input: Json): Promise<ExtensionHookResult> {
|
|
3580
|
+
if (input.action === "complete") return {};
|
|
3581
|
+
const questions = Array.isArray(input.questions) ? (input.questions as unknown[]) : [];
|
|
3582
|
+
if (questions.length === 0 || questions.every((question) => (question as Json | null)?.operator_only === true)) return {};
|
|
3583
|
+
if (!(await armedFor(ctx))) return {};
|
|
3584
|
+
if (questions.length > 1)
|
|
3585
|
+
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.");
|
|
3586
|
+
return {
|
|
3587
|
+
effects: [
|
|
3588
|
+
{
|
|
3589
|
+
kind: "rewrite_tool_input",
|
|
3590
|
+
args: { ...input, questions: [{ ...(questions[0] as Json), operator_only: true }] },
|
|
3591
|
+
reason: "WTF-P asks the author, and only the author may answer: Clio never takes a recommended option for this question.",
|
|
3592
|
+
},
|
|
3593
|
+
],
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
|
|
2767
3597
|
async function guard(ctx: ExtensionContextV2, tool: string, args: unknown, event: unknown = {}): Promise<ExtensionHookResult> {
|
|
2768
3598
|
const input = args !== null && typeof args === "object" ? (args as Json) : {};
|
|
2769
3599
|
const effects: ExtensionEffect[] = [];
|
|
@@ -2778,6 +3608,7 @@ async function guard(ctx: ExtensionContextV2, tool: string, args: unknown, event
|
|
|
2778
3608
|
// A host that sends facts once sends them for every call it can resolve, so a later call without them failed in Clio.
|
|
2779
3609
|
if ((host.target || host.dispatch) && !(await ctx.state.get<boolean>("host-facts")).value) await ctx.state.set("host-facts", true);
|
|
2780
3610
|
if (tool === "dispatch") result = await guardDispatch(ctx, input, host.dispatch, host.malformed);
|
|
3611
|
+
else if (tool === "ask_user") result = await guardQuestions(ctx, input);
|
|
2781
3612
|
else if (COMMAND_TOOLS.has(tool)) {
|
|
2782
3613
|
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
3614
|
} else {
|
|
@@ -2792,9 +3623,48 @@ async function guard(ctx: ExtensionContextV2, tool: string, args: unknown, event
|
|
|
2792
3623
|
return effects.length === 0 ? result : { ...result, effects: [...effects, ...(result.effects ?? [])] };
|
|
2793
3624
|
}
|
|
2794
3625
|
|
|
3626
|
+
/**
|
|
3627
|
+
* A note on a successful write or edit that changed a manuscript the armed
|
|
3628
|
+
* action may measure: its recorded word count is stale until measure_section
|
|
3629
|
+
* runs. It rides on the tool result, so it spends none of the turn's shared
|
|
3630
|
+
* continuation budget, and it reaches a dispatched worker too, whose writes
|
|
3631
|
+
* Clio hooks, so it says whose call the measurement is. Each section is noted
|
|
3632
|
+
* once until it is measured again.
|
|
3633
|
+
*/
|
|
3634
|
+
async function noteManuscriptWrite(ctx: ExtensionContextV2, event: unknown): Promise<ExtensionHookResult> {
|
|
3635
|
+
const armed = await armedFor(ctx);
|
|
3636
|
+
if (!armed || !armed.produces.some((output) => output.uri.startsWith("project://paper/"))) return {};
|
|
3637
|
+
const target = hostLanding(event).target;
|
|
3638
|
+
if (!target) return {};
|
|
3639
|
+
const landed = writeLanding("", ctx.snapshot.workspace, target);
|
|
3640
|
+
if ("refused" in landed || landed.relative === null || !under("paper", landed.relative)) return {};
|
|
3641
|
+
const desk = loadDesk(ctx.snapshot.workspace);
|
|
3642
|
+
const noted = (await ctx.state.get<string[]>("measure-noted")).value ?? [];
|
|
3643
|
+
const sections = sectionsForPaper(desk, landed.relative)
|
|
3644
|
+
.map((section) => section.id)
|
|
3645
|
+
.filter((id) => !noted.includes(id) && declares(armed, `project://sections/${id}`, "update"));
|
|
3646
|
+
if (sections.length === 0) return {};
|
|
3647
|
+
await ctx.state.set("measure-noted", [...noted, ...sections]);
|
|
3648
|
+
const calls = sections.map((id) => `gateway(op="call", capability="extension_wtfp__measure_section", args={section: "${id}"})`).join(" and ");
|
|
3649
|
+
return {
|
|
3650
|
+
effects: [
|
|
3651
|
+
{
|
|
3652
|
+
kind: "annotate_tool_result",
|
|
3653
|
+
severity: "info",
|
|
3654
|
+
message: clip(
|
|
3655
|
+
`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.`,
|
|
3656
|
+
"…",
|
|
3657
|
+
),
|
|
3658
|
+
},
|
|
3659
|
+
],
|
|
3660
|
+
};
|
|
3661
|
+
}
|
|
3662
|
+
|
|
2795
3663
|
function arm(text: string, desk: Desk, workspace: string): Armed | null {
|
|
2796
3664
|
const match = /^\s*\/wtfp:([a-z][a-z0-9-]*)(?:\s+(\S+))?/u.exec(text);
|
|
2797
3665
|
if (!match) return null;
|
|
3666
|
+
// The driver arms nothing itself; next_step arms each step it selects.
|
|
3667
|
+
if (match[1] === "advance") return GUARD.actions.advance ? idleArm(workspace) : null;
|
|
2798
3668
|
const action = GUARD.actions[match[1] as string];
|
|
2799
3669
|
if (!action) return null;
|
|
2800
3670
|
const candidate = match[2] ?? "";
|
|
@@ -2830,6 +3700,12 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2830
3700
|
return next.command ? { text: next.command, prompt: { fill: next.command } } : { text: next.reason, toast: { text: next.reason } };
|
|
2831
3701
|
});
|
|
2832
3702
|
api.action("gates", async (_event, ctx) => startGates(ctx));
|
|
3703
|
+
api.action("advance", async (_event, ctx) => {
|
|
3704
|
+
const command = commandFor(ctx.snapshot.plugin ?? null, "advance");
|
|
3705
|
+
return command
|
|
3706
|
+
? { text: command, prompt: { fill: command } }
|
|
3707
|
+
: { text: "advance needs the WTF-P plugin.", toast: { text: "advance needs the WTF-P plugin." } };
|
|
3708
|
+
});
|
|
2833
3709
|
api.action("validate", async (_event, ctx) => validateAll(ctx));
|
|
2834
3710
|
api.action("help", async (_event, ctx) => helpCard(ctx.snapshot.plugin ?? null));
|
|
2835
3711
|
api.action("section", async (event, ctx) => {
|
|
@@ -2851,6 +3727,10 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2851
3727
|
return { text: failure("Not written", error), isError: true };
|
|
2852
3728
|
}
|
|
2853
3729
|
});
|
|
3730
|
+
api.tool("status", async (_input, ctx) => {
|
|
3731
|
+
const desk = await deskFor(ctx);
|
|
3732
|
+
return { text: progressText(desk), data: statusDigest(desk) };
|
|
3733
|
+
});
|
|
2854
3734
|
api.tool("read_record", async (input, ctx) => {
|
|
2855
3735
|
try {
|
|
2856
3736
|
return readTool(ctx, await deskFor(ctx), String((input as Json).uri ?? ""));
|
|
@@ -2872,18 +3752,72 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2872
3752
|
return { text: `No readiness: ${error instanceof Error ? error.message : String(error)}`, isError: true };
|
|
2873
3753
|
}
|
|
2874
3754
|
});
|
|
3755
|
+
api.tool("archive", async (input, ctx) => {
|
|
3756
|
+
try {
|
|
3757
|
+
const desk = await deskFor(ctx);
|
|
3758
|
+
const made = archiveProject(ctx.snapshot.workspace, String((input as Json).archive ?? ""), await armedFor(ctx), desk.projectId);
|
|
3759
|
+
return {
|
|
3760
|
+
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.`,
|
|
3761
|
+
data: made,
|
|
3762
|
+
};
|
|
3763
|
+
} catch (error) {
|
|
3764
|
+
return { text: failure("Not archived", error), isError: true };
|
|
3765
|
+
}
|
|
3766
|
+
});
|
|
2875
3767
|
api.tool("measure_section", async (input, ctx) => {
|
|
2876
3768
|
try {
|
|
2877
|
-
const
|
|
3769
|
+
const sectionId = String((input as Json).section ?? "");
|
|
3770
|
+
const measured = measureSection(ctx.snapshot.workspace, sectionId, await storedKey(ctx, false), await armedFor(ctx));
|
|
3771
|
+
const noted = (await ctx.state.get<string[]>("measure-noted")).value ?? [];
|
|
3772
|
+
if (noted.includes(sectionId)) await ctx.state.set("measure-noted", noted.filter((id) => id !== sectionId));
|
|
2878
3773
|
const share = measured.target > 0 ? Math.round((measured.words / measured.target) * 100) : null;
|
|
2879
3774
|
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}`,
|
|
3775
|
+
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
3776
|
data: measured,
|
|
2882
3777
|
};
|
|
2883
3778
|
} catch (error) {
|
|
2884
3779
|
return { text: failure("Not measured", error), isError: true };
|
|
2885
3780
|
}
|
|
2886
3781
|
});
|
|
3782
|
+
api.tool("next_step", async (_input, ctx) => {
|
|
3783
|
+
const workspace = ctx.snapshot.workspace;
|
|
3784
|
+
const drive = (await ctx.state.get<Drive>("drive")).value;
|
|
3785
|
+
if (!drive || drive.workspace !== workspace)
|
|
3786
|
+
return { text: "Only a /wtfp:advance turn can ask the desk for its next step; nothing was armed.", isError: true };
|
|
3787
|
+
let desk = await deskFor(ctx);
|
|
3788
|
+
let recovered: string | null = null;
|
|
3789
|
+
if (desk.journal) {
|
|
3790
|
+
try {
|
|
3791
|
+
recovered = withLock(workspace, () => recover(workspace));
|
|
3792
|
+
} catch (error) {
|
|
3793
|
+
await ctx.state.set("armed", idleArm(workspace));
|
|
3794
|
+
return { text: `${failure("An interrupted record write could not be completed, so the run stops", error)} ${DRIVER_RULE}`, data: { kind: "stop" }, isError: true };
|
|
3795
|
+
}
|
|
3796
|
+
desk = await deskFor(ctx);
|
|
3797
|
+
}
|
|
3798
|
+
const decision = driveStep(desk, drive);
|
|
3799
|
+
const lead = recovered ? `${recovered} ` : "";
|
|
3800
|
+
if (decision.kind !== "step") {
|
|
3801
|
+
// Between steps and after the last one, nothing stays armed for writing.
|
|
3802
|
+
await ctx.state.set("armed", idleArm(workspace));
|
|
3803
|
+
if (decision.kind === "gate") {
|
|
3804
|
+
await ctx.state.set("drive", { ...drive, asked: [...drive.asked, decision.checkpoint] } satisfies Drive);
|
|
3805
|
+
return { text: `${lead}Gate ${decision.checkpoint}: ${decision.reason} Call extension_wtfp__gate with checkpoint ${decision.checkpoint}. ${DRIVER_RULE}`, data: decision };
|
|
3806
|
+
}
|
|
3807
|
+
return { text: `${lead}Stop: ${decision.reason} ${DRIVER_RULE}`, data: decision };
|
|
3808
|
+
}
|
|
3809
|
+
const contract = GUARD.actions[decision.action] as GuardAction;
|
|
3810
|
+
await ctx.state.set("armed", { action: decision.action, produces: contract.produces, section: decision.section, workspace } satisfies Armed);
|
|
3811
|
+
await ctx.state.set("drive", {
|
|
3812
|
+
...drive,
|
|
3813
|
+
steps: [...drive.steps, { action: decision.action, section: decision.section, fingerprint: driveFingerprint(desk), ...(decision.finish ? { finish: true } : {}) }],
|
|
3814
|
+
} satisfies Drive);
|
|
3815
|
+
const invocation = `/wtfp:${decision.action}${decision.section ? ` ${decision.section}` : ""}`;
|
|
3816
|
+
return {
|
|
3817
|
+
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"}. ${STEP_IS_A_PROCEDURE} ${DRIVER_RULE}`,
|
|
3818
|
+
data: decision,
|
|
3819
|
+
};
|
|
3820
|
+
});
|
|
2887
3821
|
api.tool("gate", async (input, ctx) => {
|
|
2888
3822
|
const id = String((input as Json).checkpoint ?? "");
|
|
2889
3823
|
const desk = await deskFor(ctx);
|
|
@@ -2902,7 +3836,13 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2902
3836
|
: "The author did not answer; the gate stays pending.",
|
|
2903
3837
|
};
|
|
2904
3838
|
try {
|
|
2905
|
-
const
|
|
3839
|
+
const typed = await freeText(ctx, event);
|
|
3840
|
+
if (typed?.checkpoint) {
|
|
3841
|
+
const desk = await deskFor(ctx);
|
|
3842
|
+
const current = desk.checkpoints.find((entry) => entry.id === typed.checkpoint);
|
|
3843
|
+
if (current && askable(desk, []).includes(current)) return { step: await ask(ctx, desk, current, FREE_TEXT), total: 1 };
|
|
3844
|
+
}
|
|
3845
|
+
const result = typed ?? (await answer(ctx, event.step, choiceOf(event.answers), noteOf(event)));
|
|
2906
3846
|
if (result.kind === "stale" && result.checkpoint) {
|
|
2907
3847
|
const desk = await deskFor(ctx);
|
|
2908
3848
|
const current = desk.checkpoints.find((entry) => entry.id === result.checkpoint);
|
|
@@ -2927,7 +3867,14 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
2927
3867
|
const recorded = (await ctx.state.get<string[]>("gate-recorded")).value ?? [];
|
|
2928
3868
|
let note = "";
|
|
2929
3869
|
try {
|
|
2930
|
-
const
|
|
3870
|
+
const typed = await freeText(ctx, event);
|
|
3871
|
+
if (typed?.checkpoint) {
|
|
3872
|
+
const desk = await deskFor(ctx);
|
|
3873
|
+
const current = desk.checkpoints.find((entry) => entry.id === typed.checkpoint);
|
|
3874
|
+
const remaining = askable(desk, kept);
|
|
3875
|
+
if (current && remaining.includes(current)) return { step: await ask(ctx, desk, current, FREE_TEXT), total: remaining.length + recorded.length + kept.length };
|
|
3876
|
+
}
|
|
3877
|
+
const result = typed ?? (await answer(ctx, event.step, choiceOf(event.answers), noteOf(event)));
|
|
2931
3878
|
if (result.kind === "recorded") recorded.push(result.text);
|
|
2932
3879
|
else if (result.kind === "kept" && result.checkpoint) kept.push(result.checkpoint);
|
|
2933
3880
|
else if (result.kind === "refused") {
|
|
@@ -3008,14 +3955,39 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
3008
3955
|
});
|
|
3009
3956
|
|
|
3010
3957
|
api.hook("prompt_submit", async (event, ctx) => {
|
|
3958
|
+
// Clio continuing a stopped yolo turn (tool budget, loop guard, a failure) resumes that turn's drive and armed step.
|
|
3959
|
+
const held = (await ctx.state.get<{ armed?: Armed; drive?: Drive; workspace: string }>("held")).value;
|
|
3960
|
+
await ctx.state.delete("held");
|
|
3961
|
+
if (event.point === "prompt_submit" && (event as { origin?: string }).origin === "continuation") {
|
|
3962
|
+
if (held && held.workspace === ctx.snapshot.workspace) {
|
|
3963
|
+
if (held.armed) await ctx.state.set("armed", held.armed);
|
|
3964
|
+
if (held.drive) await ctx.state.set("drive", held.drive);
|
|
3965
|
+
}
|
|
3966
|
+
return {};
|
|
3967
|
+
}
|
|
3011
3968
|
const typed = event.point === "prompt_submit" ? (event.text ?? "") : "";
|
|
3012
3969
|
const desk = loadDesk(ctx.snapshot.workspace);
|
|
3013
3970
|
const armed = arm(typed, desk, ctx.snapshot.workspace);
|
|
3971
|
+
// Only a prompt that starts an advance run starts a drive; any other prompt ends one.
|
|
3972
|
+
await ctx.state.delete("drive");
|
|
3973
|
+
await ctx.state.delete("measure-noted");
|
|
3014
3974
|
if (!armed) {
|
|
3015
3975
|
await ctx.state.delete("armed");
|
|
3016
3976
|
return {};
|
|
3017
3977
|
}
|
|
3018
3978
|
await ctx.state.set("armed", armed);
|
|
3979
|
+
if (armed.action === "advance") {
|
|
3980
|
+
await ctx.state.set("drive", { workspace: ctx.snapshot.workspace, steps: [], asked: [] } satisfies Drive);
|
|
3981
|
+
return {
|
|
3982
|
+
effects: [
|
|
3983
|
+
{
|
|
3984
|
+
kind: "notify_operator",
|
|
3985
|
+
key: "wtfp-guard",
|
|
3986
|
+
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.",
|
|
3987
|
+
},
|
|
3988
|
+
],
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3019
3991
|
const roots = writeRoots(desk, armed);
|
|
3020
3992
|
return {
|
|
3021
3993
|
effects: [
|
|
@@ -3028,6 +4000,14 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
3028
4000
|
};
|
|
3029
4001
|
});
|
|
3030
4002
|
api.hook("before_tool", async (event, ctx) => (event.point === "before_tool" ? guard(ctx, event.tool, event.args, event) : {}));
|
|
4003
|
+
api.hook("after_tool", async (event, ctx) => (event.point === "after_tool" && event.outcome === "ok" ? noteManuscriptWrite(ctx, event) : {}));
|
|
4004
|
+
// A WTF-P turn starts from the desk's picture of the project, so the action need not rebuild it from records.
|
|
4005
|
+
api.hook("turn_start", async (event, ctx) => {
|
|
4006
|
+
if (event.point !== "turn_start" || !(await armedFor(ctx))) return {};
|
|
4007
|
+
const desk = await deskFor(ctx);
|
|
4008
|
+
if (!desk.present) return {};
|
|
4009
|
+
return { effects: [{ kind: "inject_reminder", audience: "model", severity: "info", message: statusReminder(desk) }] };
|
|
4010
|
+
});
|
|
3031
4011
|
|
|
3032
4012
|
api.on("session_open", async (_event, ctx) => {
|
|
3033
4013
|
const workspace = ctx.snapshot.workspace;
|
|
@@ -3040,8 +4020,14 @@ export default function extension(api: ExtensionApiV2): void {
|
|
|
3040
4020
|
return { text: recovered ?? "", ...(recovered ? { toast: { text: recovered, tone: "warning" as const } } : {}), ...(await picture(ctx)) };
|
|
3041
4021
|
});
|
|
3042
4022
|
api.on("turn_end", async (_event, ctx) => {
|
|
3043
|
-
// An action arms for the turn its command starts; nothing it allowed outlives that turn.
|
|
4023
|
+
// An action arms for the turn its command starts; nothing it allowed outlives that turn. Clio's own
|
|
4024
|
+
// continuation of the turn may resume it, so the desk holds what it had until the next prompt says whose it is.
|
|
4025
|
+
const armed = (await ctx.state.get<Armed>("armed")).value;
|
|
4026
|
+
const drive = (await ctx.state.get<Drive>("drive")).value;
|
|
4027
|
+
if (armed || drive) await ctx.state.set("held", { ...(armed ? { armed } : {}), ...(drive ? { drive } : {}), workspace: ctx.snapshot.workspace });
|
|
3044
4028
|
await ctx.state.delete("armed");
|
|
4029
|
+
await ctx.state.delete("drive");
|
|
4030
|
+
await ctx.state.delete("measure-noted");
|
|
3045
4031
|
return undefined;
|
|
3046
4032
|
});
|
|
3047
4033
|
api.on("workspace_enter", async (_event, ctx) => ({ text: "", ...(await picture(ctx)) }));
|