@justjoshn/pi-pstack 0.15.36-pi.1 → 0.15.36-pi.11
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/CHANGELOG.md +79 -0
- package/README.md +26 -21
- package/agents/ci-watcher.md +28 -0
- package/agents/thermo-nuclear-code-quality-review.md +23 -0
- package/assets/logo.png +0 -0
- package/automations/benny/FOR_AGENTS.md +2 -1
- package/automations/benny/README.md +2 -2
- package/automations/benny/skills/setup-benny/SKILL.md +10 -9
- package/automations/benny/templates/reproduce-automation-prompt.md +1 -1
- package/automations/benny/templates/triage-automation-prompt.md +1 -1
- package/bin/pstack-routines-supervisor +9 -0
- package/docs/guide/01-setup.md +2 -2
- package/docs/guide/07-overnight.md +1 -1
- package/docs/guide/09-make-it-yours.md +1 -1
- package/docs/guide/10-recipes-and-pitfalls.md +1 -1
- package/docs/native-gaps.md +14 -8
- package/docs/parity-reverse-engineering.md +94 -0
- package/docs/parity-status.md +113 -0
- package/package.json +41 -6
- package/packaging/install-supervisor-unit.sh +164 -0
- package/packaging/launchd/com.pstack.routines-supervisor.plist.example +24 -0
- package/packaging/systemd/pstack-routines-supervisor.service.example +15 -0
- package/skills/architect/SKILL.md +1 -1
- package/skills/architect/references/runner-prompt.md +1 -1
- package/skills/arena/SKILL.md +4 -4
- package/skills/check-compiler-errors/SKILL.md +23 -0
- package/skills/create-skill/SKILL.md +515 -29
- package/skills/fix-ci/SKILL.md +29 -0
- package/skills/fix-merge-conflicts/SKILL.md +32 -0
- package/skills/get-pr-comments/SKILL.md +23 -0
- package/skills/how/SKILL.md +1 -1
- package/skills/ketchup/SKILL.md +2 -2
- package/skills/ketchup-video/SKILL.md +2 -2
- package/skills/loop-on-ci/SKILL.md +50 -0
- package/skills/make-bot-ui/SKILL.md +2 -2
- package/skills/make-pr-easy-to-review/SKILL.md +59 -0
- package/skills/new-branch-and-pr/SKILL.md +29 -0
- package/skills/no-inline-imports/SKILL.md +12 -0
- package/skills/poteto-help/SKILL.md +4 -4
- package/skills/poteto-mode/SKILL.md +2 -2
- package/skills/poteto-mode/playbooks/bug-fix.md +1 -1
- package/skills/poteto-mode/playbooks/feature.md +1 -1
- package/skills/poteto-mode/playbooks/hillclimb.md +1 -1
- package/skills/poteto-mode/playbooks/multi-phase-plan.md +2 -2
- package/skills/poteto-mode/playbooks/orchestrate.md +2 -2
- package/skills/poteto-mode/playbooks/perf-issue.md +1 -1
- package/skills/poteto-mode/playbooks/refactoring.md +1 -1
- package/skills/pr-review-canvas/SKILL.md +176 -0
- package/skills/pr-review-canvas/renderer.js +170 -0
- package/skills/pr-review-canvas/styles.css +96 -0
- package/skills/pr-review-canvas/template.html +18 -0
- package/skills/reflect/SKILL.md +2 -2
- package/skills/review-and-ship/SKILL.md +41 -0
- package/skills/run-smoke-tests/SKILL.md +42 -0
- package/skills/setup-pstack/SKILL.md +13 -13
- package/skills/statechart/scripts/test/cli.test.ts +1 -1
- package/skills/swarm/SKILL.md +2 -2
- package/skills/thermo-nuclear-code-quality-review/SKILL.md +192 -0
- package/skills/typescript-exhaustive-switch/SKILL.md +10 -0
- package/skills/verify-this/SKILL.md +74 -0
- package/skills/weekly-review/SKILL.md +32 -0
- package/skills/what-did-i-get-done/SKILL.md +31 -0
- package/skills/why/SKILL.md +2 -2
- package/skills/workflow-from-chats/SKILL.md +50 -0
- package/src/child-env.ts +15 -2
- package/src/index.ts +18 -3
- package/src/loop.ts +63 -14
- package/src/mode.ts +31 -7
- package/src/path-skills.ts +104 -0
- package/src/paths.ts +18 -0
- package/src/pi-command.ts +12 -0
- package/src/plan.ts +109 -24
- package/src/rule.ts +4 -4
- package/src/sections.ts +21 -2
- package/src/subscriptions/durable-store.ts +531 -0
- package/src/subscriptions/durable-types.ts +69 -0
- package/src/subscriptions/ensure-supervisor.ts +67 -0
- package/src/subscriptions/index.ts +310 -282
- package/src/subscriptions/supervisor-main.ts +134 -0
- package/src/subscriptions/supervisor.ts +325 -0
- package/src/subscriptions/webhook.ts +82 -21
- package/src/task/card.ts +29 -0
- package/src/task/models.ts +7 -0
- package/src/task/progress.ts +112 -0
- package/src/task/records.ts +7 -9
- package/src/task/registry.ts +7 -3
- package/src/task/runner.ts +112 -23
- package/src/task/tool.ts +112 -43
- package/src/task/worktree.ts +5 -3
- package/src/todo.ts +8 -3
- package/scripts/live-e2e.mjs +0 -257
- package/test/aliases.test.ts +0 -57
- package/test/ask.test.ts +0 -85
- package/test/autocomplete.test.ts +0 -39
- package/test/e2e/aliases.e2e.test.ts +0 -81
- package/test/e2e/ask.e2e.test.ts +0 -135
- package/test/e2e/harness.ts +0 -179
- package/test/e2e/host.e2e.test.ts +0 -193
- package/test/e2e/lifecycle.e2e.test.ts +0 -99
- package/test/e2e/mode.e2e.test.ts +0 -160
- package/test/e2e/package.e2e.test.ts +0 -67
- package/test/e2e/task.e2e.test.ts +0 -734
- package/test/e2e/todo.e2e.test.ts +0 -59
- package/test/fixtures/cursor-askquestion-calls.json +0 -806
- package/test/fixtures/fake-pi.mjs +0 -96
- package/test/fixtures/image-model.ts +0 -16
- package/test/fixtures/list-models.ts +0 -15
- package/test/fixtures/readonly-shell-exit.ts +0 -17
- package/test/fixtures/scripted-model.ts +0 -113
- package/test/loop.test.ts +0 -209
- package/test/mode.test.ts +0 -143
- package/test/plan.test.ts +0 -126
- package/test/readonly-shell-security.test.ts +0 -84
- package/test/readonly-shell.test.ts +0 -44
- package/test/records.test.ts +0 -143
- package/test/registry.test.ts +0 -18
- package/test/resources.test.ts +0 -162
- package/test/rule.test.ts +0 -92
- package/test/scripts.test.ts +0 -182
- package/test/sections.test.ts +0 -56
- package/test/subscriptions-cron.test.ts +0 -60
- package/test/subscriptions.test.ts +0 -598
- package/test/task-agents.test.ts +0 -49
- package/test/task-card.test.ts +0 -34
- package/test/task-fork.test.ts +0 -233
- package/test/task-format.test.ts +0 -65
- package/test/task-model.test.ts +0 -141
- package/test/task-runner.test.ts +0 -259
- package/test/task-schema.test.ts +0 -50
- package/test/task-status.test.ts +0 -155
- package/test/task-worktree.test.ts +0 -106
- package/test/todo.test.ts +0 -74
- package/test/visualize.test.ts +0 -152
- package/tsconfig.json +0 -5
- package/vitest.config.ts +0 -16
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: thermo-nuclear-code-quality-review
|
|
3
|
+
description: Run an extremely strict maintainability review for abstraction quality, giant files, and spaghetti-condition growth. Use for a thermo-nuclear code quality review, thermonuclear review, deep code quality audit, or especially harsh maintainability review.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Thermo-Nuclear Code Quality Review
|
|
8
|
+
|
|
9
|
+
Use this skill for an unusually strict review focused on implementation quality, maintainability, abstraction quality, and codebase health.
|
|
10
|
+
|
|
11
|
+
Above all, this skill should push the reviewer to be **ambitious** about code structure. Do not merely identify local cleanup opportunities. Actively search for "code judo" moves: restructurings that preserve behavior while making the implementation dramatically simpler, smaller, more direct, and more elegant.
|
|
12
|
+
|
|
13
|
+
## Core Prompt
|
|
14
|
+
|
|
15
|
+
Start from this baseline:
|
|
16
|
+
|
|
17
|
+
> Perform a deep code quality audit of the current branch's changes.
|
|
18
|
+
> Rethink how to structure / implement the changes to meaningfully improve code quality without impacting behavior.
|
|
19
|
+
> Work to improve abstractions, modularity, reduce Spaghetti code, improve succinctness and legibility.
|
|
20
|
+
> Be ambitious, if there is a clear path to improving the implementation that involves restructuring some of the codebase, go for it.
|
|
21
|
+
> Be extremely thorough and rigorous. Measure twice, cut once.
|
|
22
|
+
|
|
23
|
+
## Non-Negotiable Additional Standards
|
|
24
|
+
|
|
25
|
+
Apply the baseline prompt above, plus these explicit review rules:
|
|
26
|
+
|
|
27
|
+
0. **Be ambitious about structural simplification.**
|
|
28
|
+
- Do not stop at "this could be a bit cleaner."
|
|
29
|
+
- Look for opportunities to reframe the change so that whole branches, helpers, modes, conditionals, or layers disappear entirely.
|
|
30
|
+
- Prefer the solution that makes the code feel inevitable in hindsight.
|
|
31
|
+
- Assume there is often a "code judo" move available: a re-organization that uses the existing architecture more effectively and makes the change dramatically simpler and more elegant.
|
|
32
|
+
- If you see a path to delete complexity rather than rearrange it, push hard for that path.
|
|
33
|
+
|
|
34
|
+
1. **Do not let a PR push a file from under 1k lines to over 1k lines without a very strong reason.**
|
|
35
|
+
- Treat this as a strong code-quality smell by default.
|
|
36
|
+
- Prefer extracting helpers, subcomponents, modules, or local abstractions instead of letting a file sprawl past 1000 lines.
|
|
37
|
+
- If the diff crosses that threshold, explicitly ask whether the code should be decomposed first.
|
|
38
|
+
- Only waive this if there is a compelling structural reason and the resulting file is still clearly organized.
|
|
39
|
+
|
|
40
|
+
2. **Do not allow random spaghetti growth in existing code.**
|
|
41
|
+
- Be highly suspicious of new ad-hoc conditionals, scattered special cases, or one-off branches inserted into unrelated flows.
|
|
42
|
+
- If a change adds "weird if statements in random places", treat that as a design problem, not a stylistic nit.
|
|
43
|
+
- Prefer pushing the logic into a dedicated abstraction, helper, state machine, policy object, or separate module instead of tangling an existing path.
|
|
44
|
+
- Call out changes that make the surrounding code harder to reason about, even if they technically work.
|
|
45
|
+
|
|
46
|
+
3. **Bias toward cleaning the design, not just accepting working code.**
|
|
47
|
+
- If behavior can stay the same while the structure becomes meaningfully cleaner, push for the cleaner version.
|
|
48
|
+
- Do not rubber-stamp "it works" implementations that leave the codebase messier.
|
|
49
|
+
- Strongly prefer simplifications that remove moving pieces altogether over refactors that merely spread the same complexity around.
|
|
50
|
+
|
|
51
|
+
4. **Prefer direct, boring, maintainable code over hacky or magical code.**
|
|
52
|
+
- Treat brittle, ad-hoc, or "magic" behavior as a code-quality problem.
|
|
53
|
+
- Be skeptical of generic mechanisms that hide simple data-shape assumptions.
|
|
54
|
+
- Flag thin abstractions, identity wrappers, or pass-through helpers that add indirection without buying clarity.
|
|
55
|
+
|
|
56
|
+
5. **Push hard on type and boundary cleanliness when they affect maintainability.**
|
|
57
|
+
- Question unnecessary optionality, `unknown`, `any`, or cast-heavy code when a clearer type boundary could exist.
|
|
58
|
+
- Prefer explicit typed models or shared contracts over loosely-shaped ad-hoc objects.
|
|
59
|
+
- If a branch relies on silent fallback to paper over an unclear invariant, ask whether the boundary should be made explicit instead.
|
|
60
|
+
|
|
61
|
+
6. **Keep logic in the canonical layer and reuse existing helpers.**
|
|
62
|
+
- Call out feature logic leaking into shared paths or implementation details leaking through APIs.
|
|
63
|
+
- Prefer existing canonical utilities/helpers over bespoke one-offs.
|
|
64
|
+
- Push code toward the right package, service, or module instead of normalizing architectural drift.
|
|
65
|
+
|
|
66
|
+
7. **Treat unnecessary sequential orchestration and non-atomic updates as design smells when the cleaner structure is obvious.**
|
|
67
|
+
- If independent work is serialized for no good reason, ask whether the flow should run in parallel instead.
|
|
68
|
+
- If related updates can leave state half-applied, push for a more atomic structure.
|
|
69
|
+
- Do not over-index on micro-optimizations, but do flag avoidable orchestration complexity that makes the implementation more brittle.
|
|
70
|
+
|
|
71
|
+
## Primary Review Questions
|
|
72
|
+
|
|
73
|
+
For every meaningful change, ask:
|
|
74
|
+
|
|
75
|
+
- Is there a "code judo" move that would make this dramatically simpler?
|
|
76
|
+
- Can this change be reframed so fewer concepts, branches, or helper layers are needed?
|
|
77
|
+
- Does this improve or worsen the local architecture?
|
|
78
|
+
- Did the diff add branching complexity where a better abstraction should exist?
|
|
79
|
+
- Did a previously cohesive module become more coupled, more stateful, or harder to scan?
|
|
80
|
+
- Is this logic living in the right file and layer?
|
|
81
|
+
- Did this change enlarge a file or component past a healthy size boundary?
|
|
82
|
+
- Are there repeated conditionals that signal a missing model or missing helper?
|
|
83
|
+
- Is the implementation direct and legible, or does it rely on special cases and incidental control flow?
|
|
84
|
+
- Is this abstraction actually earning its keep, or is it just a wrapper?
|
|
85
|
+
- Did the diff introduce casts, optionality, or ad-hoc object shapes that obscure the real invariant?
|
|
86
|
+
- Is this logic living in the canonical layer, or did the diff leak details across a boundary?
|
|
87
|
+
- Is this orchestration more sequential or less atomic than it needs to be?
|
|
88
|
+
|
|
89
|
+
## What to Flag Aggressively
|
|
90
|
+
|
|
91
|
+
Escalate findings when you see:
|
|
92
|
+
|
|
93
|
+
- A complicated implementation where a cleaner reframing could delete whole categories of complexity.
|
|
94
|
+
- Refactors that move code around but fail to reduce the number of concepts a reader must hold in their head.
|
|
95
|
+
- A file crossing 1000 lines due to the PR, especially if the new code could be split out.
|
|
96
|
+
- New conditionals bolted onto unrelated code paths.
|
|
97
|
+
- One-off booleans, nullable modes, or flags that complicate existing control flow.
|
|
98
|
+
- Feature-specific logic leaking into general-purpose modules.
|
|
99
|
+
- Generic "magic" handling that hides simple structure and makes the code harder to reason about.
|
|
100
|
+
- Thin wrappers or identity abstractions that add indirection without simplifying anything.
|
|
101
|
+
- Unnecessary casts, `any`, `unknown`, or optional params that muddy the real contract.
|
|
102
|
+
- Copy-pasted logic instead of extracted helpers.
|
|
103
|
+
- Narrow edge-case handling implemented in the middle of an already busy function.
|
|
104
|
+
- Refactors that technically pass tests but make the code less modular or less readable.
|
|
105
|
+
- "Temporary" branching that is likely to become permanent debt.
|
|
106
|
+
- Bespoke helpers where the codebase already has a canonical utility for the job.
|
|
107
|
+
- Logic added in the wrong layer/package when it should live somewhere more central.
|
|
108
|
+
- Sequential async flow where obviously independent work could stay simpler and clearer with parallel execution.
|
|
109
|
+
- Partial-update logic that leaves state less atomic than necessary.
|
|
110
|
+
|
|
111
|
+
## Preferred Remedies
|
|
112
|
+
|
|
113
|
+
When you identify a code-quality problem, prefer suggestions like:
|
|
114
|
+
|
|
115
|
+
- Delete a whole layer of indirection rather than polishing it.
|
|
116
|
+
- Reframe the state model so conditionals disappear instead of getting centralized.
|
|
117
|
+
- Change the ownership boundary so the feature becomes a natural extension of an existing abstraction.
|
|
118
|
+
- Turn special-case logic into a simpler default flow with fewer exceptions.
|
|
119
|
+
- Extract a helper or pure function.
|
|
120
|
+
- Split a large file into smaller focused modules.
|
|
121
|
+
- Move feature-specific logic behind a dedicated abstraction.
|
|
122
|
+
- Replace condition chains with a typed model or explicit dispatcher.
|
|
123
|
+
- Separate orchestration from business logic.
|
|
124
|
+
- Collapse duplicate branches into a single clearer flow.
|
|
125
|
+
- Delete wrappers that do not meaningfully clarify the API.
|
|
126
|
+
- Reuse the existing canonical helper instead of introducing a near-duplicate.
|
|
127
|
+
- Make type boundaries more explicit so the control flow gets simpler.
|
|
128
|
+
- Move the logic to the package/module/layer that already owns the concept.
|
|
129
|
+
- Parallelize independent work when that also simplifies the orchestration.
|
|
130
|
+
- Restructure related updates into a more atomic flow when partial state would be harder to reason about.
|
|
131
|
+
|
|
132
|
+
Do not be satisfied with "maybe rename this" feedback when the real issue is structural.
|
|
133
|
+
Do not be satisfied with a merely cleaner version of the same messy idea if there is a plausible path to a much simpler idea.
|
|
134
|
+
|
|
135
|
+
## Review Tone
|
|
136
|
+
|
|
137
|
+
Be direct, serious, and demanding about quality.
|
|
138
|
+
Do not be rude, but do not soften major maintainability issues into mild suggestions.
|
|
139
|
+
If the code is making the codebase messier, say so clearly.
|
|
140
|
+
If the implementation missed an opportunity for a dramatic simplification, say that clearly too.
|
|
141
|
+
|
|
142
|
+
Good phrases:
|
|
143
|
+
|
|
144
|
+
- `this pushes the file past 1k lines. can we decompose this first?`
|
|
145
|
+
- `this adds another special-case branch into an already busy flow. can we move this behind its own abstraction?`
|
|
146
|
+
- `this works, but it makes the surrounding code more spaghetti. let's keep the behavior and restructure the implementation.`
|
|
147
|
+
- `this feels like feature logic leaking into a shared path. can we isolate it?`
|
|
148
|
+
- `this abstraction seems unnecessary. can we just keep the direct flow?`
|
|
149
|
+
- `why does this need a cast / optional here? can we make the boundary more explicit instead?`
|
|
150
|
+
- `this looks like a bespoke helper for something we already have elsewhere. can we reuse the canonical one?`
|
|
151
|
+
- `i think there's a code-judo move here that makes this much simpler. can we reframe this so these branches disappear?`
|
|
152
|
+
- `this refactor moves complexity around, but doesn't really delete it. is there a way to make the model itself simpler?`
|
|
153
|
+
|
|
154
|
+
## Output Expectations
|
|
155
|
+
|
|
156
|
+
Prioritize findings in this order:
|
|
157
|
+
|
|
158
|
+
1. Structural code-quality regressions
|
|
159
|
+
2. Missed opportunities for dramatic simplification / code-judo restructuring
|
|
160
|
+
3. Spaghetti / branching complexity increases
|
|
161
|
+
4. Boundary / abstraction / type-contract problems that make the code harder to reason about
|
|
162
|
+
5. File-size and decomposition concerns
|
|
163
|
+
6. Modularity and abstraction issues
|
|
164
|
+
7. Legibility and maintainability concerns
|
|
165
|
+
|
|
166
|
+
Do not flood the review with low-value nits if there are larger structural issues.
|
|
167
|
+
Prefer a smaller number of high-conviction comments over a long list of cosmetic notes.
|
|
168
|
+
|
|
169
|
+
## Approval Bar
|
|
170
|
+
|
|
171
|
+
Do not approve merely because behavior seems correct.
|
|
172
|
+
The bar for approval is:
|
|
173
|
+
|
|
174
|
+
- no clear structural regression
|
|
175
|
+
- no obvious missed opportunity to make the implementation dramatically simpler when such a path is visible
|
|
176
|
+
- no unjustified file-size explosion
|
|
177
|
+
- no obvious spaghetti-growth from special-case branching
|
|
178
|
+
- no obviously hacky or magical abstraction that makes the code harder to reason about
|
|
179
|
+
- no unnecessary wrapper/cast/optionality churn obscuring the real design
|
|
180
|
+
- no clear architecture-boundary leak or avoidable canonical-helper duplication
|
|
181
|
+
- no missed opportunity for an obvious decomposition that would materially improve maintainability
|
|
182
|
+
|
|
183
|
+
Treat these as presumptive blockers unless the author can justify them clearly:
|
|
184
|
+
|
|
185
|
+
- the PR preserves a lot of incidental complexity when there is a plausible code-judo move that would delete it
|
|
186
|
+
- the PR pushes a file from below 1000 lines to above 1000 lines
|
|
187
|
+
- the PR adds ad-hoc branching that makes an existing flow more tangled
|
|
188
|
+
- the PR solves a local problem by scattering feature checks across shared code
|
|
189
|
+
- the PR adds an unnecessary abstraction, wrapper, or cast-heavy contract that makes the design more indirect
|
|
190
|
+
- the PR duplicates an existing helper or puts logic in the wrong layer when there is a clear canonical home
|
|
191
|
+
|
|
192
|
+
If those conditions are not met, leave explicit, actionable feedback and push for a cleaner decomposition.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript-exhaustive-switch
|
|
3
|
+
description: Use exhaustive switch handling for TypeScript unions and enums
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Typescript Exhaustive Switch
|
|
8
|
+
|
|
9
|
+
typescript-exhaustive-switch: In switch statements over discriminated unions or enums, use a `never` check in the default case so newly added variants cause compile-time failures until handled.
|
|
10
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: verify-this
|
|
3
|
+
description: "Verify a claim with fresh local evidence: restate it falsifiably, capture baseline and treatment, compare artifacts, and return VERIFIED, NOT VERIFIED, or INCONCLUSIVE."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Verify This
|
|
7
|
+
|
|
8
|
+
Verification is not a recap. It proves or disproves a specific claim with repeatable evidence.
|
|
9
|
+
|
|
10
|
+
## When To Use
|
|
11
|
+
|
|
12
|
+
- The user asks "verify this", "prove it works", "did this fix it", or "show me the evidence".
|
|
13
|
+
- A bug fix needs a before/after repro.
|
|
14
|
+
- A UI, CLI, API, performance, or memory claim needs measurement.
|
|
15
|
+
- A test passes but the user-visible behavior still needs confirmation.
|
|
16
|
+
|
|
17
|
+
Do not use this for vague claims like "the code is cleaner". Ask for a measurable claim first.
|
|
18
|
+
|
|
19
|
+
## Workflow
|
|
20
|
+
|
|
21
|
+
1. Restate the claim in falsifiable form: condition, metric, and threshold.
|
|
22
|
+
2. Pick the smallest local surface that can disprove it.
|
|
23
|
+
3. Capture a baseline from the old state: merge base, parent commit, failing branch, or current broken repro.
|
|
24
|
+
4. Capture treatment from the changed state with the same command, data, warmup, and environment.
|
|
25
|
+
5. Compare raw artifacts: numbers, screenshots, terminal transcripts, HTTP responses, profiles, heap snapshots, or test output.
|
|
26
|
+
6. Return exactly one verdict: `VERIFIED`, `NOT VERIFIED`, or `INCONCLUSIVE`.
|
|
27
|
+
|
|
28
|
+
## Local Surfaces
|
|
29
|
+
|
|
30
|
+
- Code behavior: focused unit/integration tests or a minimal repro script.
|
|
31
|
+
- CLI/TUI behavior: `control-cli`, terminal transcript, or demo recording.
|
|
32
|
+
- UI behavior: `control-ui`, screenshots, accessibility snapshots, or browser traces.
|
|
33
|
+
- API behavior: local HTTP/RPC request and response diff.
|
|
34
|
+
- Performance: same-machine baseline/treatment timings or CPU profiles.
|
|
35
|
+
- Memory: heap snapshots before and after the suspected operation.
|
|
36
|
+
|
|
37
|
+
## Artifact Layout
|
|
38
|
+
|
|
39
|
+
When safe to write artifacts:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
/tmp/verify-this/<claim-slug>/
|
|
43
|
+
├── claim.md
|
|
44
|
+
├── timeline.md
|
|
45
|
+
├── baseline/
|
|
46
|
+
├── treatment/
|
|
47
|
+
├── diff/
|
|
48
|
+
└── verdict.md
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
If artifacts may contain sensitive code, prompts, screenshots, HTTP bodies, or heap data, keep only the minimal inline evidence unless the user agrees to disk storage.
|
|
52
|
+
|
|
53
|
+
## Verdict Rules
|
|
54
|
+
|
|
55
|
+
- `VERIFIED`: baseline and treatment differ in the predicted direction, by the claimed threshold, with no obvious confound.
|
|
56
|
+
- `NOT VERIFIED`: the behavior is unchanged, moves the wrong way, or misses the threshold.
|
|
57
|
+
- `INCONCLUSIVE`: no valid baseline, noisy signal, failed measurement, or an environment difference invalidates the comparison.
|
|
58
|
+
|
|
59
|
+
## Output
|
|
60
|
+
|
|
61
|
+
Use this shape:
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
VERIFIED | NOT VERIFIED | INCONCLUSIVE
|
|
65
|
+
Claim: <falsifiable claim>
|
|
66
|
+
|
|
67
|
+
Evidence:
|
|
68
|
+
<metric/artifact>: baseline=<...>, treatment=<...>, delta=<...>, threshold=<...>
|
|
69
|
+
|
|
70
|
+
Reasoning:
|
|
71
|
+
<one tight paragraph naming the evidence and any confounds>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Do not soften a negative result. A clear `NOT VERIFIED` is useful.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: weekly-review
|
|
3
|
+
description: Produce a weekly synthesis of authored commits with highlights by bugfix, tech debt, and net-new work
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Weekly review
|
|
7
|
+
|
|
8
|
+
## Trigger
|
|
9
|
+
|
|
10
|
+
Need a weekly recap of shipped work for status updates, retros, or planning.
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Determine the current git user email from repo config.
|
|
15
|
+
2. Collect authored commits from the last 7-10 days on the primary branch context.
|
|
16
|
+
3. Exclude merge commits.
|
|
17
|
+
4. Group meaningful changes into 2-5 concise bullets.
|
|
18
|
+
5. Add a short classification paragraph covering:
|
|
19
|
+
- likely bug fixes
|
|
20
|
+
- likely tech debt work
|
|
21
|
+
- likely net-new functionality
|
|
22
|
+
|
|
23
|
+
## Guardrails
|
|
24
|
+
|
|
25
|
+
- Keep the recap short and executive-readable.
|
|
26
|
+
- Base claims only on commit history and diffs.
|
|
27
|
+
- If git email is missing, ask the user to set it before proceeding.
|
|
28
|
+
|
|
29
|
+
## Output
|
|
30
|
+
|
|
31
|
+
- 2-5 bullet weekly summary
|
|
32
|
+
- Brief classification paragraph (bugfix / tech debt / net-new)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: what-did-i-get-done
|
|
3
|
+
description: Summarize authored commits over a user-specified time period into a concise update
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# What did I get done
|
|
7
|
+
|
|
8
|
+
## Trigger
|
|
9
|
+
|
|
10
|
+
Need a short, high-signal summary of work completed in a specific time range (for example: yesterday, last 3 days, or last week).
|
|
11
|
+
|
|
12
|
+
## Workflow
|
|
13
|
+
|
|
14
|
+
1. Resolve the requested time window into concrete dates.
|
|
15
|
+
2. Read commits authored by the current git user email within that range.
|
|
16
|
+
3. Exclude merge commits and uncommitted changes.
|
|
17
|
+
4. Synthesize the most important shipped changes into a concise status update.
|
|
18
|
+
5. Include the actual date range used in the final summary.
|
|
19
|
+
|
|
20
|
+
## Guardrails
|
|
21
|
+
|
|
22
|
+
- Be extremely concise and information-dense.
|
|
23
|
+
- Prioritize substantial behavior or architecture changes.
|
|
24
|
+
- Omit cosmetic-only changes (formatting, imports, minor renames).
|
|
25
|
+
- Do not infer intent or motivation. Describe changes functionally.
|
|
26
|
+
|
|
27
|
+
## Output
|
|
28
|
+
|
|
29
|
+
- One short summary suitable for a status update
|
|
30
|
+
- Real date range
|
|
31
|
+
- Optional 2-5 bullets for major changes only
|
package/skills/why/SKILL.md
CHANGED
|
@@ -8,7 +8,7 @@ disable-model-invocation: true
|
|
|
8
8
|
|
|
9
9
|
Investigate the motivation and intent behind code. The companion `how` skill answers what the code does and how it works. `why` answers what forces led to its shape.
|
|
10
10
|
|
|
11
|
-
Each spawn below names a role line in the model rule
|
|
11
|
+
Each spawn below names a role line in the model rule at the path the system prompt names and a default. Set `model` to that line's value, or to the default if the rule or the line is missing. Leave `model` unset when the value is `auto` or `inherit-parent`. If the Task tool rejects a slug, use the default and say so. If it rejects the default, use the closest valid slug of the same family from its error message. Pick each subagent's reasoning level (the `:<level>` suffix), and fast or standard speed when the model has a `-fast` variant, for the job, per the Subagents section of the **poteto-mode** skill.
|
|
12
12
|
|
|
13
13
|
Every spawn is `generalPurpose` with `readonly: false` (or `readonly` unset). **Do not set `readonly: true`.** It strips MCP access, which disables the MCP-backed investigators and the synthesizer's citation spot-checks. Investigators still shouldn't write anything.
|
|
14
14
|
|
|
@@ -46,7 +46,7 @@ Map each available MCP to one evidence category:
|
|
|
46
46
|
|
|
47
47
|
Source control is always available through git and `gh`. For the other six, classify using the MCP name, server instructions, tool names, and resource descriptors. If an MCP could fit more than one category, choose the one matching its primary evidence. Record ambiguous cases in the coverage map.
|
|
48
48
|
|
|
49
|
-
Spawn one investigator per category that has a matching MCP, all in a single message so they run concurrently, each owning exactly one tool or MCP. Don't ask one agent to cover multiple MCPs. `model`: the `why investigators` line, default `grok-4.7
|
|
49
|
+
Spawn one investigator per category that has a matching MCP, all in a single message so they run concurrently, each owning exactly one tool or MCP. Don't ask one agent to cover multiple MCPs. `model`: the `why investigators` line, default `grok-4.7[effort=xhigh,fast=true]`.
|
|
50
50
|
|
|
51
51
|
Each investigator's prompt is `references/investigator-prompt.md` filled in, plus:
|
|
52
52
|
- the category playbook `references/sources/<source>.md` for the selected MCP, adapted from the examples in `references/source-playbook.md`
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: workflow-from-chats
|
|
3
|
+
description: Extract durable working preferences from recent Pi chats and convert them into skills, rules, or workflow docs. Use when asked to learn preferences, mine feedback, personalize workflows, or generate team/person-specific agent guidance.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Workflow From Chats
|
|
7
|
+
|
|
8
|
+
Infer durable working preferences from recent chats. Do not summarize chats; extract reusable workflow guidance.
|
|
9
|
+
|
|
10
|
+
## Scope
|
|
11
|
+
|
|
12
|
+
- Default to the last 7 days unless the user asks for a different window.
|
|
13
|
+
- Read parent transcripts and relevant subagent transcripts. Use subagent content as evidence, but cite only parent conversations.
|
|
14
|
+
- Do not expose local transcript paths, secrets, customer data, private chat content, or credentials.
|
|
15
|
+
|
|
16
|
+
## Workflow
|
|
17
|
+
|
|
18
|
+
1. State the target workflow or preference surface in one paragraph.
|
|
19
|
+
2. Build an internal transcript inventory: title/topic, parent conversation ID, approximate date, completion state, relevant subagents, and why it may contain preference evidence.
|
|
20
|
+
3. Scan for explicit preferences, corrections, and workflow markers such as "I prefer", "always", "never", "not what I asked", "stop", "review", "PR", "CI", "logs", and "skill".
|
|
21
|
+
4. Extract preference atoms: trigger, workflow step, decision rule, quality bar, stop condition, evidence, and confidence.
|
|
22
|
+
5. Rate confidence as strong, medium, weak, or contradicted.
|
|
23
|
+
6. Cluster by workflow shape rather than transcript: shipping, review, simplification, debugging, capture, communication, delegation, or validation.
|
|
24
|
+
7. Choose the artifact: new skill, skill edit, rule, workflow doc, or no artifact.
|
|
25
|
+
8. Draft only the reusable guidance. Filter anecdotes that will not help future tasks.
|
|
26
|
+
|
|
27
|
+
## Confidence
|
|
28
|
+
|
|
29
|
+
- Strong: explicit user preference, workflow-changing correction, repeated parent-chat pattern, or direct request to encode behavior.
|
|
30
|
+
- Medium: accepted workflow, repeated tool/model/validation preference, or subagent consensus that the parent used successfully.
|
|
31
|
+
- Weak: agent-chosen behavior with no user feedback, one ambiguous transcript, or a likely task-specific correction.
|
|
32
|
+
- Contradicted: evidence points in incompatible directions; ask the user before writing files.
|
|
33
|
+
|
|
34
|
+
## Artifact Choice
|
|
35
|
+
|
|
36
|
+
- Skill: recurring multi-step workflow with clear triggers.
|
|
37
|
+
- Rule: general behavior that should apply broadly.
|
|
38
|
+
- Workflow doc: useful context that is not reliably triggerable.
|
|
39
|
+
- No artifact: situational, stale, or low-confidence observation.
|
|
40
|
+
|
|
41
|
+
## Output
|
|
42
|
+
|
|
43
|
+
Return a concise synthesis first:
|
|
44
|
+
|
|
45
|
+
- Target workflow.
|
|
46
|
+
- Evidence corpus with parent conversation citations only.
|
|
47
|
+
- Preference profile.
|
|
48
|
+
- Adopt, consider, dismissed.
|
|
49
|
+
- Proposed artifacts.
|
|
50
|
+
- Open questions only if they block writing.
|
package/src/child-env.ts
CHANGED
|
@@ -6,6 +6,7 @@ export const PARENT_ENV = 'PI_PSTACK_PARENT_PID';
|
|
|
6
6
|
export const READONLY_ENV = 'PI_PSTACK_READONLY';
|
|
7
7
|
export const ROOT_STORE_ENV = 'PI_PSTACK_ROOT_STORE';
|
|
8
8
|
export const WORKSPACE_ENV = 'PI_PSTACK_WORKSPACE_STATE';
|
|
9
|
+
export const ROOT_WORKSPACE_ENV = 'PI_PSTACK_ROOT_WORKSPACE';
|
|
9
10
|
|
|
10
11
|
export interface ChildIdentity {
|
|
11
12
|
depth: number;
|
|
@@ -15,6 +16,8 @@ export interface ChildIdentity {
|
|
|
15
16
|
rootStore: string | undefined;
|
|
16
17
|
/** The main chat's workspace state folder, which every agent in the tree shares, an isolated worker included. */
|
|
17
18
|
workspaceState: string | undefined;
|
|
19
|
+
/** The main chat's working directory, which authorizes every record stored in its shared workspace. */
|
|
20
|
+
rootWorkspace: string | undefined;
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
function read(): ChildIdentity {
|
|
@@ -27,6 +30,7 @@ function read(): ChildIdentity {
|
|
|
27
30
|
readonly: process.env[READONLY_ENV] === '1',
|
|
28
31
|
rootStore: process.env[ROOT_STORE_ENV] || undefined,
|
|
29
32
|
workspaceState: process.env[WORKSPACE_ENV] || undefined,
|
|
33
|
+
rootWorkspace: process.env[ROOT_WORKSPACE_ENV] || undefined,
|
|
30
34
|
};
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -37,8 +41,17 @@ delete process.env[PARENT_ENV];
|
|
|
37
41
|
delete process.env[READONLY_ENV];
|
|
38
42
|
delete process.env[ROOT_STORE_ENV];
|
|
39
43
|
delete process.env[WORKSPACE_ENV];
|
|
44
|
+
delete process.env[ROOT_WORKSPACE_ENV];
|
|
40
45
|
|
|
41
46
|
/** Variables for a child of this process at `depth` (an agent keeps the depth it was created at). */
|
|
42
|
-
export function childVariables(agentType: string, depth: number, readonly: boolean, rootStore: string, workspaceState: string): Record<string, string> {
|
|
43
|
-
return {
|
|
47
|
+
export function childVariables(agentType: string, depth: number, readonly: boolean, rootStore: string, workspaceState: string, rootWorkspace: string): Record<string, string> {
|
|
48
|
+
return {
|
|
49
|
+
[DEPTH_ENV]: String(depth),
|
|
50
|
+
[AGENT_ENV]: agentType,
|
|
51
|
+
[PARENT_ENV]: String(process.pid),
|
|
52
|
+
[ROOT_STORE_ENV]: rootStore,
|
|
53
|
+
[WORKSPACE_ENV]: workspaceState,
|
|
54
|
+
[ROOT_WORKSPACE_ENV]: rootWorkspace,
|
|
55
|
+
...(readonly ? { [READONLY_ENV]: '1' } : {}),
|
|
56
|
+
};
|
|
44
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -7,11 +7,12 @@ import { childIdentity } from './child-env.ts';
|
|
|
7
7
|
import { registerLoop } from './loop.ts';
|
|
8
8
|
import { registerMode } from './mode.ts';
|
|
9
9
|
import { canAsk, isOneShot } from './modes.ts';
|
|
10
|
+
import { createPathSkills } from './path-skills.ts';
|
|
10
11
|
import { artifactsDir, PACKAGE_ROOT, projectsDir, rootStoreDir, rulePath, SKILLS_DIR, storeDir, subagentDir } from './paths.ts';
|
|
11
12
|
import { registerPlanMode } from './plan.ts';
|
|
12
13
|
import { registerReadonlyShell } from './readonly-shell.ts';
|
|
13
14
|
import { migrateLegacyRule, modelsSection, readRule } from './rule.ts';
|
|
14
|
-
import { hostSection, subagentsSection } from './sections.ts';
|
|
15
|
+
import { alwaysAppliedRules, hostSection, subagentsSection } from './sections.ts';
|
|
15
16
|
import { registerSubscriptions } from './subscriptions/index.ts';
|
|
16
17
|
import { type AgentDefinition, loadAgentDefinitions } from './task/agents.ts';
|
|
17
18
|
import { registerAgentStatus } from './task/status.ts';
|
|
@@ -47,6 +48,7 @@ function hostSections(pi: ExtensionAPI, ctx: ExtensionContext, agents: readonly
|
|
|
47
48
|
loopAvailable: !isOneShot(ctx.mode),
|
|
48
49
|
questionsAvailable: canAsk(ctx),
|
|
49
50
|
activeTools,
|
|
51
|
+
rules: alwaysAppliedRules(SKILLS_DIR),
|
|
50
52
|
}),
|
|
51
53
|
...(activeTools.includes('Task') ? { pstack_subagents: subagentsSection(agents, availableModels(ctx), parentModel(ctx)) } : {}),
|
|
52
54
|
pstack_models: modelsSection(readRule(rulePath()), rulePath()),
|
|
@@ -99,9 +101,18 @@ export default function piPstack(pi: ExtensionAPI): void {
|
|
|
99
101
|
registerVisualize(pi, { artifactsDir: (ctx) => artifactsDir(ctx.cwd, ctx.sessionManager.getSessionId()) });
|
|
100
102
|
const task = registerTask(pi, { agents, depth: childIdentity.depth, planMode: plan.enabled });
|
|
101
103
|
registerAgentStatus(pi);
|
|
102
|
-
registerSubscriptions(pi, {
|
|
104
|
+
registerSubscriptions(pi, {
|
|
105
|
+
runFresh: async (prompt, name, meta) => {
|
|
106
|
+
await task.startBackground(`timer ${name}`, prompt, {
|
|
107
|
+
...(meta.model === undefined ? {} : { model: `${meta.model.provider}/${meta.model.id}${meta.model.thinking === undefined ? '' : `:${meta.model.thinking}`}` }),
|
|
108
|
+
...(meta.trusted === undefined ? {} : { trusted: meta.trusted }),
|
|
109
|
+
});
|
|
110
|
+
return undefined;
|
|
111
|
+
},
|
|
112
|
+
});
|
|
103
113
|
const loop = registerLoop(pi, { hasPendingWork: task.hasBackgroundWork });
|
|
104
|
-
registerTodoWrite(pi);
|
|
114
|
+
const todos = registerTodoWrite(pi);
|
|
115
|
+
const pathSkills = createPathSkills(pi);
|
|
105
116
|
registerAskQuestion(pi);
|
|
106
117
|
if (childIdentity.parentPid !== undefined) watchParent(pi, childIdentity.parentPid);
|
|
107
118
|
if (childIdentity.readonly) registerReadonlyShell(pi);
|
|
@@ -110,12 +121,16 @@ export default function piPstack(pi: ExtensionAPI): void {
|
|
|
110
121
|
const modeText = mode.section();
|
|
111
122
|
const loopText = loop.section();
|
|
112
123
|
const planText = plan.section();
|
|
124
|
+
const todoText = todos.section();
|
|
125
|
+
const pathSkillText = pathSkills.section();
|
|
113
126
|
Object.assign(
|
|
114
127
|
event.systemPromptOptions.sections,
|
|
115
128
|
hostSections(pi, ctx, agents),
|
|
116
129
|
modeText === undefined ? {} : { pstack_mode: modeText },
|
|
117
130
|
loopText === undefined ? {} : { pstack_loop: loopText },
|
|
118
131
|
planText === undefined ? {} : { pstack_plan: planText },
|
|
132
|
+
todoText === undefined ? {} : { pstack_todos: todoText },
|
|
133
|
+
pathSkillText === undefined ? {} : { pstack_path_skills: pathSkillText },
|
|
119
134
|
);
|
|
120
135
|
});
|
|
121
136
|
|
package/src/loop.ts
CHANGED
|
@@ -5,14 +5,21 @@ import { isOneShot } from './modes.ts';
|
|
|
5
5
|
const DAY_MS = 86_400_000;
|
|
6
6
|
const UNIT_MS: Record<string, number> = { s: 1_000, m: 60_000, h: 3_600_000, d: DAY_MS };
|
|
7
7
|
const DURATION = /^(?:\d+[smhd])+$/;
|
|
8
|
+
const WORD_UNITS: Record<string, string> = { second: 's', seconds: 's', sec: 's', secs: 's', minute: 'm', minutes: 'm', min: 'm', mins: 'm', hour: 'h', hours: 'h', hr: 'h', hrs: 'h', day: 'd', days: 'd' };
|
|
8
9
|
// setTimeout fires at once for delays past 2^31-1 ms (about 24.8 days), which would turn a long loop into a runaway.
|
|
9
10
|
const MAX_DELAY_MS = 24 * DAY_MS;
|
|
10
11
|
const TOO_LONG = 'Loop intervals can be at most 24d.';
|
|
11
12
|
|
|
12
|
-
/** Milliseconds for a duration such as 30s, 5m, 1h30m; undefined when the text is not a duration. */
|
|
13
|
+
/** Milliseconds for a duration such as 30s, 5m, 1h30m, 10 minutes, or 1 hour 30 minutes; undefined when the text is not a duration. */
|
|
13
14
|
export function parseDuration(text: string): number | undefined {
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const compact = text
|
|
16
|
+
.trim()
|
|
17
|
+
.toLowerCase()
|
|
18
|
+
.replace(/^every\s+/, '')
|
|
19
|
+
.replace(/(\d+)\s*(seconds?|secs?|minutes?|mins?|hours?|hrs?|days?)\b/g, (_match, count: string, word: string) => `${count}${WORD_UNITS[word] ?? ''}`)
|
|
20
|
+
.replace(/\s+/g, '');
|
|
21
|
+
if (!DURATION.test(compact)) return undefined;
|
|
22
|
+
const total = [...compact.matchAll(/(\d+)([smhd])/g)].reduce((sum, [, count, unit]) => sum + Number(count) * (UNIT_MS[unit ?? 's'] ?? 0), 0);
|
|
16
23
|
return total > 0 ? total : undefined;
|
|
17
24
|
}
|
|
18
25
|
|
|
@@ -25,15 +32,41 @@ function delayOf(text: string): number {
|
|
|
25
32
|
|
|
26
33
|
export type LoopCommand = { kind: 'status' } | { kind: 'stop' } | { kind: 'start'; prompt: string; intervalMs?: number } | { kind: 'error'; message: string };
|
|
27
34
|
|
|
35
|
+
/** The longest trailing phrase that parses as a duration, such as `5m`, `every 10 minutes`, or `1 hour 30 minutes`. */
|
|
36
|
+
function trailingInterval(text: string): { prompt: string; intervalMs: number } | undefined {
|
|
37
|
+
const tokens = text.split(/\s+/);
|
|
38
|
+
for (let take = Math.min(6, tokens.length); take >= 1; take -= 1) {
|
|
39
|
+
const intervalMs = parseDuration(tokens.slice(-take).join(' '));
|
|
40
|
+
if (intervalMs === undefined) continue;
|
|
41
|
+
const prompt = tokens
|
|
42
|
+
.slice(0, -take)
|
|
43
|
+
.join(' ')
|
|
44
|
+
.replace(/\s+every$/i, '')
|
|
45
|
+
.trim();
|
|
46
|
+
return { prompt, intervalMs };
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
28
51
|
export function parseLoopArgs(args: string): LoopCommand {
|
|
29
52
|
const trimmed = args.trim();
|
|
30
53
|
if (trimmed === '') return { kind: 'status' };
|
|
31
54
|
if (trimmed === 'stop' || trimmed === 'off') return { kind: 'stop' };
|
|
32
55
|
const [, first = '', rest = ''] = /^(\S+)\s*([\s\S]*)$/.exec(trimmed) ?? [];
|
|
33
|
-
const
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
56
|
+
const leadMs = parseDuration(first) ?? (first.toLowerCase() === 'every' ? parseDuration(rest.split(/\s+/)[0] ?? '') : undefined);
|
|
57
|
+
if (leadMs !== undefined) {
|
|
58
|
+
if (leadMs > MAX_DELAY_MS) return { kind: 'error', message: TOO_LONG };
|
|
59
|
+
const after = first.toLowerCase() === 'every' ? rest.split(/\s+/).slice(1).join(' ') : rest;
|
|
60
|
+
return after.trim() === '' ? { kind: 'error', message: '/loop needs a prompt: /loop [interval] <prompt>' } : { kind: 'start', prompt: after.trim(), intervalMs: leadMs };
|
|
61
|
+
}
|
|
62
|
+
// Cursor accepts the interval at either end, including `every 10 minutes`, so both ends are tried before treating it as a prompt.
|
|
63
|
+
const trailing = trailingInterval(trimmed);
|
|
64
|
+
if (trailing !== undefined) {
|
|
65
|
+
if (trailing.intervalMs > MAX_DELAY_MS) return { kind: 'error', message: TOO_LONG };
|
|
66
|
+
if (trailing.prompt === '') return { kind: 'error', message: '/loop needs a prompt: /loop [interval] <prompt>' };
|
|
67
|
+
return { kind: 'start', prompt: trailing.prompt, intervalMs: trailing.intervalMs };
|
|
68
|
+
}
|
|
69
|
+
return { kind: 'start', prompt: trimmed };
|
|
37
70
|
}
|
|
38
71
|
|
|
39
72
|
interface Loop {
|
|
@@ -74,18 +107,31 @@ function createLoopController(pi: ExtensionAPI, options: LoopOptions) {
|
|
|
74
107
|
clear();
|
|
75
108
|
notify(ctx, `Loop stopped: ${reason}`);
|
|
76
109
|
};
|
|
77
|
-
const fire = () => {
|
|
110
|
+
const fire = (first = false) => {
|
|
78
111
|
if (loop === undefined) return;
|
|
112
|
+
// A scheduled tick that lands mid-run is skipped rather than queued, so one long run cannot leave a pile of stale ticks.
|
|
113
|
+
if (!first && lastCtx !== undefined && !lastCtx.isIdle()) {
|
|
114
|
+
if (loop.intervalMs !== undefined) loop = { ...loop, timer: setTimeout(fire, loop.intervalMs) };
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
79
117
|
const { timer: _timer, nextWakeMs: _wake, ...rest } = loop;
|
|
80
118
|
loop = { ...rest, iteration: rest.iteration + 1 };
|
|
81
119
|
// Expansion lets a loop run a skill or template each time.
|
|
82
|
-
pi.sendUserMessage(loop.prompt, { expandPromptTemplates: true
|
|
120
|
+
pi.sendUserMessage(loop.prompt, { expandPromptTemplates: true });
|
|
121
|
+
// A fixed loop is wall-clock from each fire, like the reference's sleep loop: a long run does not push the next tick out.
|
|
122
|
+
if (loop.intervalMs !== undefined) loop = { ...loop, timer: setTimeout(fire, loop.intervalMs) };
|
|
83
123
|
};
|
|
84
124
|
const settled = (ctx: ExtensionContext, aborted: boolean) => {
|
|
85
125
|
lastCtx = ctx;
|
|
86
|
-
if (loop === undefined
|
|
126
|
+
if (loop === undefined) return;
|
|
87
127
|
if (aborted) return stop(ctx, 'the run was aborted.');
|
|
88
|
-
|
|
128
|
+
if (loop.timer !== undefined) return;
|
|
129
|
+
if (loop.intervalMs !== undefined) {
|
|
130
|
+
// An armed fixed loop has no timer yet; its first tick waits for this turn to end.
|
|
131
|
+
loop = { ...loop, timer: setTimeout(fire, loop.intervalMs) };
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const delay = loop.nextWakeMs;
|
|
89
135
|
if (delay !== undefined) loop = { ...loop, timer: setTimeout(fire, delay) };
|
|
90
136
|
else if (!options.hasPendingWork()) stop(ctx, 'the agent scheduled no next wake.');
|
|
91
137
|
};
|
|
@@ -93,14 +139,17 @@ function createLoopController(pi: ExtensionAPI, options: LoopOptions) {
|
|
|
93
139
|
if (loop !== undefined) stop(ctx, 'replaced by a new /loop.');
|
|
94
140
|
lastCtx = ctx;
|
|
95
141
|
loop = { prompt, iteration: 0, ...(intervalMs === undefined ? {} : { intervalMs }) };
|
|
96
|
-
fire();
|
|
142
|
+
fire(true);
|
|
97
143
|
};
|
|
98
144
|
/** An agent arms a loop mid-turn, so its first run waits for this turn to settle and then for the first delay. */
|
|
99
145
|
const arm = (ctx: ExtensionContext, prompt: string, schedule: { intervalMs: number } | { firstWakeMs: number }) => {
|
|
100
146
|
if (loop !== undefined) stop(ctx, 'replaced by a new loop.');
|
|
101
147
|
loop = 'intervalMs' in schedule ? { prompt, iteration: 0, intervalMs: schedule.intervalMs } : { prompt, iteration: 0, nextWakeMs: schedule.firstWakeMs };
|
|
102
148
|
};
|
|
103
|
-
const status = () =>
|
|
149
|
+
const status = () =>
|
|
150
|
+
loop === undefined
|
|
151
|
+
? 'No loop is running. Usage: /loop [interval] <prompt>, with the interval at either end; /loop stop ends one.'
|
|
152
|
+
: `Loop: "${loop.prompt}" (iteration ${loop.iteration}${loop.intervalMs === undefined ? ', agent-paced' : `, every ${formatMs(loop.intervalMs)}`})`;
|
|
104
153
|
const wake = (delayMs: number) => {
|
|
105
154
|
if (loop === undefined) throw new Error('No loop is running. Start one with prompt plus interval or wake_in, or ask the user to run /loop.');
|
|
106
155
|
if (loop.intervalMs !== undefined) throw new Error(`This loop runs every ${formatMs(loop.intervalMs)}; only the user can change its interval. Pass stop: true to end it.`);
|
|
@@ -181,7 +230,7 @@ export function registerLoop(pi: ExtensionAPI, options: LoopOptions): { section:
|
|
|
181
230
|
pi.on('agent_settled', (event, ctx) => controller.settled(ctx, event.aborted));
|
|
182
231
|
pi.on('session_shutdown', () => controller.clear());
|
|
183
232
|
pi.registerCommand('loop', {
|
|
184
|
-
description: 'Run a prompt repeatedly: /loop [interval] <prompt
|
|
233
|
+
description: 'Run a prompt repeatedly: /loop [interval] <prompt>, interval either end and like 30s, 5m, 1h, every 10 minutes (at most 24d); /loop stop',
|
|
185
234
|
handler: async (args, ctx) => handleLoopCommand(controller, args, ctx),
|
|
186
235
|
});
|
|
187
236
|
registerLoopTool(pi, controller);
|