@amaster.ai/pi-goal 0.1.2-beta.42
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/LICENSE +201 -0
- package/README.md +120 -0
- package/dist/config.d.ts +36 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/derive.d.ts +17 -0
- package/dist/derive.d.ts.map +1 -0
- package/dist/derive.js +39 -0
- package/dist/derive.js.map +1 -0
- package/dist/evaluate.d.ts +28 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +64 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/extension.d.ts +28 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +281 -0
- package/dist/extension.js.map +1 -0
- package/dist/goal-state.d.ts +46 -0
- package/dist/goal-state.d.ts.map +1 -0
- package/dist/goal-state.js +89 -0
- package/dist/goal-state.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.d.ts +23 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +79 -0
- package/dist/llm.js.map +1 -0
- package/dist/prompts.d.ts +35 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +64 -0
- package/dist/prompts.js.map +1 -0
- package/dist/transcript.d.ts +20 -0
- package/dist/transcript.d.ts.map +1 -0
- package/dist/transcript.js +53 -0
- package/dist/transcript.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { buildSessionContext, } from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { loadSettings, resolveConfig, } from './config.js';
|
|
3
|
+
import { deriveCondition } from './derive.js';
|
|
4
|
+
import { evaluateCondition } from './evaluate.js';
|
|
5
|
+
import { GoalState, isClearKeyword, MAX_CONDITION_LENGTH } from './goal-state.js';
|
|
6
|
+
import { buildActivationMessage, buildContinueMessage } from './prompts.js';
|
|
7
|
+
import { buildTranscript, buildTranscriptWithMeta } from './transcript.js';
|
|
8
|
+
const STATUS_KEY = 'pi-goal';
|
|
9
|
+
/**
|
|
10
|
+
* Evaluate the active goal against the transcript and either stop (achieved /
|
|
11
|
+
* impossible / limited) or inject a continuation message. Idempotent guard: the
|
|
12
|
+
* caller must ensure only one invocation runs at a time (see extension wiring).
|
|
13
|
+
*/
|
|
14
|
+
export async function runGoalEngine(deps, messages) {
|
|
15
|
+
const { state, config, registry } = deps;
|
|
16
|
+
const goal = state.get();
|
|
17
|
+
if (!goal || goal.status !== 'active')
|
|
18
|
+
return 'skipped';
|
|
19
|
+
if (!config.model)
|
|
20
|
+
return 'skipped'; // engine disabled without a model
|
|
21
|
+
const { text: transcript, omitted } = buildTranscriptWithMeta(messages, config.transcriptMaxChars);
|
|
22
|
+
if (!transcript)
|
|
23
|
+
return 'skipped';
|
|
24
|
+
const verdict = await evaluateCondition({
|
|
25
|
+
registry,
|
|
26
|
+
modelConfig: config.model,
|
|
27
|
+
condition: goal.condition,
|
|
28
|
+
transcript,
|
|
29
|
+
omittedCount: omitted,
|
|
30
|
+
...(deps.signal ? { signal: deps.signal } : {}),
|
|
31
|
+
});
|
|
32
|
+
// Model unavailable / call failed: do nothing this round (degrade quietly).
|
|
33
|
+
if (verdict === null)
|
|
34
|
+
return 'skipped';
|
|
35
|
+
if (verdict.impossible) {
|
|
36
|
+
state.markImpossible(verdict.reason);
|
|
37
|
+
deps.notify(`Goal deemed unreachable: ${verdict.reason}`, 'warning');
|
|
38
|
+
deps.setStatus(formatStatus(state.get()));
|
|
39
|
+
return 'impossible';
|
|
40
|
+
}
|
|
41
|
+
if (verdict.ok) {
|
|
42
|
+
state.markAchieved(verdict.reason);
|
|
43
|
+
deps.notify(`Goal achieved: ${verdict.reason}`, 'info');
|
|
44
|
+
deps.setStatus(formatStatus(state.get()));
|
|
45
|
+
return 'achieved';
|
|
46
|
+
}
|
|
47
|
+
// Not yet met — apply guards before continuing.
|
|
48
|
+
const estimate = deps.estimateTokens ?? ((t) => Math.ceil(t.length / 4));
|
|
49
|
+
const tokensUsed = goal.tokensUsed + estimate(transcript);
|
|
50
|
+
state.recordIteration(verdict.reason, tokensUsed);
|
|
51
|
+
const current = state.get();
|
|
52
|
+
if (!current)
|
|
53
|
+
return 'skipped';
|
|
54
|
+
if (current.iterations >= config.maxIterations) {
|
|
55
|
+
state.markIterationLimited(verdict.reason);
|
|
56
|
+
deps.notify(`Goal paused after ${current.iterations} rounds (max reached). Last check: ${verdict.reason}`, 'warning');
|
|
57
|
+
deps.setStatus(formatStatus(state.get()));
|
|
58
|
+
return 'iteration_limited';
|
|
59
|
+
}
|
|
60
|
+
if (config.tokenBudget && tokensUsed >= config.tokenBudget) {
|
|
61
|
+
state.markBudgetLimited(verdict.reason);
|
|
62
|
+
deps.notify(`Goal paused: token budget reached. Last check: ${verdict.reason}`, 'warning');
|
|
63
|
+
deps.setStatus(formatStatus(state.get()));
|
|
64
|
+
return 'budget_limited';
|
|
65
|
+
}
|
|
66
|
+
deps.setStatus(formatStatus(current));
|
|
67
|
+
deps.sendUserMessage(buildContinueMessage(current.condition, verdict.reason));
|
|
68
|
+
return 'continued';
|
|
69
|
+
}
|
|
70
|
+
export default function goalExtension(pi, injectedConfig) {
|
|
71
|
+
const state = new GoalState();
|
|
72
|
+
let config = resolveConfig(injectedConfig);
|
|
73
|
+
let registry;
|
|
74
|
+
let engineRunning = false;
|
|
75
|
+
// Set when `--goal` was passed with an empty value: derivation is deferred to
|
|
76
|
+
// the first before_agent_start, where the user's prompt is available. At
|
|
77
|
+
// session_start there is no transcript yet, so deriving there yields nothing.
|
|
78
|
+
let pendingDerive = false;
|
|
79
|
+
pi.on('session_start', async (_event, ctx) => {
|
|
80
|
+
const fileConfig = loadSettings(ctx.cwd);
|
|
81
|
+
config = resolveConfig({ ...fileConfig, ...injectedConfig });
|
|
82
|
+
registry = ctx.modelRegistry;
|
|
83
|
+
ctx.ui.setStatus(STATUS_KEY, config.model ? 'goal: none' : 'goal: disabled (no model)');
|
|
84
|
+
// --goal <condition> flag: set the goal at startup (print mode can't dispatch
|
|
85
|
+
// the /goal slash command, so the flag is the CLI entry point). An empty
|
|
86
|
+
// string (bare --goal) defers derivation to before_agent_start, where the
|
|
87
|
+
// user's prompt for the turn is available to derive from.
|
|
88
|
+
const flagValue = pi.getFlag('goal');
|
|
89
|
+
if (typeof flagValue === 'string') {
|
|
90
|
+
const condition = flagValue.trim();
|
|
91
|
+
if (condition && !isClearKeyword(condition)) {
|
|
92
|
+
setExplicitGoal(condition, ctx);
|
|
93
|
+
}
|
|
94
|
+
else if (!condition) {
|
|
95
|
+
pendingDerive = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// First user prompt: if a --goal derivation is pending, derive the condition
|
|
100
|
+
// now — event.prompt carries what the user wants this turn, which is the
|
|
101
|
+
// signal to derive from. Fires once per prompt; we clear the flag after.
|
|
102
|
+
pi.on('before_agent_start', async (event, ctx) => {
|
|
103
|
+
if (!pendingDerive)
|
|
104
|
+
return;
|
|
105
|
+
pendingDerive = false;
|
|
106
|
+
const evt = event;
|
|
107
|
+
const prompt = typeof evt.prompt === 'string' ? evt.prompt : '';
|
|
108
|
+
// activate=false: the agent is about to run this prompt, so don't inject an
|
|
109
|
+
// activation message (it would throw "already processing"). The run reaches
|
|
110
|
+
// agent_end on its own, where the engine evaluates the goal.
|
|
111
|
+
await deriveAndSet(ctx, prompt, false);
|
|
112
|
+
});
|
|
113
|
+
pi.on('agent_end', async (event, ctx) => {
|
|
114
|
+
if (!state.isActive() || !config.model || !registry)
|
|
115
|
+
return;
|
|
116
|
+
if (engineRunning)
|
|
117
|
+
return; // re-entrancy guard: our own sendUserMessage re-triggers agent_end
|
|
118
|
+
const evt = event;
|
|
119
|
+
const messages = Array.isArray(evt.messages) ? evt.messages : [];
|
|
120
|
+
engineRunning = true;
|
|
121
|
+
try {
|
|
122
|
+
await runGoalEngine({
|
|
123
|
+
state,
|
|
124
|
+
config,
|
|
125
|
+
registry,
|
|
126
|
+
sendUserMessage: (content) => pi.sendUserMessage(content),
|
|
127
|
+
notify: (message, level) => ctx.ui.notify(message, level),
|
|
128
|
+
setStatus: (text) => ctx.ui.setStatus(STATUS_KEY, text),
|
|
129
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
130
|
+
}, messages);
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
console.error(`[pi-goal] engine error: ${err instanceof Error ? err.message : String(err)}`);
|
|
134
|
+
}
|
|
135
|
+
finally {
|
|
136
|
+
engineRunning = false;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
pi.on('session_shutdown', async () => {
|
|
140
|
+
state.clear();
|
|
141
|
+
registry = undefined;
|
|
142
|
+
pendingDerive = false;
|
|
143
|
+
});
|
|
144
|
+
pi.registerFlag('goal', {
|
|
145
|
+
description: 'Set a goal at startup — Pi keeps working until the condition is met. Pass a condition, or an empty string to derive one from context.',
|
|
146
|
+
type: 'string',
|
|
147
|
+
});
|
|
148
|
+
pi.registerCommand('goal', {
|
|
149
|
+
description: 'Set a goal — Pi keeps working until the condition is met. Usage: /goal [<condition> | clear]. With no argument, derives a goal from the conversation.',
|
|
150
|
+
getArgumentCompletions: (prefix) => {
|
|
151
|
+
const options = ['clear'];
|
|
152
|
+
const matches = options.filter((o) => o.startsWith(prefix.trim().toLowerCase()));
|
|
153
|
+
return matches.map((o) => ({ label: o, value: o }));
|
|
154
|
+
},
|
|
155
|
+
handler: async (args, ctx) => {
|
|
156
|
+
const arg = args.trim();
|
|
157
|
+
// Clear
|
|
158
|
+
if (isClearKeyword(arg)) {
|
|
159
|
+
const cleared = state.clear();
|
|
160
|
+
ctx.ui.setStatus(STATUS_KEY, config.model ? 'goal: none' : 'goal: disabled (no model)');
|
|
161
|
+
ctx.ui.notify(cleared ? `Goal cleared: ${cleared.condition}` : 'No goal was set.', 'info');
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
// Explicit condition
|
|
165
|
+
if (arg) {
|
|
166
|
+
setExplicitGoal(arg, ctx);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// No argument: show status if a goal exists, else derive
|
|
170
|
+
const existing = state.get();
|
|
171
|
+
if (existing && existing.status === 'active') {
|
|
172
|
+
ctx.ui.notify(formatDetail(existing), 'info');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
// Interactive /goal with no arg: derive from the session's conversation
|
|
176
|
+
// history (read from the session manager, the authoritative source).
|
|
177
|
+
await deriveAndSet(ctx, '', true, readSessionMessages(ctx));
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
/** Resolved conversation messages from the session, or [] if unavailable. */
|
|
181
|
+
function readSessionMessages(ctx) {
|
|
182
|
+
try {
|
|
183
|
+
const sm = ctx.sessionManager;
|
|
184
|
+
if (!sm)
|
|
185
|
+
return [];
|
|
186
|
+
const context = buildSessionContext(sm.getEntries(), sm.getLeafId());
|
|
187
|
+
return context.messages ?? [];
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function setExplicitGoal(condition, ctx) {
|
|
194
|
+
if (condition.length > MAX_CONDITION_LENGTH) {
|
|
195
|
+
ctx.ui.notify(`Goal condition is limited to ${MAX_CONDITION_LENGTH} characters.`, 'error');
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const goal = state.set(condition, 'explicit', tokenBudgetOpts());
|
|
200
|
+
ctx.ui.setStatus(STATUS_KEY, formatStatus(goal));
|
|
201
|
+
if (config.model) {
|
|
202
|
+
pi.sendUserMessage(buildActivationMessage(goal.condition));
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
ctx.ui.notify('Goal set, but no evaluator model is configured — auto-continuation is disabled.', 'warning');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
ctx.ui.notify(err instanceof Error ? err.message : 'Failed to set goal.', 'error');
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function deriveAndSet(ctx, extraContext = '', activate = true, history = []) {
|
|
213
|
+
if (!config.model || !registry) {
|
|
214
|
+
ctx.ui.notify('No evaluator model configured. Set `pi-goal.model` in settings, or use `/goal <condition>`.', 'warning');
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
ctx.ui.notify('Deriving a goal from the conversation…', 'info');
|
|
218
|
+
// Fold the current turn's prompt (when derivation was triggered by --goal
|
|
219
|
+
// before any turn has run) into the conversation history, so there is
|
|
220
|
+
// always something to derive from even on a fresh session.
|
|
221
|
+
const buffered = buildTranscript(history, config.transcriptMaxChars);
|
|
222
|
+
const extra = extraContext.trim() ? `[user] ${extraContext.trim()}` : '';
|
|
223
|
+
const transcript = [buffered, extra].filter(Boolean).join('\n\n');
|
|
224
|
+
const condition = await deriveCondition({
|
|
225
|
+
registry,
|
|
226
|
+
modelConfig: config.model,
|
|
227
|
+
transcript,
|
|
228
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
229
|
+
});
|
|
230
|
+
if (!condition) {
|
|
231
|
+
ctx.ui.notify('Could not derive a clear goal from the conversation. Try `/goal <condition>`.', 'warning');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (config.requireConfirmForDerived && ctx.hasUI) {
|
|
235
|
+
const approved = await ctx.ui.confirm('Set this goal?', `Pi will keep working until:\n\n${condition}`);
|
|
236
|
+
if (!approved) {
|
|
237
|
+
ctx.ui.notify('Goal not set.', 'info');
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
try {
|
|
242
|
+
const goal = state.set(condition, 'derived', tokenBudgetOpts());
|
|
243
|
+
ctx.ui.setStatus(STATUS_KEY, formatStatus(goal));
|
|
244
|
+
// Only inject the activation nudge when the agent is idle (interactive
|
|
245
|
+
// /goal). When deriving at before_agent_start, the agent is already about
|
|
246
|
+
// to run the user's prompt — injecting here throws "Agent is already
|
|
247
|
+
// processing a prompt". That run naturally reaches agent_end, where the
|
|
248
|
+
// engine evaluates the goal.
|
|
249
|
+
if (activate) {
|
|
250
|
+
pi.sendUserMessage(buildActivationMessage(goal.condition));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
ctx.ui.notify(err instanceof Error ? err.message : 'Failed to set goal.', 'error');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function tokenBudgetOpts() {
|
|
258
|
+
return config.tokenBudget ? { tokenBudget: config.tokenBudget } : {};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function formatStatus(goal) {
|
|
262
|
+
if (!goal)
|
|
263
|
+
return 'goal: none';
|
|
264
|
+
if (goal.status === 'active')
|
|
265
|
+
return `goal: active (${goal.iterations})`;
|
|
266
|
+
return `goal: ${goal.status}`;
|
|
267
|
+
}
|
|
268
|
+
function formatDetail(goal) {
|
|
269
|
+
const lines = [
|
|
270
|
+
`Goal (${goal.origin}): ${goal.condition}`,
|
|
271
|
+
`Status: ${goal.status}`,
|
|
272
|
+
`Rounds: ${goal.iterations}`,
|
|
273
|
+
];
|
|
274
|
+
if (goal.tokenBudget)
|
|
275
|
+
lines.push(`Tokens: ~${goal.tokensUsed} / ${goal.tokenBudget}`);
|
|
276
|
+
if (goal.lastReason)
|
|
277
|
+
lines.push(`Last check: ${goal.lastReason}`);
|
|
278
|
+
lines.push('/goal clear to stop early');
|
|
279
|
+
return lines.join('\n');
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extension.js","sourceRoot":"","sources":["../src/extension.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAGpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,YAAY,EAGZ,aAAa,GACd,MAA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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-scoped goal state. A single active goal per session, held in memory
|
|
3
|
+
* (mirrors Claude Code's session-level activeGoal — no cross-session persistence).
|
|
4
|
+
*/
|
|
5
|
+
export type GoalStatus = 'active' | 'achieved' | 'impossible' | 'budget_limited' | 'iteration_limited' | 'cleared';
|
|
6
|
+
export type GoalOrigin = 'derived' | 'explicit';
|
|
7
|
+
export interface ActiveGoal {
|
|
8
|
+
condition: string;
|
|
9
|
+
origin: GoalOrigin;
|
|
10
|
+
status: GoalStatus;
|
|
11
|
+
iterations: number;
|
|
12
|
+
setAt: number;
|
|
13
|
+
lastReason?: string;
|
|
14
|
+
tokenBudget?: number;
|
|
15
|
+
tokensUsed: number;
|
|
16
|
+
}
|
|
17
|
+
/** Max length of a goal condition, matching Claude Code's 4000-char cap. */
|
|
18
|
+
export declare const MAX_CONDITION_LENGTH = 4000;
|
|
19
|
+
/** Keywords that clear an active goal (matches Claude Code's clear-keyword set). */
|
|
20
|
+
export declare const CLEAR_KEYWORDS: Set<string>;
|
|
21
|
+
export declare function isClearKeyword(arg: string): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Holds the single active goal for a session. Instantiated per-session in the
|
|
24
|
+
* extension; not shared across sessions.
|
|
25
|
+
*/
|
|
26
|
+
export declare class GoalState {
|
|
27
|
+
private goal;
|
|
28
|
+
get(): ActiveGoal | undefined;
|
|
29
|
+
isActive(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Set (or replace) the active goal. Throws on an empty or over-long condition
|
|
32
|
+
* so callers can surface a sanitized error to the user.
|
|
33
|
+
*/
|
|
34
|
+
set(condition: string, origin: GoalOrigin, options?: {
|
|
35
|
+
tokenBudget?: number;
|
|
36
|
+
}): ActiveGoal;
|
|
37
|
+
clear(): ActiveGoal | undefined;
|
|
38
|
+
/** Record a not-yet-met round: bump iterations, store the evaluator's reason. */
|
|
39
|
+
recordIteration(reason: string, tokensUsed: number): ActiveGoal | undefined;
|
|
40
|
+
markAchieved(reason: string): ActiveGoal | undefined;
|
|
41
|
+
markImpossible(reason: string): ActiveGoal | undefined;
|
|
42
|
+
markBudgetLimited(reason?: string): ActiveGoal | undefined;
|
|
43
|
+
markIterationLimited(reason?: string): ActiveGoal | undefined;
|
|
44
|
+
private transition;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=goal-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-state.d.ts","sourceRoot":"","sources":["../src/goal-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,UAAU,GAClB,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,gBAAgB,GAChB,mBAAmB,GACnB,SAAS,CAAC;AAEd,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEhD,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,OAAO,CAAC;AAEzC,oFAAoF;AACpF,eAAO,MAAM,cAAc,aAA+D,CAAC;AAE3F,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,IAAI,CAAyB;IAErC,GAAG,IAAI,UAAU,GAAG,SAAS;IAI7B,QAAQ,IAAI,OAAO;IAInB;;;OAGG;IACH,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,UAAU;IAuB9F,KAAK,IAAI,UAAU,GAAG,SAAS;IAS/B,iFAAiF;IACjF,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAQ3E,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIpD,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAItD,iBAAiB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI1D,oBAAoB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI7D,OAAO,CAAC,UAAU;CAQnB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-scoped goal state. A single active goal per session, held in memory
|
|
3
|
+
* (mirrors Claude Code's session-level activeGoal — no cross-session persistence).
|
|
4
|
+
*/
|
|
5
|
+
/** Max length of a goal condition, matching Claude Code's 4000-char cap. */
|
|
6
|
+
export const MAX_CONDITION_LENGTH = 4000;
|
|
7
|
+
/** Keywords that clear an active goal (matches Claude Code's clear-keyword set). */
|
|
8
|
+
export const CLEAR_KEYWORDS = new Set(['clear', 'stop', 'off', 'reset', 'none', 'cancel']);
|
|
9
|
+
export function isClearKeyword(arg) {
|
|
10
|
+
return CLEAR_KEYWORDS.has(arg.trim().toLowerCase());
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Holds the single active goal for a session. Instantiated per-session in the
|
|
14
|
+
* extension; not shared across sessions.
|
|
15
|
+
*/
|
|
16
|
+
export class GoalState {
|
|
17
|
+
goal;
|
|
18
|
+
get() {
|
|
19
|
+
return this.goal;
|
|
20
|
+
}
|
|
21
|
+
isActive() {
|
|
22
|
+
return this.goal?.status === 'active';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Set (or replace) the active goal. Throws on an empty or over-long condition
|
|
26
|
+
* so callers can surface a sanitized error to the user.
|
|
27
|
+
*/
|
|
28
|
+
set(condition, origin, options = {}) {
|
|
29
|
+
const trimmed = condition.trim();
|
|
30
|
+
if (!trimmed) {
|
|
31
|
+
throw new Error('Goal condition cannot be empty');
|
|
32
|
+
}
|
|
33
|
+
if (trimmed.length > MAX_CONDITION_LENGTH) {
|
|
34
|
+
throw new Error(`Goal condition is limited to ${MAX_CONDITION_LENGTH} characters`);
|
|
35
|
+
}
|
|
36
|
+
const goal = {
|
|
37
|
+
condition: trimmed,
|
|
38
|
+
origin,
|
|
39
|
+
status: 'active',
|
|
40
|
+
iterations: 0,
|
|
41
|
+
setAt: Date.now(),
|
|
42
|
+
tokensUsed: 0,
|
|
43
|
+
};
|
|
44
|
+
if (typeof options.tokenBudget === 'number' && options.tokenBudget > 0) {
|
|
45
|
+
goal.tokenBudget = options.tokenBudget;
|
|
46
|
+
}
|
|
47
|
+
this.goal = goal;
|
|
48
|
+
return goal;
|
|
49
|
+
}
|
|
50
|
+
clear() {
|
|
51
|
+
const previous = this.goal;
|
|
52
|
+
if (previous) {
|
|
53
|
+
previous.status = 'cleared';
|
|
54
|
+
}
|
|
55
|
+
this.goal = undefined;
|
|
56
|
+
return previous;
|
|
57
|
+
}
|
|
58
|
+
/** Record a not-yet-met round: bump iterations, store the evaluator's reason. */
|
|
59
|
+
recordIteration(reason, tokensUsed) {
|
|
60
|
+
if (!this.goal)
|
|
61
|
+
return undefined;
|
|
62
|
+
this.goal.iterations += 1;
|
|
63
|
+
this.goal.lastReason = reason;
|
|
64
|
+
this.goal.tokensUsed = tokensUsed;
|
|
65
|
+
return this.goal;
|
|
66
|
+
}
|
|
67
|
+
markAchieved(reason) {
|
|
68
|
+
return this.transition('achieved', reason);
|
|
69
|
+
}
|
|
70
|
+
markImpossible(reason) {
|
|
71
|
+
return this.transition('impossible', reason);
|
|
72
|
+
}
|
|
73
|
+
markBudgetLimited(reason) {
|
|
74
|
+
return this.transition('budget_limited', reason);
|
|
75
|
+
}
|
|
76
|
+
markIterationLimited(reason) {
|
|
77
|
+
return this.transition('iteration_limited', reason);
|
|
78
|
+
}
|
|
79
|
+
transition(status, reason) {
|
|
80
|
+
if (!this.goal)
|
|
81
|
+
return undefined;
|
|
82
|
+
this.goal.status = status;
|
|
83
|
+
if (reason !== undefined) {
|
|
84
|
+
this.goal.lastReason = reason;
|
|
85
|
+
}
|
|
86
|
+
return this.goal;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=goal-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goal-state.js","sourceRoot":"","sources":["../src/goal-state.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAuBH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAEzC,oFAAoF;AACpF,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE3F,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAO,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,SAAS;IACZ,IAAI,CAAyB;IAErC,GAAG;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,GAAG,CAAC,SAAiB,EAAE,MAAkB,EAAE,UAAoC,EAAE;QAC/E,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC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C3B,OAAO,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED,iBAAiB,CAAC,MAAe;QAC/B,OAAO,IAAI,CAAC,UAAU,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,oBAAoB,CAAC,MAAe;QAClC,OAAO,IAAI,CAAC,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IACtD,CAAC;IAEO,UAAU,CAAC,MAAkB,EAAE,MAAe;QACpD,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAC1B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DEFAULTS, type GoalModelConfig, loadSettings, type PiGoalConfig, type ResolvedGoalConfig, resolveConfig, } from './config.js';
|
|
2
|
+
export { type DeriveOptions, deriveCondition } from './derive.js';
|
|
3
|
+
export { type EvaluateOptions, evaluateCondition, type GoalVerdict, parseVerdict, } from './evaluate.js';
|
|
4
|
+
export { default, type GoalEngineDeps, type PiGoalExtensionConfig, runGoalEngine, } from './extension.js';
|
|
5
|
+
export { type ActiveGoal, CLEAR_KEYWORDS, type GoalOrigin, GoalState, type GoalStatus, isClearKeyword, MAX_CONDITION_LENGTH, } from './goal-state.js';
|
|
6
|
+
export { completeOnce, type GoalModelRegistry } from './llm.js';
|
|
7
|
+
export { buildActivationMessage, buildContinueMessage, buildDeriveUserPrompt, buildEvaluateUserPrompt, buildTruncationNote, DERIVE_SYSTEM_PROMPT, EVALUATE_SYSTEM_PROMPT, } from './prompts.js';
|
|
8
|
+
export { buildTranscript, buildTranscriptWithMeta, extractText, type TranscriptResult, } from './transcript.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,KAAK,eAAe,EACpB,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EACL,KAAK,eAAe,EACpB,iBAAiB,EACjB,KAAK,WAAW,EAChB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,UAAU,EACf,cAAc,EACd,KAAK,UAAU,EACf,SAAS,EACT,KAAK,UAAU,EACf,cAAc,EACd,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,WAAW,EACX,KAAK,gBAAgB,GACtB,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DEFAULTS, loadSettings, resolveConfig, } from './config.js';
|
|
2
|
+
export { deriveCondition } from './derive.js';
|
|
3
|
+
export { evaluateCondition, parseVerdict, } from './evaluate.js';
|
|
4
|
+
export { default, runGoalEngine, } from './extension.js';
|
|
5
|
+
export { CLEAR_KEYWORDS, GoalState, isClearKeyword, MAX_CONDITION_LENGTH, } from './goal-state.js';
|
|
6
|
+
export { completeOnce } from './llm.js';
|
|
7
|
+
export { buildActivationMessage, buildContinueMessage, buildDeriveUserPrompt, buildEvaluateUserPrompt, buildTruncationNote, DERIVE_SYSTEM_PROMPT, EVALUATE_SYSTEM_PROMPT, } from './prompts.js';
|
|
8
|
+
export { buildTranscript, buildTranscriptWithMeta, extractText, } from './transcript.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,YAAY,EAGZ,aAAa,GACd,MAAM,aAAa,CAAC;AACrB,OAAO,EAAsB,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAEL,iBAAiB,EAEjB,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,OAAO,EAGP,aAAa,GACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,cAAc,EAEd,SAAS,EAET,cAAc,EACd,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,YAAY,EAA0B,MAAM,UAAU,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,WAAW,GAEZ,MAAM,iBAAiB,CAAC"}
|
package/dist/llm.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-turn, tool-less LLM completion helper shared by the derive and
|
|
3
|
+
* evaluate steps. Wraps pi-agent-core's Agent + pi-ai's streamSimple, the same
|
|
4
|
+
* primitives pi-memory uses for background work.
|
|
5
|
+
*/
|
|
6
|
+
import type { GoalModelConfig } from './config.js';
|
|
7
|
+
/** Minimal slice of ctx.modelRegistry we depend on (kept narrow for testability). */
|
|
8
|
+
export interface GoalModelRegistry {
|
|
9
|
+
find(provider: string, model: string): unknown;
|
|
10
|
+
getApiKeyAndHeaders(model: unknown): Promise<{
|
|
11
|
+
ok: boolean;
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
error?: string;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Run one system+user prompt through the model and return the assistant's text.
|
|
19
|
+
* Returns null on any resolution/auth failure so callers can degrade gracefully
|
|
20
|
+
* (never throws for expected failures).
|
|
21
|
+
*/
|
|
22
|
+
export declare function completeOnce(registry: GoalModelRegistry, modelConfig: GoalModelConfig, systemPrompt: string, userPrompt: string, signal?: AbortSignal): Promise<string | null>;
|
|
23
|
+
//# sourceMappingURL=llm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,qFAAqF;AACrF,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/C,mBAAmB,CACjB,KAAK,EAAE,OAAO,GACb,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAChG;AAOD;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,eAAe,EAC5B,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAsCxB"}
|
package/dist/llm.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-turn, tool-less LLM completion helper shared by the derive and
|
|
3
|
+
* evaluate steps. Wraps pi-agent-core's Agent + pi-ai's streamSimple, the same
|
|
4
|
+
* primitives pi-memory uses for background work.
|
|
5
|
+
*/
|
|
6
|
+
import { Agent } from '@earendil-works/pi-agent-core';
|
|
7
|
+
import { streamSimple } from '@earendil-works/pi-ai/compat';
|
|
8
|
+
/**
|
|
9
|
+
* Run one system+user prompt through the model and return the assistant's text.
|
|
10
|
+
* Returns null on any resolution/auth failure so callers can degrade gracefully
|
|
11
|
+
* (never throws for expected failures).
|
|
12
|
+
*/
|
|
13
|
+
export async function completeOnce(registry, modelConfig, systemPrompt, userPrompt, signal) {
|
|
14
|
+
const model = registry.find(modelConfig.provider, modelConfig.model);
|
|
15
|
+
if (!model)
|
|
16
|
+
return null;
|
|
17
|
+
const auth = await registry.getApiKeyAndHeaders(model);
|
|
18
|
+
if (!auth.ok)
|
|
19
|
+
return null;
|
|
20
|
+
const agent = new Agent({
|
|
21
|
+
initialState: {
|
|
22
|
+
systemPrompt,
|
|
23
|
+
model: model,
|
|
24
|
+
tools: [],
|
|
25
|
+
},
|
|
26
|
+
streamFn: (m, c, streamOpts) => {
|
|
27
|
+
const merged = { ...(streamOpts ?? {}) };
|
|
28
|
+
if (auth.apiKey)
|
|
29
|
+
merged.apiKey = auth.apiKey;
|
|
30
|
+
if (auth.headers)
|
|
31
|
+
merged.headers = auth.headers;
|
|
32
|
+
const existingSignal = streamOpts?.signal;
|
|
33
|
+
if (!existingSignal && signal)
|
|
34
|
+
merged.signal = signal;
|
|
35
|
+
return streamSimple(m, c, merged);
|
|
36
|
+
},
|
|
37
|
+
convertToLlm: (msgs) => msgs,
|
|
38
|
+
});
|
|
39
|
+
// Tool-less: a single assistant turn ends the run. Guard against runaway anyway.
|
|
40
|
+
agent.subscribe((event) => {
|
|
41
|
+
if (event.type === 'turn_end') {
|
|
42
|
+
void agent.abort();
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
await agent.prompt(userPrompt);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return lastAssistantText(agent.state.messages);
|
|
52
|
+
}
|
|
53
|
+
function lastAssistantText(messages) {
|
|
54
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
55
|
+
const msg = messages[i];
|
|
56
|
+
if (msg?.role !== 'assistant')
|
|
57
|
+
continue;
|
|
58
|
+
const text = extractText(msg.content);
|
|
59
|
+
if (text)
|
|
60
|
+
return text;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
function extractText(content) {
|
|
65
|
+
if (typeof content === 'string')
|
|
66
|
+
return content.trim();
|
|
67
|
+
if (Array.isArray(content)) {
|
|
68
|
+
return content
|
|
69
|
+
.filter((c) => !!c &&
|
|
70
|
+
typeof c === 'object' &&
|
|
71
|
+
c.type === 'text' &&
|
|
72
|
+
typeof c.text === 'string')
|
|
73
|
+
.map((c) => c.text)
|
|
74
|
+
.join('\n')
|
|
75
|
+
.trim();
|
|
76
|
+
}
|
|
77
|
+
return '';
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=llm.js.map
|
package/dist/llm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm.js","sourceRoot":"","sources":["../src/llm.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAgB5D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAA2B,E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 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt templates for the goal engine.
|
|
3
|
+
*
|
|
4
|
+
* The evaluator and activation prompts are adapted almost verbatim from Claude
|
|
5
|
+
* Code's own stop-hook prompts (agent-prompt-hook-condition-evaluator-stop,
|
|
6
|
+
* system-reminder-session-stop-hook-active), tuned only where pi's mechanics
|
|
7
|
+
* differ (a `/goal` command instead of CC's). The derive prompt has no CC
|
|
8
|
+
* analogue — CC always takes an explicit condition — so it is ours.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DERIVE_SYSTEM_PROMPT = "You infer a single, concrete completion condition from a coding conversation.\n\nGiven the recent transcript, output ONE line describing the measurable outcome that would mean the user's current objective is fully handled. This condition will later be used to judge whether the agent may stop working.\n\nRules:\n- Output ONLY the condition text \u2014 no preamble, no quotes, no markdown, no trailing explanation.\n- Make it measurable and verifiable (e.g. \"All tests pass and `pnpm lint` reports no errors\", \"The /login endpoint returns 200 for valid credentials and 401 otherwise\").\n- Base it on the user's most recent intent, not incidental side-quests.\n- Keep it under 300 characters.\n- If the conversation has no actionable objective, output exactly: NONE";
|
|
11
|
+
export declare function buildDeriveUserPrompt(transcript: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Stop-condition evaluator. Adapted from Claude Code's
|
|
14
|
+
* `agent-prompt-hook-condition-evaluator-stop` — the quote-evidence
|
|
15
|
+
* requirement, the "insufficient evidence in transcript" fallback, and the
|
|
16
|
+
* impossible-judgment discipline all come from CC's original wording.
|
|
17
|
+
*/
|
|
18
|
+
export declare const EVALUATE_SYSTEM_PROMPT = "You are evaluating a stop-condition hook. Read the conversation transcript carefully, then judge whether the user-provided condition is satisfied.\n\nYour response must be a JSON object with one of these shapes:\n- {\"ok\": true, \"reason\": \"<quote evidence from the transcript that satisfies the condition>\"}\n- {\"ok\": false, \"reason\": \"<quote what is missing or what blocks the condition>\"}\n- {\"ok\": false, \"impossible\": true, \"reason\": \"<explain why the condition can never be satisfied>\"}\n\nAlways include a \"reason\" field, quoting specific text from the transcript whenever possible. If the transcript does not contain clear evidence that the condition is satisfied, return {\"ok\": false, \"reason\": \"insufficient evidence in transcript\"}.\n\nOnly use {\"ok\": false, \"impossible\": true} when the condition is genuinely unachievable in this session \u2014 for example: the condition is self-contradictory, it depends on a resource or capability that is unavailable, or the assistant has explicitly tried, exhausted reasonable approaches, and stated it cannot be done. Apply your own judgment when deciding this \u2014 the assistant claiming the goal is impossible is evidence, not proof; independently confirm the condition is genuinely unachievable rather than deferring to the assistant's self-assessment. Do not use it just because the goal has not been reached yet or because progress is slow. When in doubt, return {\"ok\": false} without \"impossible\".";
|
|
19
|
+
/**
|
|
20
|
+
* Note prepended to the transcript when older messages were dropped to fit the
|
|
21
|
+
* evaluator's char cap. Adapted from CC's
|
|
22
|
+
* `system-prompt-hook-evaluator-truncated-transcript-note`: if the evidence
|
|
23
|
+
* might be in the omitted prefix, the evaluator should return insufficient
|
|
24
|
+
* evidence rather than guess.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildTruncationNote(omittedCount: number): string;
|
|
27
|
+
export declare function buildEvaluateUserPrompt(condition: string, transcript: string, omittedCount?: number): string;
|
|
28
|
+
/**
|
|
29
|
+
* Injected once when a goal is set, so the main agent starts working toward it.
|
|
30
|
+
* Adapted from CC's `system-reminder-session-stop-hook-active`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildActivationMessage(condition: string): string;
|
|
33
|
+
/** Injected after a not-yet-met evaluation to drive the next round of work. */
|
|
34
|
+
export declare function buildContinueMessage(condition: string, reason: string): string;
|
|
35
|
+
//# sourceMappingURL=prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,oBAAoB,qwBASuC,CAAC;AAEzE,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,w9CAS0pB,CAAC;AAE9rB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,YAAY,SAAI,GACf,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9E"}
|