@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
|
@@ -4,7 +4,7 @@ import { join } from "path";
|
|
|
4
4
|
import { findExactModelReferenceMatch, formatModelReference } from "../models/utils.js";
|
|
5
5
|
import { SUB_AGENTS_DIR_NAME } from "../paths.js";
|
|
6
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
7
|
-
const ALLOWED_SUB_AGENT_TOOLS = ["read", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
7
|
+
const ALLOWED_SUB_AGENT_TOOLS = ["read", "grep", "bash", "edit", "write", "web_search", "web_fetch"];
|
|
8
8
|
const DEFAULT_SUB_AGENT_TOOLS = ["read", "bash"];
|
|
9
9
|
const DEFAULT_MAX_TURNS = 24;
|
|
10
10
|
const DEFAULT_MAX_TOOL_CALLS = 48;
|
|
@@ -15,6 +15,31 @@ const MAX_SUB_AGENT_SYSTEM_PROMPT_CHARS = 16000;
|
|
|
15
15
|
const ALLOWED_CONTEXT_MODES = ["isolated", "contextual"];
|
|
16
16
|
const ALLOWED_MEMORY_MODES = ["none", "session", "relevant"];
|
|
17
17
|
const ALLOWED_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
18
|
+
/**
|
|
19
|
+
* Execution budgets as a single named tuple. Frontmatter keeps the four numeric knobs
|
|
20
|
+
* (a human editing a config file has grounds to pick numbers); the invocation surface
|
|
21
|
+
* only offers these presets, because a model choosing `maxToolCalls` per delegation is
|
|
22
|
+
* guessing. `standard` is byte-identical to the DEFAULT_* values, so omitting `effort`
|
|
23
|
+
* leaves behavior unchanged.
|
|
24
|
+
*/
|
|
25
|
+
export const SUB_AGENT_EFFORT_PRESETS = {
|
|
26
|
+
quick: { maxTurns: 8, maxToolCalls: 16, maxWallTimeSec: 120, bashTimeoutSec: 60 },
|
|
27
|
+
standard: {
|
|
28
|
+
maxTurns: DEFAULT_MAX_TURNS,
|
|
29
|
+
maxToolCalls: DEFAULT_MAX_TOOL_CALLS,
|
|
30
|
+
maxWallTimeSec: DEFAULT_MAX_WALL_TIME_SEC,
|
|
31
|
+
bashTimeoutSec: DEFAULT_BASH_TIMEOUT_SEC,
|
|
32
|
+
},
|
|
33
|
+
deep: { maxTurns: 48, maxToolCalls: 96, maxWallTimeSec: 900, bashTimeoutSec: 180 },
|
|
34
|
+
};
|
|
35
|
+
const ALLOWED_EFFORTS = Object.keys(SUB_AGENT_EFFORT_PRESETS);
|
|
36
|
+
/**
|
|
37
|
+
* The invocation-side spelling of `contextMode` + `memory`. Those two frontmatter knobs
|
|
38
|
+
* encode only four meaningful states (`isolated` implies `memory: none`), so the calling
|
|
39
|
+
* surface collapses them into one enum. The dropped state — contextual with `memory: none`,
|
|
40
|
+
* i.e. paths-only injection — remains expressible in frontmatter.
|
|
41
|
+
*/
|
|
42
|
+
const ALLOWED_CONTEXT_CHOICES = ["none", "session", "relevant"];
|
|
18
43
|
/** verify is the last unattended gate before an attestation is trusted; give it real reasoning by default. */
|
|
19
44
|
const DEFAULT_VERIFY_THINKING_LEVEL = "medium";
|
|
20
45
|
const DEFAULT_WORK_THINKING_LEVEL = "off";
|
|
@@ -114,6 +139,31 @@ function parseThinkingLevel(raw) {
|
|
|
114
139
|
error: `Unknown thinkingLevel "${normalized}". Allowed values: ${ALLOWED_THINKING_LEVELS.join(", ")}`,
|
|
115
140
|
};
|
|
116
141
|
}
|
|
142
|
+
function parseEffort(raw) {
|
|
143
|
+
const normalized = readOptionalTrimmedString(raw);
|
|
144
|
+
if (!normalized) {
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
if (ALLOWED_EFFORTS.includes(normalized)) {
|
|
148
|
+
return { value: normalized };
|
|
149
|
+
}
|
|
150
|
+
return { error: `Unknown effort "${normalized}". Allowed values: ${ALLOWED_EFFORTS.join(", ")}` };
|
|
151
|
+
}
|
|
152
|
+
function parseContextChoice(raw) {
|
|
153
|
+
const normalized = readOptionalTrimmedString(raw);
|
|
154
|
+
if (!normalized) {
|
|
155
|
+
return {};
|
|
156
|
+
}
|
|
157
|
+
if (!ALLOWED_CONTEXT_CHOICES.includes(normalized)) {
|
|
158
|
+
return {
|
|
159
|
+
error: `Unknown context "${normalized}". Allowed values: ${ALLOWED_CONTEXT_CHOICES.join(", ")}`,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (normalized === "none") {
|
|
163
|
+
return { value: { contextMode: "isolated", memory: "none" } };
|
|
164
|
+
}
|
|
165
|
+
return { value: { contextMode: "contextual", memory: normalized } };
|
|
166
|
+
}
|
|
117
167
|
function parseMemoryMode(raw, contextMode) {
|
|
118
168
|
const normalized = readOptionalTrimmedString(raw);
|
|
119
169
|
if (!normalized) {
|
|
@@ -171,12 +221,6 @@ function parsePositiveInteger(raw, fallback) {
|
|
|
171
221
|
}
|
|
172
222
|
return { value: parsed };
|
|
173
223
|
}
|
|
174
|
-
function resolvePositiveOverride(value, fallback) {
|
|
175
|
-
if (!Number.isFinite(value) || value === undefined || value <= 0) {
|
|
176
|
-
return fallback;
|
|
177
|
-
}
|
|
178
|
-
return Math.floor(value);
|
|
179
|
-
}
|
|
180
224
|
function resolveModelReference(modelRef, availableModels) {
|
|
181
225
|
const { match, ambiguous } = findExactModelReferenceMatch(modelRef, availableModels);
|
|
182
226
|
if (match) {
|
|
@@ -346,20 +390,26 @@ subagentDefaultModelRef) {
|
|
|
346
390
|
model = resolved.model;
|
|
347
391
|
modelRef = formatModelReference(resolved.model);
|
|
348
392
|
}
|
|
349
|
-
const
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
393
|
+
const effortOverride = parseEffort(overrides.effort);
|
|
394
|
+
if (effortOverride.error) {
|
|
395
|
+
return { error: effortOverride.error };
|
|
396
|
+
}
|
|
397
|
+
// An explicit `effort` replaces the whole budget tuple rather than merging field by
|
|
398
|
+
// field, so a preset never produces a combination no preset describes.
|
|
399
|
+
const budget = effortOverride.value
|
|
400
|
+
? SUB_AGENT_EFFORT_PRESETS[effortOverride.value]
|
|
401
|
+
: {
|
|
402
|
+
maxTurns: baseConfig?.maxTurns ?? DEFAULT_MAX_TURNS,
|
|
403
|
+
maxToolCalls: baseConfig?.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS,
|
|
404
|
+
maxWallTimeSec: baseConfig?.maxWallTimeSec ?? DEFAULT_MAX_WALL_TIME_SEC,
|
|
405
|
+
bashTimeoutSec: baseConfig?.bashTimeoutSec ?? DEFAULT_BASH_TIMEOUT_SEC,
|
|
406
|
+
};
|
|
407
|
+
const contextOverride = parseContextChoice(overrides.context);
|
|
408
|
+
if (contextOverride.error) {
|
|
409
|
+
return { error: contextOverride.error };
|
|
361
410
|
}
|
|
362
|
-
const
|
|
411
|
+
const contextMode = contextOverride.value?.contextMode ?? baseConfig?.contextMode ?? "isolated";
|
|
412
|
+
const memory = contextOverride.value?.memory ?? baseConfig?.memory ?? (contextMode === "contextual" ? "relevant" : "none");
|
|
363
413
|
const pathsOverride = overrides.paths ? parseStringList(overrides.paths, "paths") : undefined;
|
|
364
414
|
if (pathsOverride?.error) {
|
|
365
415
|
return { error: pathsOverride.error };
|
|
@@ -391,10 +441,10 @@ subagentDefaultModelRef) {
|
|
|
391
441
|
tools: tools.tools,
|
|
392
442
|
model: model ?? currentModel,
|
|
393
443
|
modelRef: modelRef ?? formatModelReference(model ?? currentModel),
|
|
394
|
-
maxTurns,
|
|
395
|
-
maxToolCalls,
|
|
396
|
-
maxWallTimeSec,
|
|
397
|
-
bashTimeoutSec,
|
|
444
|
+
maxTurns: budget.maxTurns,
|
|
445
|
+
maxToolCalls: budget.maxToolCalls,
|
|
446
|
+
maxWallTimeSec: budget.maxWallTimeSec,
|
|
447
|
+
bashTimeoutSec: budget.bashTimeoutSec,
|
|
398
448
|
contextMode,
|
|
399
449
|
memory,
|
|
400
450
|
paths,
|
package/dist/subagents/tool.d.ts
CHANGED
|
@@ -16,17 +16,12 @@ declare const subagentSchema: Type.TObject<{
|
|
|
16
16
|
systemPrompt: Type.TOptional<Type.TString>;
|
|
17
17
|
tools: Type.TOptional<Type.TArray<Type.TString>>;
|
|
18
18
|
model: Type.TOptional<Type.TString>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
maxWallTimeSec: Type.TOptional<Type.TNumber>;
|
|
22
|
-
bashTimeoutSec: Type.TOptional<Type.TNumber>;
|
|
23
|
-
contextMode: Type.TOptional<Type.TUnion<[Type.TLiteral<"isolated">, Type.TLiteral<"contextual">]>>;
|
|
24
|
-
memory: Type.TOptional<Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"session">, Type.TLiteral<"relevant">]>>;
|
|
19
|
+
effort: Type.TOptional<Type.TUnion<[Type.TLiteral<"quick">, Type.TLiteral<"standard">, Type.TLiteral<"deep">]>>;
|
|
20
|
+
context: Type.TOptional<Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"session">, Type.TLiteral<"relevant">]>>;
|
|
25
21
|
paths: Type.TOptional<Type.TArray<Type.TString>>;
|
|
26
22
|
purpose: Type.TOptional<Type.TUnion<[Type.TLiteral<"work">, Type.TLiteral<"verify">]>>;
|
|
27
23
|
taskId: Type.TOptional<Type.TString>;
|
|
28
24
|
isolation: Type.TOptional<Type.TUnion<[Type.TLiteral<"shared">, Type.TLiteral<"worktree">]>>;
|
|
29
|
-
worktreePath: Type.TOptional<Type.TString>;
|
|
30
25
|
returns: Type.TOptional<Type.TUnion<[Type.TLiteral<"text">, Type.TLiteral<"artifact">]>>;
|
|
31
26
|
thinkingLevel: Type.TOptional<Type.TUnion<[Type.TLiteral<"off">, Type.TLiteral<"minimal">, Type.TLiteral<"low">, Type.TLiteral<"medium">, Type.TLiteral<"high">, Type.TLiteral<"xhigh">]>>;
|
|
32
27
|
}>;
|
package/dist/subagents/tool.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
3
|
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
4
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
@@ -27,15 +28,11 @@ const subagentSchema = Type.Object({
|
|
|
27
28
|
})),
|
|
28
29
|
tools: Type.Optional(Type.Array(Type.String(), { description: "Optional tool whitelist for the sub-agent" })),
|
|
29
30
|
model: Type.Optional(Type.String({ description: "Optional exact model reference. Defaults to the parent's current model." })),
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
maxWallTimeSec: Type.Optional(Type.Number({ description: "Optional wall time budget in seconds for this sub-agent" })),
|
|
33
|
-
bashTimeoutSec: Type.Optional(Type.Number({ description: "Optional default timeout in seconds for bash commands inside this sub-agent" })),
|
|
34
|
-
contextMode: Type.Optional(Type.Union([Type.Literal("isolated"), Type.Literal("contextual")], {
|
|
35
|
-
description: 'Optional context mode. "isolated" (default) runs with no injected context; "contextual" injects selected session and memory context.',
|
|
31
|
+
effort: Type.Optional(Type.Union([Type.Literal("quick"), Type.Literal("standard"), Type.Literal("deep")], {
|
|
32
|
+
description: 'Execution budget preset (turns, tool calls, wall time). "standard" is the default; "quick" for narrow lookups, "deep" for long analyses.',
|
|
36
33
|
})),
|
|
37
|
-
|
|
38
|
-
description: '
|
|
34
|
+
context: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("session"), Type.Literal("relevant")], {
|
|
35
|
+
description: 'What context to inject. "none" (default) runs fully isolated; "session" adds current session state; "relevant" adds session state plus recalled memory.',
|
|
39
36
|
})),
|
|
40
37
|
paths: Type.Optional(Type.Array(Type.String(), {
|
|
41
38
|
description: "Optional preferred file or directory paths for the sub-agent to focus on.",
|
|
@@ -45,11 +42,10 @@ const subagentSchema = Type.Object({
|
|
|
45
42
|
})),
|
|
46
43
|
taskId: Type.Optional(Type.String({ description: "Persistent task id, required when purpose=verify." })),
|
|
47
44
|
isolation: Type.Optional(Type.Union([Type.Literal("shared"), Type.Literal("worktree")], {
|
|
48
|
-
description: '"worktree" runs in
|
|
45
|
+
description: '"worktree" runs in the task\'s own git worktree, reusing the one recorded on the task or creating it on first use. Requires taskId.',
|
|
49
46
|
})),
|
|
50
|
-
worktreePath: Type.Optional(Type.String({ description: "Reuse an existing task-owned worktree; must be under channel tasks/worktrees/." })),
|
|
51
47
|
returns: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("artifact")], {
|
|
52
|
-
description: '
|
|
48
|
+
description: '"text" (default) returns the response directly; "artifact" makes the sub-agent write its primary output to a file and end with an ARTIFACT: <filename> marker. The full output is saved to disk either way.',
|
|
53
49
|
})),
|
|
54
50
|
thinkingLevel: Type.Optional(Type.Union([
|
|
55
51
|
Type.Literal("off"),
|
|
@@ -130,8 +126,6 @@ async function prepareRunContext(runId, params, options) {
|
|
|
130
126
|
const artifactDir = await prepareArtifactDir(options.channelDir, runId);
|
|
131
127
|
const isolation = params.isolation ?? "shared";
|
|
132
128
|
if (isolation === "shared") {
|
|
133
|
-
if (params.worktreePath)
|
|
134
|
-
throw new Error("worktreePath requires isolation=worktree.");
|
|
135
129
|
const workingDirectory = resolve(options.workingDirectory ?? process.cwd());
|
|
136
130
|
return { runId, purpose, taskId, isolation, workingDirectory, artifactDir };
|
|
137
131
|
}
|
|
@@ -142,15 +136,19 @@ async function prepareRunContext(runId, params, options) {
|
|
|
142
136
|
}
|
|
143
137
|
const baseDir = resolve(options.channelDir, "tasks", "worktrees");
|
|
144
138
|
await mkdir(baseDir, { recursive: true });
|
|
145
|
-
|
|
146
|
-
|
|
139
|
+
// The task ledger — not the caller — owns the worktree identity. Reusing what
|
|
140
|
+
// `control.worktree` already records is what keeps a second delegation on the same task
|
|
141
|
+
// from creating a rival worktree and orphaning the first one.
|
|
142
|
+
const recordedPath = ownedTask.fields.control.worktree?.path;
|
|
143
|
+
if (recordedPath && existsSync(recordedPath)) {
|
|
144
|
+
const existing = resolve(recordedPath);
|
|
147
145
|
const rel = relative(baseDir, existing);
|
|
148
146
|
if (!rel || rel.startsWith("..") || isAbsolute(rel)) {
|
|
149
|
-
throw new Error(`
|
|
147
|
+
throw new Error(`Task ${taskId} records a worktree outside ${baseDir}: ${existing}. Clear it with task_manage before delegating.`);
|
|
150
148
|
}
|
|
151
149
|
const check = await options.executor.exec(`git -C ${shellEscape(existing)} rev-parse --is-inside-work-tree`);
|
|
152
150
|
if (check.code !== 0 || check.stdout.trim() !== "true") {
|
|
153
|
-
throw new Error(`
|
|
151
|
+
throw new Error(`Task ${taskId} records a path that is not a usable git worktree: ${existing}. Clear it with task_manage before delegating.`);
|
|
154
152
|
}
|
|
155
153
|
const branchResult = await options.executor.exec(`git -C ${shellEscape(existing)} branch --show-current`);
|
|
156
154
|
const context = {
|
|
@@ -205,8 +203,8 @@ async function recordTaskWorktree(channelDir, taskId, context) {
|
|
|
205
203
|
await updateStoredTask(channelDir, taskId, (task) => {
|
|
206
204
|
if (!task.fields.control || !context.worktreePath)
|
|
207
205
|
return;
|
|
206
|
+
// The recorded worktree *is* the isolation fact; there is no separate flag to keep in sync.
|
|
208
207
|
task.fields.control = applyTaskControlPatch(task.fields.control, {
|
|
209
|
-
isolation: "worktree",
|
|
210
208
|
worktreePath: context.worktreePath,
|
|
211
209
|
worktreeBranch: context.worktreeBranch,
|
|
212
210
|
});
|
|
@@ -487,7 +485,7 @@ export function createSubAgentTool(options) {
|
|
|
487
485
|
return {
|
|
488
486
|
name: "subagent",
|
|
489
487
|
label: "subagent",
|
|
490
|
-
description: "Delegate a task to a sub-agent with an isolated context. Default path: pass an inline systemPrompt (plus optional tools/model) to define a temporary sub-agent — no configured agent is required. You may instead name a configured sub-agent via `agent`; workspaceDir/sub-agents/ may be empty on a given install, which does not block inline delegation. Sub-agents never receive the subagent tool, so they cannot create nested agents.",
|
|
488
|
+
description: "Delegate a task to a sub-agent with an isolated context. Default path: pass an inline systemPrompt (plus optional tools/model) to define a temporary sub-agent — no configured agent is required. You may instead name a configured sub-agent via `agent`; workspaceDir/sub-agents/ may be empty on a given install, which does not block inline delegation. Execution budgets come from `effort` presets and context injection from `context`; both have safe defaults, so state the task well and leave them alone unless you have a reason. Sub-agents never receive the subagent tool, so they cannot create nested agents.",
|
|
491
489
|
parameters: subagentSchema,
|
|
492
490
|
execute: async (_toolCallId, params, signal, onUpdate) => {
|
|
493
491
|
const availableModels = options.getAvailableModels();
|
package/dist/tasks/control.d.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
export type TaskPriority = "low" | "normal" | "high" | "critical";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Whether the task may touch systems outside the workspace. Only `external` carries machine
|
|
4
|
+
* semantics (it gates the approval chain); the former `read-only`/`workspace` split had no
|
|
5
|
+
* enforcement anywhere and is read back as `workspace`.
|
|
6
|
+
*/
|
|
7
|
+
export type TaskSideEffects = "workspace" | "external";
|
|
4
8
|
export type TaskVerificationMode = "evidence" | "independent";
|
|
5
9
|
export type TaskVerificationStatus = "pending" | "passed" | "failed";
|
|
6
|
-
|
|
10
|
+
/**
|
|
11
|
+
* How the last agent run on this task ended. Pure telemetry, written only by the runtime
|
|
12
|
+
* (attempt claim/finish and governor escalation) — never by a `task_manage` action or a
|
|
13
|
+
* `/tasks` command, so it cannot drift into a second state machine alongside `status`.
|
|
14
|
+
*/
|
|
15
|
+
export type TaskOutcome = "pending" | "running" | "progress" | "blocked" | "failed";
|
|
7
16
|
/** Who paused a task: a user via /tasks pause, or the deterministic governor (ex-`escalated`). */
|
|
8
17
|
export type TaskPausedBy = "user" | "governor";
|
|
9
18
|
export interface TaskBudget {
|
|
@@ -16,6 +25,8 @@ export interface TaskUsage {
|
|
|
16
25
|
attempts: number;
|
|
17
26
|
tokens: number;
|
|
18
27
|
costUsd: number;
|
|
28
|
+
/** False when at least one contributing model omitted pricing metadata. */
|
|
29
|
+
costKnown: boolean;
|
|
19
30
|
wallTimeMinutes: number;
|
|
20
31
|
}
|
|
21
32
|
export interface TaskVerification {
|
|
@@ -40,14 +51,16 @@ export interface TaskControl {
|
|
|
40
51
|
blockedReason?: string;
|
|
41
52
|
parent?: string;
|
|
42
53
|
dependsOn: string[];
|
|
43
|
-
isolation: TaskIsolation;
|
|
44
54
|
sideEffects: TaskSideEffects;
|
|
45
55
|
externalApproval: "not-required" | "required" | "granted";
|
|
46
56
|
approvalBy?: string;
|
|
47
57
|
approvedAt?: string;
|
|
48
58
|
approvalBodyHash?: string;
|
|
49
59
|
budget: TaskBudget;
|
|
60
|
+
/** Usage in the current recurring cycle (or the full one-shot task). */
|
|
50
61
|
usage: TaskUsage;
|
|
62
|
+
/** Non-resetting audit total; legacy controls seed it from their first parsed cycle usage. */
|
|
63
|
+
lifetimeUsage: TaskUsage;
|
|
51
64
|
verification: TaskVerification;
|
|
52
65
|
worktree?: TaskWorktree;
|
|
53
66
|
lastStartedAt?: string;
|
|
@@ -61,11 +74,9 @@ export interface TaskControlPatch {
|
|
|
61
74
|
priority?: TaskPriority;
|
|
62
75
|
deadline?: string;
|
|
63
76
|
nextAction?: string;
|
|
64
|
-
lastOutcome?: TaskOutcome;
|
|
65
77
|
blockedReason?: string;
|
|
66
78
|
parent?: string;
|
|
67
79
|
dependsOn?: string[];
|
|
68
|
-
isolation?: TaskIsolation;
|
|
69
80
|
sideEffects?: TaskSideEffects;
|
|
70
81
|
externalApproval?: "not-required" | "required" | "granted";
|
|
71
82
|
maxAttempts?: number;
|
package/dist/tasks/control.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { errorMessage } from "../shared/text-utils.js";
|
|
2
2
|
const PRIORITIES = ["low", "normal", "high", "critical"];
|
|
3
|
-
const
|
|
4
|
-
const SIDE_EFFECTS = ["read-only", "workspace", "external"];
|
|
3
|
+
const SIDE_EFFECTS = ["workspace", "external"];
|
|
5
4
|
const VERIFICATION_MODES = ["evidence", "independent"];
|
|
6
5
|
const VERIFICATION_STATUSES = ["pending", "passed", "failed"];
|
|
7
|
-
const OUTCOMES = ["pending", "running", "progress", "blocked", "failed"
|
|
6
|
+
const OUTCOMES = ["pending", "running", "progress", "blocked", "failed"];
|
|
8
7
|
const PAUSED_BY = ["user", "governor"];
|
|
9
8
|
const TASK_ID_PATTERN = /^[A-Za-z0-9._-]+$/;
|
|
10
9
|
function isRecord(value) {
|
|
@@ -24,6 +23,14 @@ function finiteNonNegative(value, fallback = 0) {
|
|
|
24
23
|
}
|
|
25
24
|
return value;
|
|
26
25
|
}
|
|
26
|
+
function parseTaskUsage(value) {
|
|
27
|
+
const attempts = Math.floor(finiteNonNegative(value.attempts));
|
|
28
|
+
const tokens = Math.floor(finiteNonNegative(value.tokens));
|
|
29
|
+
const costUsd = finiteNonNegative(value.costUsd);
|
|
30
|
+
const wallTimeMinutes = finiteNonNegative(value.wallTimeMinutes);
|
|
31
|
+
const costKnown = typeof value.costKnown === "boolean" ? value.costKnown : costUsd > 0 || (tokens === 0 && wallTimeMinutes === 0);
|
|
32
|
+
return { attempts, tokens, costUsd, costKnown, wallTimeMinutes };
|
|
33
|
+
}
|
|
27
34
|
function optionalPositive(value) {
|
|
28
35
|
if (value === undefined)
|
|
29
36
|
return undefined;
|
|
@@ -40,6 +47,26 @@ function enumValue(value, values, fallback) {
|
|
|
40
47
|
}
|
|
41
48
|
return value;
|
|
42
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Values retired from an enum are read back as their canonical replacement rather than failing
|
|
52
|
+
* the parse, so task files written by an older build stay readable; the next write normalizes
|
|
53
|
+
* them on disk and no migration script is needed. `control.isolation` was dropped outright —
|
|
54
|
+
* unknown keys are simply ignored here.
|
|
55
|
+
*/
|
|
56
|
+
function canonicalEnumValue(value) {
|
|
57
|
+
switch (value) {
|
|
58
|
+
// The read-only/workspace split never gated anything; only `external` has semantics.
|
|
59
|
+
case "read-only":
|
|
60
|
+
return "workspace";
|
|
61
|
+
// Outcomes once written by `task_manage` actions; the runtime now owns this field and
|
|
62
|
+
// records only how the last run ended.
|
|
63
|
+
case "verified":
|
|
64
|
+
case "skipped":
|
|
65
|
+
return "progress";
|
|
66
|
+
default:
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
43
70
|
function taskIds(value) {
|
|
44
71
|
if (value === undefined)
|
|
45
72
|
return [];
|
|
@@ -63,11 +90,11 @@ export function createDefaultTaskControl(mode = "independent") {
|
|
|
63
90
|
priority: "normal",
|
|
64
91
|
lastOutcome: "pending",
|
|
65
92
|
dependsOn: [],
|
|
66
|
-
isolation: "shared",
|
|
67
93
|
sideEffects: "workspace",
|
|
68
94
|
externalApproval: "not-required",
|
|
69
95
|
budget: { maxAttempts: 12 },
|
|
70
|
-
usage: { attempts: 0, tokens: 0, costUsd: 0, wallTimeMinutes: 0 },
|
|
96
|
+
usage: { attempts: 0, tokens: 0, costUsd: 0, costKnown: true, wallTimeMinutes: 0 },
|
|
97
|
+
lifetimeUsage: { attempts: 0, tokens: 0, costUsd: 0, costKnown: true, wallTimeMinutes: 0 },
|
|
71
98
|
verification: { mode, status: "pending" },
|
|
72
99
|
};
|
|
73
100
|
}
|
|
@@ -84,6 +111,8 @@ export function parseTaskControl(raw) {
|
|
|
84
111
|
}
|
|
85
112
|
const budget = isRecord(value.budget) ? value.budget : {};
|
|
86
113
|
const usage = isRecord(value.usage) ? value.usage : {};
|
|
114
|
+
const parsedUsage = parseTaskUsage(usage);
|
|
115
|
+
const lifetimeUsage = isRecord(value.lifetimeUsage) ? parseTaskUsage(value.lifetimeUsage) : { ...parsedUsage };
|
|
87
116
|
const verification = isRecord(value.verification) ? value.verification : {};
|
|
88
117
|
const worktree = isRecord(value.worktree) ? value.worktree : undefined;
|
|
89
118
|
const maxAttempts = optionalPositive(budget.maxAttempts);
|
|
@@ -96,7 +125,7 @@ export function parseTaskControl(raw) {
|
|
|
96
125
|
}
|
|
97
126
|
const parent = optionalString(value.parent);
|
|
98
127
|
validateTaskId(parent, "control.parent");
|
|
99
|
-
const sideEffects = enumValue(value.sideEffects, SIDE_EFFECTS, "workspace");
|
|
128
|
+
const sideEffects = enumValue(canonicalEnumValue(value.sideEffects), SIDE_EFFECTS, "workspace");
|
|
100
129
|
const externalApproval = enumValue(value.externalApproval, ["not-required", "required", "granted"], "not-required");
|
|
101
130
|
const approvalBy = optionalString(value.approvalBy);
|
|
102
131
|
const approvedAt = optionalString(value.approvedAt);
|
|
@@ -118,11 +147,10 @@ export function parseTaskControl(raw) {
|
|
|
118
147
|
priority: enumValue(value.priority, PRIORITIES, "normal"),
|
|
119
148
|
deadline,
|
|
120
149
|
nextAction: optionalString(value.nextAction),
|
|
121
|
-
lastOutcome: enumValue(value.lastOutcome, OUTCOMES, "pending"),
|
|
150
|
+
lastOutcome: enumValue(canonicalEnumValue(value.lastOutcome), OUTCOMES, "pending"),
|
|
122
151
|
blockedReason: optionalString(value.blockedReason),
|
|
123
152
|
parent,
|
|
124
153
|
dependsOn: taskIds(value.dependsOn),
|
|
125
|
-
isolation: enumValue(value.isolation, ISOLATIONS, "shared"),
|
|
126
154
|
sideEffects,
|
|
127
155
|
externalApproval,
|
|
128
156
|
approvalBy,
|
|
@@ -134,12 +162,8 @@ export function parseTaskControl(raw) {
|
|
|
134
162
|
maxCostUsd: optionalPositive(budget.maxCostUsd),
|
|
135
163
|
maxWallTimeMinutes: optionalPositive(budget.maxWallTimeMinutes),
|
|
136
164
|
},
|
|
137
|
-
usage:
|
|
138
|
-
|
|
139
|
-
tokens: Math.floor(finiteNonNegative(usage.tokens)),
|
|
140
|
-
costUsd: finiteNonNegative(usage.costUsd),
|
|
141
|
-
wallTimeMinutes: finiteNonNegative(usage.wallTimeMinutes),
|
|
142
|
-
},
|
|
165
|
+
usage: parsedUsage,
|
|
166
|
+
lifetimeUsage,
|
|
143
167
|
verification: {
|
|
144
168
|
mode: enumValue(verification.mode, VERIFICATION_MODES, "independent"),
|
|
145
169
|
status: enumValue(verification.status, VERIFICATION_STATUSES, "pending"),
|
|
@@ -176,7 +200,7 @@ export function resetTaskControlForCycle(control, cycleId) {
|
|
|
176
200
|
approvalBy: undefined,
|
|
177
201
|
approvedAt: undefined,
|
|
178
202
|
approvalBodyHash: undefined,
|
|
179
|
-
usage: { attempts: 0, tokens: 0, costUsd: 0, wallTimeMinutes: 0 },
|
|
203
|
+
usage: { attempts: 0, tokens: 0, costUsd: 0, costKnown: true, wallTimeMinutes: 0 },
|
|
180
204
|
verification: { mode: control.verification.mode, status: "pending" },
|
|
181
205
|
worktree: undefined,
|
|
182
206
|
lastStartedAt: undefined,
|
|
@@ -208,8 +232,6 @@ export function applyTaskControlPatch(control, patch) {
|
|
|
208
232
|
}
|
|
209
233
|
next.deadline = patchOptionalString(next.deadline, patch.deadline);
|
|
210
234
|
next.nextAction = patchOptionalString(next.nextAction, patch.nextAction);
|
|
211
|
-
if (patch.lastOutcome !== undefined)
|
|
212
|
-
next.lastOutcome = patch.lastOutcome;
|
|
213
235
|
next.blockedReason = patchOptionalString(next.blockedReason, patch.blockedReason);
|
|
214
236
|
next.parent = patchOptionalString(next.parent, patch.parent);
|
|
215
237
|
validateTaskId(next.parent, "parent");
|
|
@@ -218,8 +240,6 @@ export function applyTaskControlPatch(control, patch) {
|
|
|
218
240
|
validateTaskId(dependency.trim(), "dependsOn");
|
|
219
241
|
next.dependsOn = taskIds(patch.dependsOn);
|
|
220
242
|
}
|
|
221
|
-
if (patch.isolation !== undefined)
|
|
222
|
-
next.isolation = patch.isolation;
|
|
223
243
|
if (patch.sideEffects !== undefined)
|
|
224
244
|
next.sideEffects = patch.sideEffects;
|
|
225
245
|
if (patch.externalApproval !== undefined)
|
|
@@ -278,6 +298,9 @@ export function taskBudgetViolation(control, nowMs) {
|
|
|
278
298
|
if (control.budget.maxCostUsd !== undefined && control.usage.costUsd >= control.budget.maxCostUsd) {
|
|
279
299
|
return `cost budget exhausted ($${control.usage.costUsd.toFixed(4)}/$${control.budget.maxCostUsd.toFixed(4)})`;
|
|
280
300
|
}
|
|
301
|
+
if (control.budget.maxCostUsd !== undefined && !control.usage.costKnown) {
|
|
302
|
+
return "cost budget unavailable because at least one run model has no pricing; configure model pricing or replace maxCostUsd with maxTokens";
|
|
303
|
+
}
|
|
281
304
|
if (control.budget.maxWallTimeMinutes !== undefined &&
|
|
282
305
|
control.usage.wallTimeMinutes >= control.budget.maxWallTimeMinutes) {
|
|
283
306
|
return `wall-time budget exhausted (${control.usage.wallTimeMinutes.toFixed(1)}/${control.budget.maxWallTimeMinutes}m)`;
|
package/dist/tasks/store.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare function releaseTaskAttemptClaim(channelDir: string, id: string,
|
|
|
28
28
|
export declare function finishTaskAttempt(channelDir: string, id: string, result: {
|
|
29
29
|
tokens: number;
|
|
30
30
|
costUsd: number;
|
|
31
|
+
costKnown: boolean;
|
|
31
32
|
wallTimeMinutes: number;
|
|
32
33
|
failed: boolean;
|
|
33
34
|
silent?: boolean;
|
package/dist/tasks/store.js
CHANGED
|
@@ -69,6 +69,7 @@ export async function claimTaskAttempt(channelDir, id, now) {
|
|
|
69
69
|
previousLastStartedAt: task.fields.control.lastStartedAt,
|
|
70
70
|
};
|
|
71
71
|
task.fields.control.usage.attempts++;
|
|
72
|
+
task.fields.control.lifetimeUsage.attempts++;
|
|
72
73
|
task.fields.control.lastStartedAt = now.toISOString();
|
|
73
74
|
task.fields.control.lastOutcome = "running";
|
|
74
75
|
});
|
|
@@ -82,6 +83,7 @@ export async function releaseTaskAttemptClaim(channelDir, id, claim, startedAt)
|
|
|
82
83
|
if (!control || control.lastStartedAt !== startedAt.toISOString())
|
|
83
84
|
return;
|
|
84
85
|
control.usage.attempts = Math.max(0, control.usage.attempts - 1);
|
|
86
|
+
control.lifetimeUsage.attempts = Math.max(0, control.lifetimeUsage.attempts - 1);
|
|
85
87
|
control.lastStartedAt = claim.previousLastStartedAt;
|
|
86
88
|
control.lastOutcome = claim.previousLastOutcome;
|
|
87
89
|
control.blockedReason = claim.previousBlockedReason;
|
|
@@ -94,13 +96,19 @@ export async function finishTaskAttempt(channelDir, id, result) {
|
|
|
94
96
|
return;
|
|
95
97
|
control.usage.tokens += Math.max(0, Math.floor(result.tokens));
|
|
96
98
|
control.usage.costUsd += Math.max(0, result.costUsd);
|
|
99
|
+
control.usage.costKnown &&= result.costKnown;
|
|
97
100
|
control.usage.wallTimeMinutes += Math.max(0, result.wallTimeMinutes);
|
|
101
|
+
control.lifetimeUsage.tokens += Math.max(0, Math.floor(result.tokens));
|
|
102
|
+
control.lifetimeUsage.costUsd += Math.max(0, result.costUsd);
|
|
103
|
+
control.lifetimeUsage.costKnown &&= result.costKnown;
|
|
104
|
+
control.lifetimeUsage.wallTimeMinutes += Math.max(0, result.wallTimeMinutes);
|
|
98
105
|
control.lastFinishedAt = result.finishedAt.toISOString();
|
|
99
106
|
if (result.silent) {
|
|
100
107
|
// The driver claimed before dispatch to prevent concurrent work. A silent
|
|
101
108
|
// turn performed no task advancement, so retain its cost audit but not its
|
|
102
109
|
// attempt charge.
|
|
103
110
|
control.usage.attempts = Math.max(0, control.usage.attempts - 1);
|
|
111
|
+
control.lifetimeUsage.attempts = Math.max(0, control.lifetimeUsage.attempts - 1);
|
|
104
112
|
if (control.lastOutcome === "running") {
|
|
105
113
|
control.lastOutcome = "pending";
|
|
106
114
|
control.blockedReason = undefined;
|
|
@@ -21,7 +21,7 @@ export declare const SETTABLE_TASK_STATUSES: readonly ["active", "waiting", "pau
|
|
|
21
21
|
export type SettableTaskStatus = (typeof SETTABLE_TASK_STATUSES)[number];
|
|
22
22
|
/** Statuses the driver never dispatches. */
|
|
23
23
|
export declare const TERMINAL_TASK_STATUSES: Set<string>;
|
|
24
|
-
export type TaskLifecycleAction = "create" | "progress" | "candidate" | "verify" | "done" | "cancel" | "set" | "pause" | "resume" | "run";
|
|
24
|
+
export type TaskLifecycleAction = "create" | "progress" | "candidate" | "verify" | "done" | "skip" | "cancel" | "set" | "pause" | "resume" | "run";
|
|
25
25
|
/**
|
|
26
26
|
* Map a stored (possibly legacy) status string to a canonical status.
|
|
27
27
|
* Legacy files are read losslessly and written back canonical on the next write;
|
|
@@ -26,6 +26,7 @@ const TRANSITIONS = {
|
|
|
26
26
|
candidate: { from: ["active", "waiting"], to: "verifying" },
|
|
27
27
|
verify: { from: ["verifying"], to: "verifying" },
|
|
28
28
|
done: { from: ["active", "waiting", "verifying"], to: "done" },
|
|
29
|
+
skip: { from: ["active", "waiting", "verifying"], to: "done" },
|
|
29
30
|
cancel: { from: ["active", "waiting", "verifying", "paused"], to: "cancelled" },
|
|
30
31
|
set: { from: ["active", "waiting", "verifying", "paused", "done"], to: "caller" },
|
|
31
32
|
pause: { from: ["active", "waiting", "verifying"], to: "paused" },
|
package/dist/tools/registry.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hasKnownModelPricing } from "../models/utils.js";
|
|
1
2
|
import { createBashTool } from "./bash.js";
|
|
2
3
|
import { createEditTool } from "./edit.js";
|
|
3
4
|
import { createEventManageTool } from "./event-manage.js";
|
|
@@ -153,6 +154,7 @@ export const TOOL_REGISTRY = [
|
|
|
153
154
|
channelDir: ctx.channelDir,
|
|
154
155
|
channelId: ctx.channelId,
|
|
155
156
|
workingDirectory: ctx.securityContext.cwd,
|
|
157
|
+
costTrackingAvailable: hasKnownModelPricing(req(ctx.getCurrentModel, "getCurrentModel")()),
|
|
156
158
|
}),
|
|
157
159
|
},
|
|
158
160
|
{
|
|
@@ -4,10 +4,11 @@ import { join } from "node:path";
|
|
|
4
4
|
import { writeFileAtomically } from "../../shared/atomic-file.js";
|
|
5
5
|
import { normalizeTaskId, uncheckedTaskAcceptanceItems } from "../../shared/task-ledger.js";
|
|
6
6
|
import { RecoverableToolError } from "../tool-details.js";
|
|
7
|
-
import { renderTaskFile, renderTaskSkeleton, tasksDir, validateTaskRelations } from "./shared.js";
|
|
7
|
+
import { assertCostBudgetAvailable, renderTaskFile, renderTaskSkeleton, tasksDir, validateTaskRelations, } from "./shared.js";
|
|
8
8
|
export async function createTask(options, request) {
|
|
9
9
|
if (!request.id)
|
|
10
10
|
throw new RecoverableToolError('action "create" requires an id.');
|
|
11
|
+
assertCostBudgetAvailable(options, request);
|
|
11
12
|
const id = normalizeTaskId(request.id);
|
|
12
13
|
const dir = tasksDir(options);
|
|
13
14
|
const taskPath = join(dir, `${id}.md`);
|
|
@@ -2,5 +2,12 @@ import type { TaskManageRequest, TaskManageResult, TaskManageToolOptions } from
|
|
|
2
2
|
export declare function setTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
3
3
|
export declare function progressTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
4
4
|
export declare function doneTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
5
|
+
/**
|
|
6
|
+
* Close one recurring occurrence without pretending its DoD was completed.
|
|
7
|
+
*
|
|
8
|
+
* This is the stateful counterpart of a silent/deduplicated wake: merely returning
|
|
9
|
+
* `[SILENT]` would leave the runtime-opened cycle active with no wake and cause retries.
|
|
10
|
+
*/
|
|
11
|
+
export declare function skipTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
5
12
|
export declare function cancelTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
|
|
6
13
|
export declare function listTasks(options: TaskManageToolOptions): Promise<TaskManageResult>;
|