@oyasmi/pipiclaw 0.8.9 → 0.8.10-beta.1
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/dist/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +6 -10
- package/dist/agent/maintenance-context.d.ts +0 -1
- package/dist/agent/maintenance-context.js +0 -7
- package/dist/agent/session-events.d.ts +1 -0
- package/dist/agent/session-events.js +10 -0
- package/dist/agent/types.d.ts +7 -0
- package/dist/agent/types.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/memory/consolidation.js +0 -1
- package/dist/memory/extraction.d.ts +1 -7
- package/dist/memory/extraction.js +2 -46
- package/dist/memory/lifecycle.js +3 -3
- package/dist/memory/maintenance-gates.d.ts +4 -16
- package/dist/memory/maintenance-gates.js +11 -51
- package/dist/memory/maintenance-jobs.d.ts +3 -14
- package/dist/memory/maintenance-jobs.js +12 -103
- package/dist/memory/maintenance-state.d.ts +2 -6
- package/dist/memory/maintenance-state.js +14 -10
- package/dist/memory/promotion.d.ts +0 -22
- package/dist/memory/promotion.js +1 -8
- package/dist/memory/review-log.d.ts +1 -1
- package/dist/memory/scheduler.d.ts +1 -9
- package/dist/memory/scheduler.js +3 -15
- package/dist/memory/source-window.d.ts +2 -2
- package/dist/memory/task-digest.js +0 -2
- package/dist/models/utils.d.ts +5 -0
- package/dist/models/utils.js +10 -0
- package/dist/playbooks/task-closeout.md +2 -0
- package/dist/playbooks/task-delegation.md +3 -3
- package/dist/playbooks/task-driving.md +3 -3
- package/dist/playbooks/task-planning.md +6 -5
- package/dist/runtime/bootstrap.js +1 -4
- package/dist/runtime/task-commands.js +35 -16
- package/dist/runtime/task-driver.js +3 -1
- package/dist/settings.d.ts +4 -14
- package/dist/settings.js +2 -26
- package/dist/shared/task-ledger.d.ts +11 -0
- package/dist/shared/task-ledger.js +185 -3
- package/dist/subagents/discovery.d.ts +41 -7
- package/dist/subagents/discovery.js +74 -24
- package/dist/subagents/tool.d.ts +2 -7
- package/dist/subagents/tool.js +17 -19
- package/dist/tasks/control.d.ts +17 -6
- package/dist/tasks/control.js +42 -19
- package/dist/tasks/store.d.ts +1 -0
- package/dist/tasks/store.js +8 -0
- package/dist/tasks/transitions.d.ts +1 -1
- package/dist/tasks/transitions.js +1 -0
- package/dist/tools/registry.js +2 -0
- package/dist/tools/task-manage/create.js +2 -1
- package/dist/tools/task-manage/lifecycle.d.ts +7 -0
- package/dist/tools/task-manage/lifecycle.js +55 -14
- package/dist/tools/task-manage/schema.d.ts +2 -4
- package/dist/tools/task-manage/schema.js +14 -16
- package/dist/tools/task-manage/shared.d.ts +1 -0
- package/dist/tools/task-manage/shared.js +10 -9
- package/dist/tools/task-manage/types.d.ts +3 -1
- package/dist/tools/task-manage/verification.js +1 -2
- package/dist/tools/task-manage.js +4 -2
- package/examples/sub-agents/README.md +1 -1
- package/package.json +1 -1
- package/dist/memory/post-turn-review.d.ts +0 -43
- package/dist/memory/post-turn-review.js +0 -136
- package/dist/memory/promotion-signals.d.ts +0 -5
- package/dist/memory/promotion-signals.js +0 -33
|
@@ -190,14 +190,12 @@ async function listTasks(channelDir) {
|
|
|
190
190
|
}
|
|
191
191
|
const blocks = entries.map((entry) => {
|
|
192
192
|
const status = entry.frontmatter.readable ? (entry.frontmatter.status ?? "active") : "⚠ unreadable frontmatter";
|
|
193
|
-
const detail = [` status: ${status}`, `wake: ${relativeWake(entry.wakeMs, now)}`];
|
|
193
|
+
const detail = [` status: ${status}`, `next wake: ${relativeWake(entry.wakeMs, now)}`];
|
|
194
194
|
const control = entry.frontmatter.control;
|
|
195
195
|
if (control) {
|
|
196
196
|
detail.push(`priority: ${control.priority}`);
|
|
197
197
|
detail.push(`attempts: ${control.usage.attempts}/${control.budget.maxAttempts}`);
|
|
198
198
|
detail.push(`verify: ${control.verification.mode}/${control.verification.status}`);
|
|
199
|
-
if (control.isolation !== "shared")
|
|
200
|
-
detail.push(`isolation: ${control.isolation}`);
|
|
201
199
|
if (control.sideEffects !== "workspace") {
|
|
202
200
|
detail.push(`effects: ${control.sideEffects}/${control.externalApproval}`);
|
|
203
201
|
}
|
|
@@ -211,9 +209,15 @@ async function listTasks(channelDir) {
|
|
|
211
209
|
detail.push(`next: ${control.nextAction}`);
|
|
212
210
|
if (control.worktree?.branch)
|
|
213
211
|
detail.push(`branch: ${control.worktree.branch}`);
|
|
212
|
+
if (control.cycleId) {
|
|
213
|
+
detail.push(`${status === "done" ? "last" : "current"} cycle: ${control.cycleId}`);
|
|
214
|
+
}
|
|
214
215
|
}
|
|
215
216
|
if (entry.frontmatter.recurrence)
|
|
216
217
|
detail.push(`recurrence: ${entry.frontmatter.recurrence}`);
|
|
218
|
+
if (entry.frontmatter.schedule) {
|
|
219
|
+
detail.push(`schedule timezone: ${Intl.DateTimeFormat().resolvedOptions().timeZone} (host)`);
|
|
220
|
+
}
|
|
217
221
|
return `- ${entry.id} — ${entry.title}\n${detail.join(" ")}`;
|
|
218
222
|
});
|
|
219
223
|
return `# Tasks: ${entries.length} active\n\n${blocks.join("\n")}`;
|
|
@@ -260,7 +264,6 @@ export async function pauseTask(options, idInput) {
|
|
|
260
264
|
task.fields.wake = undefined;
|
|
261
265
|
if (task.fields.control) {
|
|
262
266
|
task.fields.control.pausedBy = "user";
|
|
263
|
-
task.fields.control.lastOutcome = "blocked";
|
|
264
267
|
task.fields.control.blockedReason = `Paused by ${options.approver?.trim() || "a user"}.`;
|
|
265
268
|
}
|
|
266
269
|
await writeStoredTask(task);
|
|
@@ -279,7 +282,6 @@ export async function resumeTask(options, idInput) {
|
|
|
279
282
|
task.fields.wake = undefined;
|
|
280
283
|
if (task.fields.control) {
|
|
281
284
|
task.fields.control.pausedBy = undefined;
|
|
282
|
-
task.fields.control.lastOutcome = "pending";
|
|
283
285
|
task.fields.control.blockedReason = undefined;
|
|
284
286
|
}
|
|
285
287
|
await writeStoredTask(task);
|
|
@@ -301,7 +303,6 @@ async function runTask(options, idInput) {
|
|
|
301
303
|
task.fields.wake = undefined;
|
|
302
304
|
if (task.fields.control) {
|
|
303
305
|
task.fields.control.pausedBy = undefined;
|
|
304
|
-
task.fields.control.lastOutcome = "pending";
|
|
305
306
|
task.fields.control.blockedReason = undefined;
|
|
306
307
|
}
|
|
307
308
|
await writeStoredTask(task);
|
|
@@ -319,13 +320,15 @@ function renderUsageLine(entry) {
|
|
|
319
320
|
if (!control)
|
|
320
321
|
return `- ${entry.id}: legacy task (no governed usage recorded)`;
|
|
321
322
|
const verification = control.verification;
|
|
323
|
+
const cycleCost = control.usage.costKnown ? `$${control.usage.costUsd.toFixed(4)}` : "unavailable";
|
|
324
|
+
const lifetimeCost = control.lifetimeUsage.costKnown
|
|
325
|
+
? `$${control.lifetimeUsage.costUsd.toFixed(4)}`
|
|
326
|
+
: "unavailable";
|
|
322
327
|
return [
|
|
323
328
|
`- ${entry.id} — ${entry.title}`,
|
|
324
|
-
`
|
|
325
|
-
`
|
|
326
|
-
`
|
|
327
|
-
` wall time: ${control.usage.wallTimeMinutes.toFixed(1)}m`,
|
|
328
|
-
` last outcome: ${control.lastOutcome}`,
|
|
329
|
+
` this cycle: ${control.usage.attempts}/${control.budget.maxAttempts} attempts, ${control.usage.tokens} tokens, ${cycleCost}, ${control.usage.wallTimeMinutes.toFixed(1)}m`,
|
|
330
|
+
` recorded lifetime: ${control.lifetimeUsage.attempts} attempts, ${control.lifetimeUsage.tokens} tokens, ${lifetimeCost}, ${control.lifetimeUsage.wallTimeMinutes.toFixed(1)}m`,
|
|
331
|
+
` last run: ${control.lastOutcome}`,
|
|
329
332
|
` verification: ${verification.mode}/${verification.status}`,
|
|
330
333
|
].join("\n");
|
|
331
334
|
}
|
|
@@ -353,22 +356,38 @@ async function taskStats(options, idInput) {
|
|
|
353
356
|
const governed = entries.filter((entry) => entry.frontmatter.control);
|
|
354
357
|
const totals = governed.reduce((total, entry) => {
|
|
355
358
|
const usage = entry.frontmatter.control.usage;
|
|
359
|
+
const lifetime = entry.frontmatter.control.lifetimeUsage;
|
|
356
360
|
total.attempts += usage.attempts;
|
|
357
361
|
total.tokens += usage.tokens;
|
|
358
362
|
total.costUsd += usage.costUsd;
|
|
363
|
+
total.costKnown &&= usage.costKnown;
|
|
359
364
|
total.wallTimeMinutes += usage.wallTimeMinutes;
|
|
365
|
+
total.lifetimeAttempts += lifetime.attempts;
|
|
366
|
+
total.lifetimeTokens += lifetime.tokens;
|
|
367
|
+
total.lifetimeCostUsd += lifetime.costUsd;
|
|
368
|
+
total.lifetimeCostKnown &&= lifetime.costKnown;
|
|
369
|
+
total.lifetimeWallTimeMinutes += lifetime.wallTimeMinutes;
|
|
360
370
|
return total;
|
|
361
|
-
}, {
|
|
371
|
+
}, {
|
|
372
|
+
attempts: 0,
|
|
373
|
+
tokens: 0,
|
|
374
|
+
costUsd: 0,
|
|
375
|
+
costKnown: true,
|
|
376
|
+
wallTimeMinutes: 0,
|
|
377
|
+
lifetimeAttempts: 0,
|
|
378
|
+
lifetimeTokens: 0,
|
|
379
|
+
lifetimeCostUsd: 0,
|
|
380
|
+
lifetimeCostKnown: true,
|
|
381
|
+
lifetimeWallTimeMinutes: 0,
|
|
382
|
+
});
|
|
362
383
|
const verified = governed.filter((entry) => entry.frontmatter.control?.verification.status === "passed").length;
|
|
363
384
|
const stalled = governed.filter((entry) => entry.frontmatter.control?.lastOutcome === "failed").length;
|
|
364
385
|
return [
|
|
365
386
|
"# Task Stats",
|
|
366
387
|
"",
|
|
367
388
|
`governed tasks: ${governed.length}/${entries.length}`,
|
|
368
|
-
`
|
|
369
|
-
`
|
|
370
|
-
`cost: $${totals.costUsd.toFixed(4)}`,
|
|
371
|
-
`wall time: ${totals.wallTimeMinutes.toFixed(1)}m`,
|
|
389
|
+
`this cycle: ${totals.attempts} attempts, ${totals.tokens} tokens, ${totals.costKnown ? `$${totals.costUsd.toFixed(4)}` : "cost unavailable"}, ${totals.wallTimeMinutes.toFixed(1)}m`,
|
|
390
|
+
`recorded lifetime: ${totals.lifetimeAttempts} attempts, ${totals.lifetimeTokens} tokens, ${totals.lifetimeCostKnown ? `$${totals.lifetimeCostUsd.toFixed(4)}` : "cost unavailable"}, ${totals.lifetimeWallTimeMinutes.toFixed(1)}m`,
|
|
372
391
|
`verification PASS: ${verified}`,
|
|
373
392
|
`last-run failures: ${stalled}`,
|
|
374
393
|
"",
|
|
@@ -114,7 +114,8 @@ export function createTaskDriverEvent(channelId, entry, nowMs) {
|
|
|
114
114
|
`Open tasks/${entry.id}.md and read ${join(PLAYBOOKS_DIR, "task-driving.md")} before acting. ` +
|
|
115
115
|
"Advance the next concrete step under the task's current control, acceptance, approval, and verification state. " +
|
|
116
116
|
`If complete or waiting, use the matching task_manage lifecycle/checkpoint action from the playbook.${verificationInstruction} ` +
|
|
117
|
-
"
|
|
117
|
+
"For a recurring occurrence intentionally not run because it is duplicate or already satisfied, call task_manage skip with the reason, then respond with exactly [SILENT]. " +
|
|
118
|
+
"If no task state or tool action is needed and this wake produces no user-visible result, respond with exactly [SILENT].",
|
|
118
119
|
ts: String(nowMs),
|
|
119
120
|
conversationId: "",
|
|
120
121
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
@@ -196,6 +197,7 @@ export class TaskDriver {
|
|
|
196
197
|
if (this.loopActive)
|
|
197
198
|
return;
|
|
198
199
|
this.loopActive = true;
|
|
200
|
+
log.logInfo("Task driver started", `schedule timezone=${Intl.DateTimeFormat().resolvedOptions().timeZone} (host)`);
|
|
199
201
|
void this.tick();
|
|
200
202
|
}
|
|
201
203
|
stop() {
|
package/dist/settings.d.ts
CHANGED
|
@@ -84,22 +84,14 @@ export interface PipiclawSessionMemorySettings {
|
|
|
84
84
|
forceRefreshBeforeCompact: boolean;
|
|
85
85
|
forceRefreshBeforeNewSession: boolean;
|
|
86
86
|
}
|
|
87
|
-
export interface PipiclawMemoryGrowthSettings {
|
|
88
|
-
postTurnReviewEnabled: boolean;
|
|
89
|
-
autoWriteChannelMemory: boolean;
|
|
90
|
-
autoWriteWorkspaceSkills: boolean;
|
|
91
|
-
minSkillAutoWriteConfidence: number;
|
|
92
|
-
minMemoryAutoWriteConfidence: number;
|
|
93
|
-
idleWritesHistory: boolean;
|
|
94
|
-
minTurnsBetweenReview: number;
|
|
95
|
-
minToolCallsBetweenReview: number;
|
|
96
|
-
}
|
|
97
87
|
export interface PipiclawMemoryMaintenanceSettings {
|
|
98
88
|
enabled: boolean;
|
|
99
89
|
minIdleMinutesBeforeLlmWork: number;
|
|
100
90
|
sessionRefreshIntervalMinutes: number;
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
/** Idle cadence of the merged memory checkpoint (durable extraction) job. */
|
|
92
|
+
checkpointIntervalMinutes: number;
|
|
93
|
+
/** Confidence bar a candidate must clear before it is written to MEMORY.md. */
|
|
94
|
+
minMemoryAutoWriteConfidence: number;
|
|
103
95
|
structuralMaintenanceIntervalHours: number;
|
|
104
96
|
maxConcurrentChannels: number;
|
|
105
97
|
failureBackoffMinutes: number;
|
|
@@ -142,7 +134,6 @@ export interface PipiclawSettings {
|
|
|
142
134
|
taskDigest?: Partial<PipiclawTaskDigestSettings>;
|
|
143
135
|
taskDriver?: Partial<PipiclawTaskDriverSettings>;
|
|
144
136
|
sessionMemory?: Partial<PipiclawSessionMemorySettings>;
|
|
145
|
-
memoryGrowth?: Partial<PipiclawMemoryGrowthSettings>;
|
|
146
137
|
memoryMaintenance?: Partial<PipiclawMemoryMaintenanceSettings>;
|
|
147
138
|
sessionSearch?: Partial<PipiclawSessionSearchSettings>;
|
|
148
139
|
logging?: Partial<Omit<PipiclawLoggingSettings, "file">> & {
|
|
@@ -182,7 +173,6 @@ export declare class PipiclawSettingsManager {
|
|
|
182
173
|
getTaskDigestSettings(): PipiclawTaskDigestSettings;
|
|
183
174
|
getTaskDriverSettings(): PipiclawTaskDriverSettings;
|
|
184
175
|
getSessionMemorySettings(): PipiclawSessionMemorySettings;
|
|
185
|
-
getMemoryGrowthSettings(): PipiclawMemoryGrowthSettings;
|
|
186
176
|
getMemoryMaintenanceSettings(): PipiclawMemoryMaintenanceSettings;
|
|
187
177
|
getSessionSearchSettings(): PipiclawSessionSearchSettings;
|
|
188
178
|
getLoggingSettings(): PipiclawLoggingSettings;
|
package/dist/settings.js
CHANGED
|
@@ -53,17 +53,6 @@ const DEFAULT_SESSION_MEMORY = {
|
|
|
53
53
|
forceRefreshBeforeCompact: true,
|
|
54
54
|
forceRefreshBeforeNewSession: true,
|
|
55
55
|
};
|
|
56
|
-
const DEFAULT_MEMORY_GROWTH = {
|
|
57
|
-
postTurnReviewEnabled: true,
|
|
58
|
-
autoWriteChannelMemory: true,
|
|
59
|
-
autoWriteWorkspaceSkills: false,
|
|
60
|
-
minSkillAutoWriteConfidence: 0.9,
|
|
61
|
-
minMemoryAutoWriteConfidence: 0.85,
|
|
62
|
-
idleWritesHistory: false,
|
|
63
|
-
minTurnsBetweenReview: 12,
|
|
64
|
-
minToolCallsBetweenReview: 24,
|
|
65
|
-
};
|
|
66
|
-
const MIN_SKILL_AUTO_WRITE_CONFIDENCE = 0.9;
|
|
67
56
|
const DEFAULT_SESSION_SEARCH = {
|
|
68
57
|
enabled: true,
|
|
69
58
|
maxFiles: 12,
|
|
@@ -76,8 +65,8 @@ const DEFAULT_MEMORY_MAINTENANCE = {
|
|
|
76
65
|
enabled: true,
|
|
77
66
|
minIdleMinutesBeforeLlmWork: 10,
|
|
78
67
|
sessionRefreshIntervalMinutes: 10,
|
|
79
|
-
|
|
80
|
-
|
|
68
|
+
checkpointIntervalMinutes: 20,
|
|
69
|
+
minMemoryAutoWriteConfidence: 0.85,
|
|
81
70
|
structuralMaintenanceIntervalHours: 6,
|
|
82
71
|
maxConcurrentChannels: 1,
|
|
83
72
|
failureBackoffMinutes: 30,
|
|
@@ -218,19 +207,6 @@ export class PipiclawSettingsManager {
|
|
|
218
207
|
...this.settings.sessionMemory,
|
|
219
208
|
};
|
|
220
209
|
}
|
|
221
|
-
getMemoryGrowthSettings() {
|
|
222
|
-
const settings = {
|
|
223
|
-
...DEFAULT_MEMORY_GROWTH,
|
|
224
|
-
...this.settings.memoryGrowth,
|
|
225
|
-
};
|
|
226
|
-
const configured = settings.minSkillAutoWriteConfidence;
|
|
227
|
-
return {
|
|
228
|
-
...settings,
|
|
229
|
-
minSkillAutoWriteConfidence: Number.isFinite(configured)
|
|
230
|
-
? Math.min(1, Math.max(MIN_SKILL_AUTO_WRITE_CONFIDENCE, configured))
|
|
231
|
-
: MIN_SKILL_AUTO_WRITE_CONFIDENCE,
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
210
|
getMemoryMaintenanceSettings() {
|
|
235
211
|
return {
|
|
236
212
|
...DEFAULT_MEMORY_MAINTENANCE,
|
|
@@ -64,6 +64,9 @@ export declare const STANDARD_TASK_SECTIONS: readonly [{
|
|
|
64
64
|
readonly label: "History";
|
|
65
65
|
readonly names: readonly ["History", "历史"];
|
|
66
66
|
}];
|
|
67
|
+
/** Recurring task files are working context, not an unbounded audit log. */
|
|
68
|
+
export declare const MAX_INLINE_TASK_HISTORY_ENTRIES = 8;
|
|
69
|
+
export declare const MAX_INLINE_TASK_HISTORY_CHARS: number;
|
|
67
70
|
/** Validate/normalize a task id (filename without `.md`), rejecting path traversal. */
|
|
68
71
|
export declare function normalizeTaskId(id: string): string;
|
|
69
72
|
/** The document body after the leading frontmatter block, or the whole content when there is none. */
|
|
@@ -123,6 +126,14 @@ export declare function normalizeTaskFields(fields: TaskDocumentFields): TaskDoc
|
|
|
123
126
|
export declare function renderTaskDocument(fields: TaskDocumentFields, rawBody: string): string;
|
|
124
127
|
/** Append one progress bullet to the standard Current Cycle section. */
|
|
125
128
|
export declare function appendCurrentCycleNote(content: string, note: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Upsert the completion evidence subsection inside Current Cycle.
|
|
131
|
+
*
|
|
132
|
+
* Evidence is part of the cycle log, not a new top-level section. This makes the next
|
|
133
|
+
* `startTaskCycle` fold it into the matching History entry and prevents repeated `done`
|
|
134
|
+
* attempts from appending duplicate evidence blocks.
|
|
135
|
+
*/
|
|
136
|
+
export declare function upsertCurrentCycleCompletionEvidence(content: string, evidenceLines: readonly string[]): string;
|
|
126
137
|
/**
|
|
127
138
|
* Close the visible current-cycle notes into History and open a fresh cycle.
|
|
128
139
|
* Periodic task cycles deliberately use this small, deterministic transformation
|
|
@@ -14,6 +14,12 @@ export const STANDARD_TASK_SECTIONS = [
|
|
|
14
14
|
{ label: "Current Cycle", names: ["Current Cycle", "当前周期"] },
|
|
15
15
|
{ label: "History", names: ["History", "历史"] },
|
|
16
16
|
];
|
|
17
|
+
/** Recurring task files are working context, not an unbounded audit log. */
|
|
18
|
+
export const MAX_INLINE_TASK_HISTORY_ENTRIES = 8;
|
|
19
|
+
export const MAX_INLINE_TASK_HISTORY_CHARS = 24 * 1024;
|
|
20
|
+
const MAX_INLINE_TASK_HISTORY_ENTRY_CHARS = 4 * 1024;
|
|
21
|
+
const HISTORY_OMISSION_NOTE = "- Older cycle details omitted from working context; use session_search with the task id or cycle id to inspect cold history.";
|
|
22
|
+
const HISTORY_TRUNCATION_NOTE = "- Entry truncated in working context; use session_search with the task id or cycle id to inspect the complete cold history.";
|
|
17
23
|
/** Validate/normalize a task id (filename without `.md`), rejecting path traversal. */
|
|
18
24
|
export function normalizeTaskId(id) {
|
|
19
25
|
const trimmed = id.trim();
|
|
@@ -271,6 +277,7 @@ export function appendCurrentCycleNote(content, note) {
|
|
|
271
277
|
continue;
|
|
272
278
|
sectionStart = index;
|
|
273
279
|
sectionLevel = match[1]?.length ?? 0;
|
|
280
|
+
break;
|
|
274
281
|
}
|
|
275
282
|
if (sectionStart === -1) {
|
|
276
283
|
throw new Error('Task body has no "Current Cycle" section; normalize the task skeleton first.');
|
|
@@ -289,6 +296,165 @@ export function appendCurrentCycleNote(content, note) {
|
|
|
289
296
|
lines.splice(insertAt, 0, `- ${trimmedNote}`);
|
|
290
297
|
return lines.join("\n");
|
|
291
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Upsert the completion evidence subsection inside Current Cycle.
|
|
301
|
+
*
|
|
302
|
+
* Evidence is part of the cycle log, not a new top-level section. This makes the next
|
|
303
|
+
* `startTaskCycle` fold it into the matching History entry and prevents repeated `done`
|
|
304
|
+
* attempts from appending duplicate evidence blocks.
|
|
305
|
+
*/
|
|
306
|
+
export function upsertCurrentCycleCompletionEvidence(content, evidenceLines) {
|
|
307
|
+
const lines = content.split("\n");
|
|
308
|
+
let currentStart = -1;
|
|
309
|
+
let currentLevel = 0;
|
|
310
|
+
for (let index = 0; index < lines.length; index++) {
|
|
311
|
+
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
312
|
+
if (!match || !matchesTaskSectionTitle(match[2] ?? "", ["Current Cycle", "当前周期"]))
|
|
313
|
+
continue;
|
|
314
|
+
currentStart = index;
|
|
315
|
+
currentLevel = match[1]?.length ?? 0;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
if (currentStart === -1 || currentLevel >= 6) {
|
|
319
|
+
// Legacy/non-standard one-shot tasks were historically completable without the
|
|
320
|
+
// canonical skeleton. Keep that compatibility, but upsert one bounded top-level
|
|
321
|
+
// block instead of returning to the old append-only behavior.
|
|
322
|
+
const stripped = stripLegacyCompletionEvidence(content).content.replace(/\n+$/, "");
|
|
323
|
+
return `${stripped}\n\n## Completion Evidence\n\n${evidenceLines.join("\n")}\n`;
|
|
324
|
+
}
|
|
325
|
+
let currentEnd = lines.length;
|
|
326
|
+
for (let index = currentStart + 1; index < lines.length; index++) {
|
|
327
|
+
const match = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
328
|
+
if (match && (match[1]?.length ?? 7) <= currentLevel) {
|
|
329
|
+
currentEnd = index;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
const evidenceLevel = currentLevel + 1;
|
|
334
|
+
let evidenceStart = -1;
|
|
335
|
+
let evidenceEnd = -1;
|
|
336
|
+
for (let index = currentStart + 1; index < currentEnd; index++) {
|
|
337
|
+
const match = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
338
|
+
if (!match)
|
|
339
|
+
continue;
|
|
340
|
+
const level = match[1]?.length ?? 7;
|
|
341
|
+
if (level === evidenceLevel && matchesTaskSectionTitle(match[2] ?? "", ["Completion Evidence"])) {
|
|
342
|
+
evidenceStart = index;
|
|
343
|
+
evidenceEnd = currentEnd;
|
|
344
|
+
for (let nested = index + 1; nested < currentEnd; nested++) {
|
|
345
|
+
const nestedHeading = /^(#{1,6})\s+/.exec(lines[nested] ?? "");
|
|
346
|
+
if (nestedHeading && (nestedHeading[1]?.length ?? 7) <= evidenceLevel) {
|
|
347
|
+
evidenceEnd = nested;
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
if (evidenceStart !== -1) {
|
|
355
|
+
lines.splice(evidenceStart, evidenceEnd - evidenceStart);
|
|
356
|
+
currentEnd -= evidenceEnd - evidenceStart;
|
|
357
|
+
}
|
|
358
|
+
while (currentEnd > currentStart + 1 && (lines[currentEnd - 1] ?? "").trim() === "")
|
|
359
|
+
currentEnd--;
|
|
360
|
+
const block = [`${"#".repeat(evidenceLevel)} Completion Evidence`, "", ...evidenceLines, ""];
|
|
361
|
+
lines.splice(currentEnd, 0, ...block);
|
|
362
|
+
return lines.join("\n");
|
|
363
|
+
}
|
|
364
|
+
function stripLegacyCompletionEvidence(content) {
|
|
365
|
+
const lines = content.split("\n");
|
|
366
|
+
const blocks = [];
|
|
367
|
+
for (let index = 0; index < lines.length;) {
|
|
368
|
+
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
369
|
+
if (!heading ||
|
|
370
|
+
(heading[1]?.length ?? 0) !== 2 ||
|
|
371
|
+
!matchesTaskSectionTitle(heading[2] ?? "", ["Completion Evidence"])) {
|
|
372
|
+
index++;
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
let end = lines.length;
|
|
376
|
+
for (let nested = index + 1; nested < lines.length; nested++) {
|
|
377
|
+
const nextHeading = /^(#{1,6})\s+/.exec(lines[nested] ?? "");
|
|
378
|
+
if (nextHeading && (nextHeading[1]?.length ?? 7) <= 2) {
|
|
379
|
+
end = nested;
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
blocks.push(lines.slice(index, end).join("\n").trim());
|
|
384
|
+
lines.splice(index, end - index);
|
|
385
|
+
while (index > 0 &&
|
|
386
|
+
index < lines.length &&
|
|
387
|
+
(lines[index - 1] ?? "").trim() === "" &&
|
|
388
|
+
(lines[index] ?? "").trim() === "") {
|
|
389
|
+
lines.splice(index, 1);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return { content: lines.join("\n"), blocks };
|
|
393
|
+
}
|
|
394
|
+
function clipHistoryEntry(entry) {
|
|
395
|
+
if (entry.length <= MAX_INLINE_TASK_HISTORY_ENTRY_CHARS)
|
|
396
|
+
return entry.trim();
|
|
397
|
+
const suffix = `\n${HISTORY_TRUNCATION_NOTE}`;
|
|
398
|
+
const limit = Math.max(0, MAX_INLINE_TASK_HISTORY_ENTRY_CHARS - suffix.length);
|
|
399
|
+
let clipped = entry.slice(0, limit);
|
|
400
|
+
const lastNewline = clipped.lastIndexOf("\n");
|
|
401
|
+
if (lastNewline > 0)
|
|
402
|
+
clipped = clipped.slice(0, lastNewline);
|
|
403
|
+
return `${clipped.trimEnd()}${suffix}`;
|
|
404
|
+
}
|
|
405
|
+
function compactTaskHistory(content, alreadyOmitted = false) {
|
|
406
|
+
const lines = content.split("\n");
|
|
407
|
+
let historyStart = -1;
|
|
408
|
+
let historyLevel = 0;
|
|
409
|
+
for (let index = 0; index < lines.length; index++) {
|
|
410
|
+
const heading = /^(#{1,6})\s+(.+?)\s*$/.exec(lines[index] ?? "");
|
|
411
|
+
if (heading && matchesTaskSectionTitle(heading[2] ?? "", ["History", "历史"])) {
|
|
412
|
+
historyStart = index;
|
|
413
|
+
historyLevel = heading[1]?.length ?? 0;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (historyStart === -1 || historyLevel >= 6)
|
|
418
|
+
return content;
|
|
419
|
+
let historyEnd = lines.length;
|
|
420
|
+
for (let index = historyStart + 1; index < lines.length; index++) {
|
|
421
|
+
const heading = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
422
|
+
if (heading && (heading[1]?.length ?? 7) <= historyLevel) {
|
|
423
|
+
historyEnd = index;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const entryStarts = [];
|
|
428
|
+
for (let index = historyStart + 1; index < historyEnd; index++) {
|
|
429
|
+
const heading = /^(#{1,6})\s+/.exec(lines[index] ?? "");
|
|
430
|
+
if ((heading?.[1]?.length ?? 0) === historyLevel + 1)
|
|
431
|
+
entryStarts.push(index);
|
|
432
|
+
}
|
|
433
|
+
if (entryStarts.length === 0)
|
|
434
|
+
return content;
|
|
435
|
+
const entries = entryStarts.map((start, index) => clipHistoryEntry(lines
|
|
436
|
+
.slice(start, entryStarts[index + 1] ?? historyEnd)
|
|
437
|
+
.join("\n")
|
|
438
|
+
.trim()));
|
|
439
|
+
const kept = [];
|
|
440
|
+
let chars = 0;
|
|
441
|
+
for (const entry of entries) {
|
|
442
|
+
const nextChars = chars + entry.length + (kept.length > 0 ? 2 : 0);
|
|
443
|
+
if (kept.length >= MAX_INLINE_TASK_HISTORY_ENTRIES || nextChars > MAX_INLINE_TASK_HISTORY_CHARS)
|
|
444
|
+
break;
|
|
445
|
+
kept.push(entry);
|
|
446
|
+
chars = nextChars;
|
|
447
|
+
}
|
|
448
|
+
const omitted = alreadyOmitted || kept.length < entries.length;
|
|
449
|
+
const replacement = [
|
|
450
|
+
"",
|
|
451
|
+
...kept.flatMap((entry, index) => (index === kept.length - 1 ? [entry] : [entry, ""])),
|
|
452
|
+
...(omitted ? ["", HISTORY_OMISSION_NOTE] : []),
|
|
453
|
+
"",
|
|
454
|
+
];
|
|
455
|
+
lines.splice(historyStart + 1, historyEnd - historyStart - 1, ...replacement);
|
|
456
|
+
return lines.join("\n");
|
|
457
|
+
}
|
|
292
458
|
/**
|
|
293
459
|
* Close the visible current-cycle notes into History and open a fresh cycle.
|
|
294
460
|
* Periodic task cycles deliberately use this small, deterministic transformation
|
|
@@ -299,7 +465,8 @@ export function startTaskCycle(content, cycleId) {
|
|
|
299
465
|
const normalizedCycleId = cycleId.trim();
|
|
300
466
|
if (!normalizedCycleId)
|
|
301
467
|
throw new Error("Cycle id must not be empty.");
|
|
302
|
-
const
|
|
468
|
+
const legacy = stripLegacyCompletionEvidence(content);
|
|
469
|
+
const lines = legacy.content.split("\n");
|
|
303
470
|
let currentStart = -1;
|
|
304
471
|
let currentLevel = 0;
|
|
305
472
|
let historyStart = -1;
|
|
@@ -328,10 +495,24 @@ export function startTaskCycle(content, cycleId) {
|
|
|
328
495
|
break;
|
|
329
496
|
}
|
|
330
497
|
}
|
|
331
|
-
|
|
498
|
+
let previous = lines
|
|
332
499
|
.slice(currentStart + 1, currentEnd)
|
|
333
500
|
.join("\n")
|
|
334
501
|
.trim();
|
|
502
|
+
const latestLegacyEvidence = legacy.blocks.at(-1);
|
|
503
|
+
if (latestLegacyEvidence && !/^(#{1,6})\s+Completion Evidence\b/im.test(previous)) {
|
|
504
|
+
previous = `${previous}\n\n${latestLegacyEvidence.replace(/^##\s+/, "### ")}`.trim();
|
|
505
|
+
}
|
|
506
|
+
// The archived cycle gets its own H3 entry under History. Demote subsections that
|
|
507
|
+
// were nested under the H2 Current Cycle so they remain children of that entry.
|
|
508
|
+
previous = previous
|
|
509
|
+
.split("\n")
|
|
510
|
+
.map((line) => {
|
|
511
|
+
const heading = /^(#{1,6})(\s+.*)$/.exec(line);
|
|
512
|
+
const level = heading?.[1]?.length ?? 0;
|
|
513
|
+
return heading && level > currentLevel && level < 6 ? `#${line}` : line;
|
|
514
|
+
})
|
|
515
|
+
.join("\n");
|
|
335
516
|
const previousHeading = (lines[currentStart] ?? "## Current Cycle").replace(/^#+\s*/, "").trim();
|
|
336
517
|
const replacement = [
|
|
337
518
|
`${"#".repeat(currentLevel)} Current Cycle (${normalizedCycleId})`,
|
|
@@ -347,7 +528,8 @@ export function startTaskCycle(content, cycleId) {
|
|
|
347
528
|
// A nested history heading would be unusual; inserting directly after the
|
|
348
529
|
// canonical History heading remains predictable and preserves all older notes.
|
|
349
530
|
lines.splice(shiftedHistoryStart + 1, 0, ...historyEntry);
|
|
350
|
-
|
|
531
|
+
const compacted = compactTaskHistory(lines.join("\n"), legacy.blocks.length > 1);
|
|
532
|
+
return resetTaskAcceptanceCheckboxes(compacted);
|
|
351
533
|
}
|
|
352
534
|
/**
|
|
353
535
|
* Uncheck every "- [x]" under DoD/Verification.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
|
-
declare const ALLOWED_SUB_AGENT_TOOLS: readonly ["read", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
2
|
+
declare const ALLOWED_SUB_AGENT_TOOLS: readonly ["read", "grep", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
3
3
|
declare const ALLOWED_CONTEXT_MODES: readonly ["isolated", "contextual"];
|
|
4
4
|
declare const ALLOWED_MEMORY_MODES: readonly ["none", "session", "relevant"];
|
|
5
5
|
declare const ALLOWED_THINKING_LEVELS: readonly ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
@@ -7,6 +7,42 @@ export type SubAgentToolName = (typeof ALLOWED_SUB_AGENT_TOOLS)[number];
|
|
|
7
7
|
export type SubAgentContextMode = (typeof ALLOWED_CONTEXT_MODES)[number];
|
|
8
8
|
export type SubAgentMemoryMode = (typeof ALLOWED_MEMORY_MODES)[number];
|
|
9
9
|
export type SubAgentThinkingLevel = (typeof ALLOWED_THINKING_LEVELS)[number];
|
|
10
|
+
/**
|
|
11
|
+
* Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
|
|
12
|
+
* (a human editing a config file has grounds to pick numbers); the invocation surface
|
|
13
|
+
* only offers these presets, because a model choosing `maxToolCalls` per delegation is
|
|
14
|
+
* guessing. `standard` is byte-identical to the DEFAULT_* values, so omitting `effort`
|
|
15
|
+
* leaves behavior unchanged.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SUB_AGENT_EFFORT_PRESETS: {
|
|
18
|
+
readonly quick: {
|
|
19
|
+
readonly maxTurns: 8;
|
|
20
|
+
readonly maxToolCalls: 16;
|
|
21
|
+
readonly maxWallTimeSec: 120;
|
|
22
|
+
readonly bashTimeoutSec: 60;
|
|
23
|
+
};
|
|
24
|
+
readonly standard: {
|
|
25
|
+
readonly maxTurns: 24;
|
|
26
|
+
readonly maxToolCalls: 48;
|
|
27
|
+
readonly maxWallTimeSec: 300;
|
|
28
|
+
readonly bashTimeoutSec: 120;
|
|
29
|
+
};
|
|
30
|
+
readonly deep: {
|
|
31
|
+
readonly maxTurns: 48;
|
|
32
|
+
readonly maxToolCalls: 96;
|
|
33
|
+
readonly maxWallTimeSec: 900;
|
|
34
|
+
readonly bashTimeoutSec: 180;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export type SubAgentEffort = keyof typeof SUB_AGENT_EFFORT_PRESETS;
|
|
38
|
+
/**
|
|
39
|
+
* The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
|
|
40
|
+
* encode only four meaningful states (`isolated` implies `memory: none`), so the calling
|
|
41
|
+
* surface collapses them into one enum. The dropped state — contextual with `memory: none`,
|
|
42
|
+
* i.e. paths-only injection — remains expressible in frontmatter.
|
|
43
|
+
*/
|
|
44
|
+
declare const ALLOWED_CONTEXT_CHOICES: readonly ["none", "session", "relevant"];
|
|
45
|
+
export type SubAgentContextChoice = (typeof ALLOWED_CONTEXT_CHOICES)[number];
|
|
10
46
|
export interface SubAgentConfig {
|
|
11
47
|
name: string;
|
|
12
48
|
description: string;
|
|
@@ -42,12 +78,10 @@ export interface SubAgentInvocationOverrides {
|
|
|
42
78
|
systemPrompt?: string;
|
|
43
79
|
tools?: string[];
|
|
44
80
|
model?: string;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
contextMode?: string;
|
|
50
|
-
memory?: string;
|
|
81
|
+
/** Named budget preset; wins over frontmatter numbers as a whole tuple, never field by field. */
|
|
82
|
+
effort?: string;
|
|
83
|
+
/** Collapsed `contextMode` + `memory`; see SubAgentContextChoice. */
|
|
84
|
+
context?: string;
|
|
51
85
|
paths?: string[];
|
|
52
86
|
thinkingLevel?: string;
|
|
53
87
|
/** Drives the thinkingLevel default: "verify" defaults on, everything else stays off. */
|