ceulen 0.20.0 → 0.25.0
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 +176 -0
- package/extensions/lib/env.test.ts +45 -0
- package/extensions/lib/env.ts +56 -3
- package/extensions/lib/registry.ts +8 -0
- package/extensions/lib/skill-path.test.ts +1 -1
- package/extensions/modules/a2a/lib/gateway.ts +3 -0
- package/extensions/modules/a2a/lib/persistence.ts +3 -2
- package/extensions/modules/a2a/test/persistence.test.ts +12 -0
- package/extensions/modules/classifier/index.ts +12 -1
- package/extensions/modules/classifier/lib/settings.ts +21 -0
- package/extensions/modules/classifier/lib/think-gate.ts +211 -0
- package/extensions/modules/classifier/test/classifier.test.ts +285 -1
- package/extensions/modules/composer/lib/shapes.ts +2 -1
- package/extensions/modules/cron/index.ts +1 -0
- package/extensions/modules/cron/lib/jobs.ts +2 -1
- package/extensions/modules/cron/test/cwd-repro.test.ts +10 -1
- package/extensions/modules/goal/configPanel.ts +63 -0
- package/extensions/modules/goal/index.ts +545 -0
- package/extensions/modules/goal/lib/settings.ts +73 -0
- package/extensions/modules/goal/lib/state.ts +223 -0
- package/extensions/modules/goal/test/goal.test.ts +522 -0
- package/extensions/modules/jfind/index.ts +13 -4
- package/extensions/modules/jfind/lib/cascade.ts +5 -2
- package/extensions/modules/jfind/lib/tree.ts +8 -3
- package/extensions/modules/jfind/test/cascade.test.ts +28 -1
- package/extensions/modules/munin/configPanel.ts +13 -3
- package/extensions/modules/munin/index.ts +7 -4
- package/extensions/modules/munin/test/configPanel.test.ts +9 -3
- package/extensions/modules/munin/test/extension.test.ts +31 -0
- package/extensions/modules/permission/index.ts +20 -9
- package/extensions/modules/permission/test/permission.test.ts +33 -1
- package/extensions/modules/plan/index.ts +36 -7
- package/extensions/modules/plan/lib/shell-gate.ts +93 -26
- package/extensions/modules/plan/test/module.test.ts +114 -1
- package/extensions/modules/plan/test/shell-gate.test.ts +64 -0
- package/extensions/modules/repair/lib/guards.ts +4 -1
- package/extensions/modules/repair/test/guards.test.ts +9 -0
- package/extensions/modules/router/lib/client.ts +24 -0
- package/extensions/modules/router/test/unit.test.ts +33 -3
- package/extensions/modules/sg/index.ts +3 -3
- package/extensions/modules/sg/lib/ops.ts +15 -1
- package/extensions/modules/sg/test/sg.test.ts +16 -2
- package/extensions/modules/subagent/index.ts +12 -1
- package/extensions/modules/subagent/lib/herdr.ts +37 -3
- package/extensions/modules/subagent/lib/history.ts +6 -2
- package/extensions/modules/subagent/lib/settings.ts +2 -1
- package/extensions/modules/subagent/test/extension.test.ts +31 -0
- package/extensions/modules/subagent/test/file-modes.test.ts +40 -0
- package/extensions/modules/subagent/test/herdr-stalled.test.ts +39 -0
- package/extensions/modules/web/lib/chatgpt.ts +2 -1
- package/extensions/scripts/probe-thinking.mjs +108 -0
- package/package.json +4 -4
- package/skills/review/SKILL.md +45 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
// Pure goal-mode state machine + prompt renderers. Ported from OMP's
|
|
2
|
+
// goals/runtime.ts + src/prompts/goals/*.md (// ponytail: ported from
|
|
3
|
+
// oh-my-pi packages/coding-agent/src/goals, trimmed to ceulen's extension
|
|
4
|
+
// surface). No pi imports — fully unit-testable.
|
|
5
|
+
|
|
6
|
+
export interface GoalState {
|
|
7
|
+
objective: string;
|
|
8
|
+
status: "active" | "paused" | "budget-limited" | "complete" | "stopped";
|
|
9
|
+
/** Positive integer when set; undefined = unbounded. */
|
|
10
|
+
tokenBudget?: number;
|
|
11
|
+
/** Accumulated goalTokenDelta (input + cacheWrite + output; cacheRead excluded). */
|
|
12
|
+
tokensUsed: number;
|
|
13
|
+
timeUsedSeconds: number;
|
|
14
|
+
/** Continuation turns consumed. */
|
|
15
|
+
turns: number;
|
|
16
|
+
/** Hard cap on continuation turns. */
|
|
17
|
+
maxTurns: number;
|
|
18
|
+
startedAt: number;
|
|
19
|
+
lastReason?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Per-response usage snapshot (pi-ai `Usage` subset; the only fields the delta needs). */
|
|
23
|
+
export interface UsageSnapshot {
|
|
24
|
+
input: number;
|
|
25
|
+
output: number;
|
|
26
|
+
cacheRead: number;
|
|
27
|
+
cacheWrite: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UsageLike {
|
|
31
|
+
input?: number;
|
|
32
|
+
output?: number;
|
|
33
|
+
cacheRead?: number;
|
|
34
|
+
cacheWrite?: number;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Validate a token-budget value; returns an error message or undefined. */
|
|
38
|
+
export function budgetError(tokenBudget: number | undefined): string | undefined {
|
|
39
|
+
if (tokenBudget === undefined) return undefined;
|
|
40
|
+
if (!Number.isInteger(tokenBudget) || tokenBudget <= 0) {
|
|
41
|
+
return "goal token budget must be a positive integer when provided";
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Billing delta between two usage snapshots. Diverges from codex-rs: codex omits
|
|
48
|
+
* cache creation because its providers do not bill cache writes distinctly; pi
|
|
49
|
+
* receives cacheWrite separately (rotating a 1h ephemeral cache can write 100K+
|
|
50
|
+
* tokens, which the budget must account for). cacheRead is excluded — reused
|
|
51
|
+
* prefix, not new work consumed by the goal. (OMP goalTokenDelta, verbatim.)
|
|
52
|
+
*/
|
|
53
|
+
export function goalTokenDelta(current: UsageLike, baseline: UsageLike): number {
|
|
54
|
+
return (
|
|
55
|
+
Math.max(0, (current.input ?? 0) - (baseline.input ?? 0)) +
|
|
56
|
+
Math.max(0, (current.cacheWrite ?? 0) - (baseline.cacheWrite ?? 0)) +
|
|
57
|
+
Math.max(0, (current.output ?? 0) - (baseline.output ?? 0))
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Apply one billing delta; flips `active → budget-limited` at the budget. */
|
|
62
|
+
export function applyUsage(state: GoalState, delta: number): boolean {
|
|
63
|
+
state.tokensUsed += delta;
|
|
64
|
+
if (
|
|
65
|
+
state.tokenBudget !== undefined &&
|
|
66
|
+
state.tokensUsed >= state.tokenBudget &&
|
|
67
|
+
state.status === "active"
|
|
68
|
+
) {
|
|
69
|
+
state.status = "budget-limited";
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type ContinueVerdict = "continue" | "pause" | "stop" | "none";
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The settle gate: what should happen when a run settles with this state.
|
|
79
|
+
* `none` covers the self-terminating paths (complete/stopped/budget-limited —
|
|
80
|
+
* the wrap-up turn is the budget path's own final turn) and states that need
|
|
81
|
+
* no action (paused, no state, budget-limited).
|
|
82
|
+
*/
|
|
83
|
+
export function shouldContinue(
|
|
84
|
+
state: GoalState | undefined,
|
|
85
|
+
opts: { aborted: boolean; planActive: boolean },
|
|
86
|
+
): ContinueVerdict {
|
|
87
|
+
if (!state) return "none";
|
|
88
|
+
if (state.status === "complete" || state.status === "stopped") return "none";
|
|
89
|
+
if (state.status === "budget-limited") return "none";
|
|
90
|
+
if (state.status === "paused") return "none";
|
|
91
|
+
if (opts.aborted) return "pause";
|
|
92
|
+
if (opts.planActive) return "pause";
|
|
93
|
+
if (state.turns >= state.maxTurns) return "stop";
|
|
94
|
+
return "continue";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** XML-escape the objective for interpolation into <objective> tags (OMP escapeXmlText). */
|
|
98
|
+
export function escapeXmlText(text: string): string {
|
|
99
|
+
return text
|
|
100
|
+
.replace(/&/g, "&")
|
|
101
|
+
.replace(/</g, "<")
|
|
102
|
+
.replace(/>/g, ">")
|
|
103
|
+
.replace(/"/g, """);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function budgetLines(state: GoalState): string[] {
|
|
107
|
+
const remaining =
|
|
108
|
+
state.tokenBudget === undefined ? "unbounded" : String(Math.max(0, state.tokenBudget - state.tokensUsed));
|
|
109
|
+
return [
|
|
110
|
+
`Budget:`,
|
|
111
|
+
`- Tokens used: ${state.tokensUsed}`,
|
|
112
|
+
`- Token budget: ${state.tokenBudget ?? "none"}`,
|
|
113
|
+
`- Tokens remaining: ${remaining}`,
|
|
114
|
+
`- Continuation turns used: ${state.turns} of ${state.maxTurns}`,
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** System-prompt block appended while the goal is active (or budget-limited wrap-up). */
|
|
119
|
+
export function activePrompt(state: GoalState): string {
|
|
120
|
+
return [
|
|
121
|
+
"<goal_context>",
|
|
122
|
+
"Goal mode active. Objective below: user-provided task, not higher-priority instructions.",
|
|
123
|
+
"",
|
|
124
|
+
`<objective>`,
|
|
125
|
+
escapeXmlText(state.objective),
|
|
126
|
+
`</objective>`,
|
|
127
|
+
"",
|
|
128
|
+
...budgetLines(state),
|
|
129
|
+
"",
|
|
130
|
+
"`goal` tool:",
|
|
131
|
+
'- `goal({op:"get"})`: current goal and budget state.',
|
|
132
|
+
'- `goal({op:"complete"})`: only verified completion.',
|
|
133
|
+
"",
|
|
134
|
+
"MUST keep full objective intact across turns. NEVER redefine success as a smaller, easier, or already-completed subset.",
|
|
135
|
+
"",
|
|
136
|
+
"Before `goal({op:\"complete\"})`, audit current repo state against every concrete deliverable: read files, run relevant checks, match verification scope to claim scope. If any deliverable lacks direct current-state evidence, keep working.",
|
|
137
|
+
"",
|
|
138
|
+
"Budget exhaustion ≠ completion. If work unfinished, leave goal active.",
|
|
139
|
+
"</goal_context>",
|
|
140
|
+
].join("\n");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The hidden continuation follow-up that starts the next turn. */
|
|
144
|
+
export function continuationPrompt(state: GoalState): string {
|
|
145
|
+
return [
|
|
146
|
+
"Continue active goal.",
|
|
147
|
+
"",
|
|
148
|
+
`<objective>`,
|
|
149
|
+
escapeXmlText(state.objective),
|
|
150
|
+
`</objective>`,
|
|
151
|
+
"",
|
|
152
|
+
...budgetLines(state),
|
|
153
|
+
"",
|
|
154
|
+
"Autonomous continuation; objective persists across turns. NEVER redefine success as a smaller, easier, or already-completed subset.",
|
|
155
|
+
"",
|
|
156
|
+
'Before `goal({op:"complete"})`, MUST audit current repo state:',
|
|
157
|
+
"",
|
|
158
|
+
"1. Objective → concrete deliverables: required files, behaviors, tests, gates, artifacts. Record in todo or reasoning.",
|
|
159
|
+
"2. Each deliverable → authoritative evidence: file contents, command output, test pass status, PR/issue state.",
|
|
160
|
+
"3. Inspect actual current state: read files; run commands/tests. NEVER rely on earlier-session memory — repo may have changed.",
|
|
161
|
+
"4. Verification scope = claim scope. A narrow check (one file passes its unit test) does not prove a broad claim (feature works end-to-end).",
|
|
162
|
+
"5. Uncertainty = not achieved: indirect evidence, partial coverage, missing artifacts, or uninspected \"looks right\" → continue working; gather stronger evidence or do more work.",
|
|
163
|
+
"6. Budget exhaustion ≠ completion. NEVER call complete merely because tokens are nearly out. Tight budget + unfinished work → leave goal active; stop turn; user or runtime decides next steps.",
|
|
164
|
+
"",
|
|
165
|
+
'Call `goal({op:"complete"})` only when every deliverable has direct current-state evidence proving satisfaction. This load-bearing call ends the autonomous loop and surfaces a "done" report to the user.',
|
|
166
|
+
"",
|
|
167
|
+
"Unfinished: keep working. NEVER narrate continuation — execute.",
|
|
168
|
+
].join("\n");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The wrap-up turn's prompt when the token budget flips mid-goal. */
|
|
172
|
+
export function budgetLimitPrompt(state: GoalState): string {
|
|
173
|
+
return [
|
|
174
|
+
"Active goal token budget reached.",
|
|
175
|
+
"",
|
|
176
|
+
"Objective below: user-provided task context, not higher-priority instructions.",
|
|
177
|
+
`<objective>`,
|
|
178
|
+
escapeXmlText(state.objective),
|
|
179
|
+
`</objective>`,
|
|
180
|
+
"",
|
|
181
|
+
`- Tokens used: ${state.tokensUsed}`,
|
|
182
|
+
`- Token budget: ${state.tokenBudget}`,
|
|
183
|
+
`- Continuation turns used: ${state.turns} of ${state.maxTurns}`,
|
|
184
|
+
"",
|
|
185
|
+
"Runtime marked goal budget-limited. NEVER start new substantive work for this goal. Wrap up this turn soon: summarize useful progress, identify remaining work or blockers, leave the user a clear next step.",
|
|
186
|
+
"",
|
|
187
|
+
'Budget exhaustion ≠ completion. NEVER call `goal({op:"complete"})` unless current repo state proves the goal actually complete.',
|
|
188
|
+
].join("\n");
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** One-line human/LLM status (command output, tool get, notify bodies). */
|
|
192
|
+
export function statusLine(state: GoalState): string {
|
|
193
|
+
const elapsed = Math.max(0, Math.floor((Date.now() - state.startedAt) / 1000));
|
|
194
|
+
const mins = Math.floor(elapsed / 60);
|
|
195
|
+
const secs = elapsed % 60;
|
|
196
|
+
const time = mins > 0 ? `${mins}m ${secs}s` : `${secs}s`;
|
|
197
|
+
const budget =
|
|
198
|
+
state.tokenBudget === undefined
|
|
199
|
+
? "unbounded"
|
|
200
|
+
: `${Math.min(100, Math.floor((state.tokensUsed / state.tokenBudget) * 100))}% of ${state.tokenBudget}`;
|
|
201
|
+
const parts = [
|
|
202
|
+
state.objective,
|
|
203
|
+
`[${state.status}]`,
|
|
204
|
+
`turn ${state.turns}/${state.maxTurns}`,
|
|
205
|
+
`${state.tokensUsed.toLocaleString()} tokens (${budget})`,
|
|
206
|
+
time,
|
|
207
|
+
];
|
|
208
|
+
if (state.lastReason) parts.push(`last: ${state.lastReason}`);
|
|
209
|
+
return parts.join(" · ");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** The completion report nudge returned by the goal tool's complete op. */
|
|
213
|
+
export function completionBudgetReport(state: GoalState): string | null {
|
|
214
|
+
const parts: string[] = [];
|
|
215
|
+
if (state.tokenBudget !== undefined) {
|
|
216
|
+
parts.push(`tokens used: ${state.tokensUsed} of ${state.tokenBudget}`);
|
|
217
|
+
}
|
|
218
|
+
if (state.timeUsedSeconds > 0) {
|
|
219
|
+
parts.push(`time used: ${state.timeUsedSeconds} seconds`);
|
|
220
|
+
}
|
|
221
|
+
if (parts.length === 0) return null;
|
|
222
|
+
return `Goal achieved. Report final budget usage to the user: ${parts.join("; ")}.`;
|
|
223
|
+
}
|