@code-yeongyu/senpi 2026.8.26 → 2026.8.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +55 -0
- package/README.md +3 -3
- package/dist/cli/args.d.ts +3 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +14 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +10 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +67 -29
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/credential-pool/classify.d.ts +42 -0
- package/dist/core/credential-pool/classify.d.ts.map +1 -0
- package/dist/core/credential-pool/classify.js +75 -0
- package/dist/core/credential-pool/classify.js.map +1 -0
- package/dist/core/credential-pool/env-slots.d.ts +22 -0
- package/dist/core/credential-pool/env-slots.d.ts.map +1 -0
- package/dist/core/credential-pool/env-slots.js +37 -0
- package/dist/core/credential-pool/env-slots.js.map +1 -0
- package/dist/core/credential-pool/failover.d.ts +54 -0
- package/dist/core/credential-pool/failover.d.ts.map +1 -0
- package/dist/core/credential-pool/failover.js +106 -0
- package/dist/core/credential-pool/failover.js.map +1 -0
- package/dist/core/credential-pool/rotation-stream.d.ts +43 -0
- package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -0
- package/dist/core/credential-pool/rotation-stream.js +96 -0
- package/dist/core/credential-pool/rotation-stream.js.map +1 -0
- package/dist/core/credential-pool/state-store.d.ts +89 -0
- package/dist/core/credential-pool/state-store.d.ts.map +1 -0
- package/dist/core/credential-pool/state-store.js +166 -0
- package/dist/core/credential-pool/state-store.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +67 -0
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.d.ts +1 -1
- package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.js +1 -0
- package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/index.js +14 -22
- package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation-recovery.d.ts +1 -0
- package/dist/core/extensions/builtin/goal/continuation-recovery.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation-recovery.js +2 -0
- package/dist/core/extensions/builtin/goal/continuation-recovery.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts +8 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js +15 -0
- package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/direct-input-lifecycle.js +2 -2
- package/dist/core/extensions/builtin/goal/direct-input-lifecycle.js.map +1 -1
- package/dist/core/extensions/builtin/goal/format.d.ts +6 -1
- package/dist/core/extensions/builtin/goal/format.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/format.js +6 -0
- package/dist/core/extensions/builtin/goal/format.js.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js +5 -2
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +31 -7
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/persistence.js +2 -0
- package/dist/core/extensions/builtin/goal/persistence.js.map +1 -1
- package/dist/core/extensions/builtin/goal/renderers.d.ts +14 -0
- package/dist/core/extensions/builtin/goal/renderers.d.ts.map +1 -0
- package/dist/core/extensions/builtin/goal/renderers.js +153 -0
- package/dist/core/extensions/builtin/goal/renderers.js.map +1 -0
- package/dist/core/extensions/builtin/goal/store.d.ts +6 -2
- package/dist/core/extensions/builtin/goal/store.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/store.js +8 -2
- package/dist/core/extensions/builtin/goal/store.js.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.js +16 -6
- package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
- package/dist/core/extensions/builtin/goal/types.d.ts +1 -0
- package/dist/core/extensions/builtin/goal/types.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/types.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/index.js +1 -1
- package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.d.ts +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.js +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.js.map +1 -1
- package/dist/core/hidden-stdout-log.d.ts +10 -0
- package/dist/core/hidden-stdout-log.d.ts.map +1 -1
- package/dist/core/hidden-stdout-log.js +36 -5
- package/dist/core/hidden-stdout-log.js.map +1 -1
- package/dist/core/model-config-schema.d.ts +85 -12
- package/dist/core/model-config-schema.d.ts.map +1 -1
- package/dist/core/model-config-schema.js +25 -0
- package/dist/core/model-config-schema.js.map +1 -1
- package/dist/core/model-runtime.d.ts +34 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +98 -5
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +2 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +32 -7
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +26 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/index.d.ts +1 -0
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -0
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution-fallback.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution-fallback.js +82 -1
- package/dist/modes/interactive/components/tool-execution-fallback.js.map +1 -1
- package/dist/modes/interactive/interactive-host-runtime.d.ts +29 -0
- package/dist/modes/interactive/interactive-host-runtime.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-host-runtime.js +244 -0
- package/dist/modes/interactive/interactive-host-runtime.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +46 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +7 -1
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts +41 -0
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -0
- package/dist/modes/rpc/host-ensure.js +245 -0
- package/dist/modes/rpc/host-ensure.js.map +1 -0
- package/dist/modes/rpc/host-lifecycle.d.ts +57 -0
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -0
- package/dist/modes/rpc/host-lifecycle.js +491 -0
- package/dist/modes/rpc/host-lifecycle.js.map +1 -0
- package/dist/modes/rpc/host-watchdog.d.ts +33 -0
- package/dist/modes/rpc/host-watchdog.d.ts.map +1 -0
- package/dist/modes/rpc/host-watchdog.js +142 -0
- package/dist/modes/rpc/host-watchdog.js.map +1 -0
- package/dist/modes/rpc/multi-session-host.d.ts +7 -1
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +206 -32
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +25 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +83 -10
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +12 -2
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +13 -2
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +65 -25
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/docs/rpc.md +53 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +30 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-indirect-eval.js +711 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +10 -10
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-eval-result.ts +9 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +6 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js +46 -14
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts +11 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js +30 -16
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.d.ts +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.js +75 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts +45 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js +81 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.d.ts +31 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.js +65 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +37 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +32 -6
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +6 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +75 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +75 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +5 -5
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts +5 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +90 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
+
import type { Theme } from "../../../../modes/interactive/theme/theme.ts";
|
|
3
|
+
import type { ToolRenderResultOptions } from "../../types.ts";
|
|
4
|
+
interface ResultLike {
|
|
5
|
+
content: ReadonlyArray<{
|
|
6
|
+
type: string;
|
|
7
|
+
text?: string;
|
|
8
|
+
}>;
|
|
9
|
+
details?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare function renderGoalToolCall(toolName: string, args: unknown, theme: Theme): Text;
|
|
12
|
+
export declare function renderGoalToolResult(result: ResultLike, options: ToolRenderResultOptions, theme: Theme): Text;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/renderers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,KAAK,EAAE,KAAK,EAAc,MAAM,8CAA8C,CAAC;AACtF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAS9D,UAAU,UAAU;IACnB,OAAO,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAgBtF;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,uBAAuB,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAY7G"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
+
import { formatGoalElapsedSeconds, formatTokensCompact } from "./format.js";
|
|
3
|
+
import { GOAL_STATUS_VALUES, isRecord } from "./types.js";
|
|
4
|
+
const OBJECTIVE_PREVIEW_WIDTH = 120;
|
|
5
|
+
const COLLAPSED_OBJECTIVE_LINES = 2;
|
|
6
|
+
const CALL_OBJECTIVE_BUDGET = 80;
|
|
7
|
+
const CALL_REASON_BUDGET = 60;
|
|
8
|
+
export function renderGoalToolCall(toolName, args, theme) {
|
|
9
|
+
const title = theme.fg("toolTitle", theme.bold(toolName));
|
|
10
|
+
const params = isRecord(args) ? args : {};
|
|
11
|
+
if (toolName === "create_goal" && typeof params.objective === "string") {
|
|
12
|
+
const preview = objectiveCallPreview(params.objective);
|
|
13
|
+
return new Text(preview === "" ? title : `${title} ${theme.fg("muted", preview)}`, 0, 0);
|
|
14
|
+
}
|
|
15
|
+
if (toolName === "update_goal" && typeof params.status === "string") {
|
|
16
|
+
const statusColor = params.status === "complete" ? "success" : "error";
|
|
17
|
+
let line = `${title} ${theme.fg("muted", "→")} ${theme.fg(statusColor, params.status)}`;
|
|
18
|
+
if (typeof params.reason === "string" && params.reason.trim().length > 0) {
|
|
19
|
+
line += ` ${theme.fg("muted", `— ${shorten(params.reason.trim(), CALL_REASON_BUDGET)}`)}`;
|
|
20
|
+
}
|
|
21
|
+
return new Text(line, 0, 0);
|
|
22
|
+
}
|
|
23
|
+
return new Text(title, 0, 0);
|
|
24
|
+
}
|
|
25
|
+
export function renderGoalToolResult(result, options, theme) {
|
|
26
|
+
const text = result.content.find((block) => block.type === "text")?.text ?? "";
|
|
27
|
+
const details = resolveRenderDetails(result.details, text);
|
|
28
|
+
if (details === undefined)
|
|
29
|
+
return new Text(theme.fg("toolOutput", text), 0, 0);
|
|
30
|
+
if (details.goal === null) {
|
|
31
|
+
const lines = [theme.fg("dim", "No active goal is set.")];
|
|
32
|
+
appendNotice(lines, details.notice, theme);
|
|
33
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
34
|
+
}
|
|
35
|
+
const lines = goalWidgetLines(details.goal, options.expanded, theme);
|
|
36
|
+
appendNotice(lines, details.notice, theme);
|
|
37
|
+
return new Text(lines.join("\n"), 0, 0);
|
|
38
|
+
}
|
|
39
|
+
function goalWidgetLines(goal, expanded, theme) {
|
|
40
|
+
const status = theme.fg(statusColor(goal.status), theme.bold(`${statusGlyph(goal.status)} ${goal.status}`));
|
|
41
|
+
const usage = ` • ${formatTokensCompact(goal.tokensUsed)} tokens • ${formatGoalElapsedSeconds(goal.timeUsedSeconds)}`;
|
|
42
|
+
const lines = [`${status}${theme.fg("muted", usage)}`];
|
|
43
|
+
const objectiveLines = goal.objective
|
|
44
|
+
.split("\n")
|
|
45
|
+
.map((line) => line.trim())
|
|
46
|
+
.filter((line) => line.length > 0);
|
|
47
|
+
if (expanded) {
|
|
48
|
+
for (const line of objectiveLines)
|
|
49
|
+
lines.push(theme.fg("toolOutput", ` ${line}`));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
for (const line of objectiveLines.slice(0, COLLAPSED_OBJECTIVE_LINES)) {
|
|
53
|
+
lines.push(theme.fg("toolOutput", ` ${shorten(line, OBJECTIVE_PREVIEW_WIDTH)}`));
|
|
54
|
+
}
|
|
55
|
+
const hidden = objectiveLines.length - COLLAPSED_OBJECTIVE_LINES;
|
|
56
|
+
if (hidden > 0)
|
|
57
|
+
lines.push(theme.fg("dim", ` … +${hidden} more lines`));
|
|
58
|
+
}
|
|
59
|
+
if (goal.blockedReason !== undefined && goal.blockedReason.length > 0) {
|
|
60
|
+
lines.push(theme.fg("warning", ` ⚠ ${goal.blockedReason}`));
|
|
61
|
+
}
|
|
62
|
+
if (expanded) {
|
|
63
|
+
const created = isoTimestamp(goal.createdAt);
|
|
64
|
+
const updated = isoTimestamp(goal.updatedAt);
|
|
65
|
+
lines.push(theme.fg("dim", ` created ${created} • updated ${updated}`));
|
|
66
|
+
}
|
|
67
|
+
return lines;
|
|
68
|
+
}
|
|
69
|
+
function appendNotice(lines, notice, theme) {
|
|
70
|
+
if (notice !== undefined && notice.length > 0)
|
|
71
|
+
lines.push(theme.fg("dim", ` ${notice}`));
|
|
72
|
+
}
|
|
73
|
+
function resolveRenderDetails(details, text) {
|
|
74
|
+
const direct = parseRenderDetails(details);
|
|
75
|
+
if (direct !== undefined)
|
|
76
|
+
return direct;
|
|
77
|
+
const trimmed = text.trim();
|
|
78
|
+
if (!trimmed.startsWith("{"))
|
|
79
|
+
return undefined;
|
|
80
|
+
try {
|
|
81
|
+
return parseRenderDetails(JSON.parse(trimmed));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function parseRenderDetails(value) {
|
|
88
|
+
if (!isRecord(value) || !("goal" in value))
|
|
89
|
+
return undefined;
|
|
90
|
+
const goal = value.goal;
|
|
91
|
+
const notice = typeof value.notice === "string" ? value.notice : undefined;
|
|
92
|
+
if (goal === null)
|
|
93
|
+
return { goal: null, ...(notice === undefined ? {} : { notice }) };
|
|
94
|
+
if (!isGoalSnapshotLike(goal))
|
|
95
|
+
return undefined;
|
|
96
|
+
return { goal, ...(notice === undefined ? {} : { notice }) };
|
|
97
|
+
}
|
|
98
|
+
function isGoalSnapshotLike(value) {
|
|
99
|
+
return (isRecord(value) &&
|
|
100
|
+
typeof value.objective === "string" &&
|
|
101
|
+
typeof value.status === "string" &&
|
|
102
|
+
GOAL_STATUS_VALUES.includes(value.status) &&
|
|
103
|
+
typeof value.tokensUsed === "number" &&
|
|
104
|
+
typeof value.timeUsedSeconds === "number" &&
|
|
105
|
+
typeof value.createdAt === "number" &&
|
|
106
|
+
typeof value.updatedAt === "number");
|
|
107
|
+
}
|
|
108
|
+
function statusGlyph(status) {
|
|
109
|
+
switch (status) {
|
|
110
|
+
case "active":
|
|
111
|
+
return "●";
|
|
112
|
+
case "paused":
|
|
113
|
+
return "◌";
|
|
114
|
+
case "blocked":
|
|
115
|
+
return "■";
|
|
116
|
+
case "complete":
|
|
117
|
+
return "✓";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function statusColor(status) {
|
|
121
|
+
switch (status) {
|
|
122
|
+
case "active":
|
|
123
|
+
return "accent";
|
|
124
|
+
case "paused":
|
|
125
|
+
return "muted";
|
|
126
|
+
case "blocked":
|
|
127
|
+
return "error";
|
|
128
|
+
case "complete":
|
|
129
|
+
return "success";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function objectiveCallPreview(objective) {
|
|
133
|
+
const lines = objective
|
|
134
|
+
.split("\n")
|
|
135
|
+
.map((line) => line.trim())
|
|
136
|
+
.filter((line) => line.length > 0);
|
|
137
|
+
const first = lines[0] ?? "";
|
|
138
|
+
if (first === "")
|
|
139
|
+
return "";
|
|
140
|
+
const truncated = shorten(first, CALL_OBJECTIVE_BUDGET);
|
|
141
|
+
if (lines.length > 1 && truncated === first)
|
|
142
|
+
return `${first}…`;
|
|
143
|
+
return truncated;
|
|
144
|
+
}
|
|
145
|
+
function isoTimestamp(epochSeconds) {
|
|
146
|
+
return new Date(epochSeconds * 1000).toISOString();
|
|
147
|
+
}
|
|
148
|
+
function shorten(value, max) {
|
|
149
|
+
if (value.length <= max)
|
|
150
|
+
return value;
|
|
151
|
+
return `${value.slice(0, max - 1)}…`;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/renderers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAG9C,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAA8B,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAA0C,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElG,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AACpC,MAAM,qBAAqB,GAAG,EAAE,CAAC;AACjC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAO9B,MAAM,UAAU,kBAAkB,CAAC,QAAgB,EAAE,IAAa,EAAE,KAAY;IAC/E,MAAM,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1C,IAAI,QAAQ,KAAK,aAAa,IAAI,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;QACxE,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACvD,OAAO,IAAI,IAAI,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,E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AO,CAAC;QAChB,KAAK,UAAU;YACd,OAAO,SAAS,CAAC;IACnB,CAAC;AACF,CAAC;AAED,SAAS,oBAAoB,CAAC,SAAiB;IAC9C,MAAM,KAAK,GAAG,SAAS;SACrB,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC;IACxD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,KAAK,KAAK;QAAE,OAAO,GAAG,KAAK,GAAG,CAAC;IAChE,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,YAAY,CAAC,YAAoB;IACzC,OAAO,IAAI,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AACpD,CAAC;AAED,SAAS,OAAO,CAAC,KAAa,EAAE,GAAW;IAC1C,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,KAAK,CAAC;IACtC,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;AACtC,CAAC","sourcesContent":["import { Text } from \"@earendil-works/pi-tui\";\nimport type { Theme, ThemeColor } from \"../../../../modes/interactive/theme/theme.ts\";\nimport type { ToolRenderResultOptions } from \"../../types.ts\";\nimport { formatGoalElapsedSeconds, formatTokensCompact, type GoalToolRenderDetails } from \"./format.ts\";\nimport { GOAL_STATUS_VALUES, type GoalStatus, type GoalToolSnapshot, isRecord } from \"./types.ts\";\n\nconst OBJECTIVE_PREVIEW_WIDTH = 120;\nconst COLLAPSED_OBJECTIVE_LINES = 2;\nconst CALL_OBJECTIVE_BUDGET = 80;\nconst CALL_REASON_BUDGET = 60;\n\ninterface ResultLike {\n\tcontent: ReadonlyArray<{ type: string; text?: string }>;\n\tdetails?: unknown;\n}\n\nexport function renderGoalToolCall(toolName: string, args: unknown, theme: Theme): Text {\n\tconst title = theme.fg(\"toolTitle\", theme.bold(toolName));\n\tconst params = isRecord(args) ? args : {};\n\tif (toolName === \"create_goal\" && typeof params.objective === \"string\") {\n\t\tconst preview = objectiveCallPreview(params.objective);\n\t\treturn new Text(preview === \"\" ? title : `${title} ${theme.fg(\"muted\", preview)}`, 0, 0);\n\t}\n\tif (toolName === \"update_goal\" && typeof params.status === \"string\") {\n\t\tconst statusColor: ThemeColor = params.status === \"complete\" ? \"success\" : \"error\";\n\t\tlet line = `${title} ${theme.fg(\"muted\", \"→\")} ${theme.fg(statusColor, params.status)}`;\n\t\tif (typeof params.reason === \"string\" && params.reason.trim().length > 0) {\n\t\t\tline += ` ${theme.fg(\"muted\", `— ${shorten(params.reason.trim(), CALL_REASON_BUDGET)}`)}`;\n\t\t}\n\t\treturn new Text(line, 0, 0);\n\t}\n\treturn new Text(title, 0, 0);\n}\n\nexport function renderGoalToolResult(result: ResultLike, options: ToolRenderResultOptions, theme: Theme): Text {\n\tconst text = result.content.find((block) => block.type === \"text\")?.text ?? \"\";\n\tconst details = resolveRenderDetails(result.details, text);\n\tif (details === undefined) return new Text(theme.fg(\"toolOutput\", text), 0, 0);\n\tif (details.goal === null) {\n\t\tconst lines = [theme.fg(\"dim\", \"No active goal is set.\")];\n\t\tappendNotice(lines, details.notice, theme);\n\t\treturn new Text(lines.join(\"\\n\"), 0, 0);\n\t}\n\tconst lines = goalWidgetLines(details.goal, options.expanded, theme);\n\tappendNotice(lines, details.notice, theme);\n\treturn new Text(lines.join(\"\\n\"), 0, 0);\n}\n\nfunction goalWidgetLines(goal: GoalToolSnapshot, expanded: boolean, theme: Theme): string[] {\n\tconst status = theme.fg(statusColor(goal.status), theme.bold(`${statusGlyph(goal.status)} ${goal.status}`));\n\tconst usage = ` • ${formatTokensCompact(goal.tokensUsed)} tokens • ${formatGoalElapsedSeconds(goal.timeUsedSeconds)}`;\n\tconst lines = [`${status}${theme.fg(\"muted\", usage)}`];\n\n\tconst objectiveLines = goal.objective\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0);\n\tif (expanded) {\n\t\tfor (const line of objectiveLines) lines.push(theme.fg(\"toolOutput\", ` ${line}`));\n\t} else {\n\t\tfor (const line of objectiveLines.slice(0, COLLAPSED_OBJECTIVE_LINES)) {\n\t\t\tlines.push(theme.fg(\"toolOutput\", ` ${shorten(line, OBJECTIVE_PREVIEW_WIDTH)}`));\n\t\t}\n\t\tconst hidden = objectiveLines.length - COLLAPSED_OBJECTIVE_LINES;\n\t\tif (hidden > 0) lines.push(theme.fg(\"dim\", ` … +${hidden} more lines`));\n\t}\n\n\tif (goal.blockedReason !== undefined && goal.blockedReason.length > 0) {\n\t\tlines.push(theme.fg(\"warning\", ` ⚠ ${goal.blockedReason}`));\n\t}\n\tif (expanded) {\n\t\tconst created = isoTimestamp(goal.createdAt);\n\t\tconst updated = isoTimestamp(goal.updatedAt);\n\t\tlines.push(theme.fg(\"dim\", ` created ${created} • updated ${updated}`));\n\t}\n\treturn lines;\n}\n\nfunction appendNotice(lines: string[], notice: string | undefined, theme: Theme): void {\n\tif (notice !== undefined && notice.length > 0) lines.push(theme.fg(\"dim\", ` ${notice}`));\n}\n\nfunction resolveRenderDetails(details: unknown, text: string): GoalToolRenderDetails | undefined {\n\tconst direct = parseRenderDetails(details);\n\tif (direct !== undefined) return direct;\n\tconst trimmed = text.trim();\n\tif (!trimmed.startsWith(\"{\")) return undefined;\n\ttry {\n\t\treturn parseRenderDetails(JSON.parse(trimmed));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction parseRenderDetails(value: unknown): GoalToolRenderDetails | undefined {\n\tif (!isRecord(value) || !(\"goal\" in value)) return undefined;\n\tconst goal = value.goal;\n\tconst notice = typeof value.notice === \"string\" ? value.notice : undefined;\n\tif (goal === null) return { goal: null, ...(notice === undefined ? {} : { notice }) };\n\tif (!isGoalSnapshotLike(goal)) return undefined;\n\treturn { goal, ...(notice === undefined ? {} : { notice }) };\n}\n\nfunction isGoalSnapshotLike(value: unknown): value is GoalToolSnapshot {\n\treturn (\n\t\tisRecord(value) &&\n\t\ttypeof value.objective === \"string\" &&\n\t\ttypeof value.status === \"string\" &&\n\t\t(GOAL_STATUS_VALUES as readonly string[]).includes(value.status) &&\n\t\ttypeof value.tokensUsed === \"number\" &&\n\t\ttypeof value.timeUsedSeconds === \"number\" &&\n\t\ttypeof value.createdAt === \"number\" &&\n\t\ttypeof value.updatedAt === \"number\"\n\t);\n}\n\nfunction statusGlyph(status: GoalStatus): string {\n\tswitch (status) {\n\t\tcase \"active\":\n\t\t\treturn \"●\";\n\t\tcase \"paused\":\n\t\t\treturn \"◌\";\n\t\tcase \"blocked\":\n\t\t\treturn \"■\";\n\t\tcase \"complete\":\n\t\t\treturn \"✓\";\n\t}\n}\n\nfunction statusColor(status: GoalStatus): ThemeColor {\n\tswitch (status) {\n\t\tcase \"active\":\n\t\t\treturn \"accent\";\n\t\tcase \"paused\":\n\t\t\treturn \"muted\";\n\t\tcase \"blocked\":\n\t\t\treturn \"error\";\n\t\tcase \"complete\":\n\t\t\treturn \"success\";\n\t}\n}\n\nfunction objectiveCallPreview(objective: string): string {\n\tconst lines = objective\n\t\t.split(\"\\n\")\n\t\t.map((line) => line.trim())\n\t\t.filter((line) => line.length > 0);\n\tconst first = lines[0] ?? \"\";\n\tif (first === \"\") return \"\";\n\tconst truncated = shorten(first, CALL_OBJECTIVE_BUDGET);\n\tif (lines.length > 1 && truncated === first) return `${first}…`;\n\treturn truncated;\n}\n\nfunction isoTimestamp(epochSeconds: number): string {\n\treturn new Date(epochSeconds * 1000).toISOString();\n}\n\nfunction shorten(value: string, max: number): string {\n\tif (value.length <= max) return value;\n\treturn `${value.slice(0, max - 1)}…`;\n}\n"]}
|
|
@@ -11,6 +11,10 @@ export declare function updateGoal(ref: GoalStoreRef, update: GoalUpdate, source
|
|
|
11
11
|
export declare function archiveGoal(ref: GoalStoreRef, goal: Goal): Promise<void>;
|
|
12
12
|
export declare function clearGoal(ref: GoalStoreRef): Promise<boolean>;
|
|
13
13
|
export declare function accountGoalUsage(ref: GoalStoreRef, usage: TokenUsageSnapshot, elapsedSeconds: number, mode?: GoalAccountingMode, expectedGoalId?: string): Promise<Goal | null>;
|
|
14
|
-
export declare function recordContinuationDelivered(ref: GoalStoreRef, signature: string, expectedGoalId?: string
|
|
15
|
-
|
|
14
|
+
export declare function recordContinuationDelivered(ref: GoalStoreRef, signature: string, expectedGoalId?: string, options?: {
|
|
15
|
+
countUnattended?: boolean;
|
|
16
|
+
}): Promise<Goal | null>;
|
|
17
|
+
export declare function resetContinuationStreak(ref: GoalStoreRef, options?: {
|
|
18
|
+
unattended?: boolean;
|
|
19
|
+
}): Promise<Goal | null>;
|
|
16
20
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,YAAY,EAA+B,MAAM,kBAAkB,CAAC;AAE9F,OAAO,KAAK,EACX,IAAI,EACJ,kBAAkB,EAClB,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,YAAY,EAAE,CAAC;AAmBxB,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAE7D;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAEnE;AAED,wBAAgB,yBAAyB,CAA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wBAAsB,UAAU,CAC/B,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,UAAU,EAClB,MAAM,GAAE,gBAA0B,GAChC,OAAO,CAAC,IAAI,CAAC,CAyDf;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAI9E;AAQD,wBAAsB,SAAS,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAMnE;AAED,wBAAsB,gBAAgB,CACrC,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,kBAAkB,EACzB,cAAc,EAAE,MAAM,EACtB,IAAI,GAAE,kBAA6B,EACnC,cAAc,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAetB;AAED,wBAAsB,2BAA2B,CAChD,GAAG,EAAE,YAAY,EACjB,SAAS,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,MAAM,EACvB,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,OAAO,CAAA;CAAO,GACzC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAatB;AAED,wBAAsB,uBAAuB,CAC5C,GAAG,EAAE,YAAY,EACjB,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACpC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAUtB"}
|
|
@@ -54,6 +54,7 @@ export async function createGoal(ref, objective, tokenBudget) {
|
|
|
54
54
|
tokensUsed: 0,
|
|
55
55
|
timeUsedSeconds: 0,
|
|
56
56
|
consecutiveContinuations: 0,
|
|
57
|
+
unattendedContinuations: 0,
|
|
57
58
|
createdAt: now,
|
|
58
59
|
updatedAt: now,
|
|
59
60
|
lastStartedAt: now,
|
|
@@ -89,6 +90,7 @@ export async function updateGoal(ref, update, source = "model") {
|
|
|
89
90
|
tokensUsed: 0,
|
|
90
91
|
timeUsedSeconds: 0,
|
|
91
92
|
consecutiveContinuations: 0,
|
|
93
|
+
unattendedContinuations: 0,
|
|
92
94
|
createdAt: now,
|
|
93
95
|
updatedAt: now,
|
|
94
96
|
...(tokenBudget === undefined ? {} : { tokenBudget }),
|
|
@@ -105,6 +107,7 @@ export async function updateGoal(ref, update, source = "model") {
|
|
|
105
107
|
const next = transitionGoalStatus({ ...current, objective }, requestedStatus ?? current.status, source, update.reason, now);
|
|
106
108
|
if (next.status !== current.status) {
|
|
107
109
|
next.consecutiveContinuations = 0;
|
|
110
|
+
next.unattendedContinuations = 0;
|
|
108
111
|
delete next.lastContinuationSignature;
|
|
109
112
|
}
|
|
110
113
|
if (tokenBudget === undefined)
|
|
@@ -150,7 +153,7 @@ export async function accountGoalUsage(ref, usage, elapsedSeconds, mode = "activ
|
|
|
150
153
|
return next;
|
|
151
154
|
});
|
|
152
155
|
}
|
|
153
|
-
export async function recordContinuationDelivered(ref, signature, expectedGoalId) {
|
|
156
|
+
export async function recordContinuationDelivered(ref, signature, expectedGoalId, options = {}) {
|
|
154
157
|
return enqueueGoalMutation(ref, async () => {
|
|
155
158
|
const goal = await readGoalFile(ref);
|
|
156
159
|
if (!goal || (expectedGoalId !== undefined && goal.id !== expectedGoalId))
|
|
@@ -158,18 +161,21 @@ export async function recordContinuationDelivered(ref, signature, expectedGoalId
|
|
|
158
161
|
const next = {
|
|
159
162
|
...goal,
|
|
160
163
|
consecutiveContinuations: (goal.consecutiveContinuations ?? 0) + 1,
|
|
164
|
+
unattendedContinuations: (goal.unattendedContinuations ?? 0) + (options.countUnattended === false ? 0 : 1),
|
|
161
165
|
lastContinuationSignature: signature,
|
|
162
166
|
};
|
|
163
167
|
await writeGoalFile(ref, next);
|
|
164
168
|
return next;
|
|
165
169
|
});
|
|
166
170
|
}
|
|
167
|
-
export async function resetContinuationStreak(ref) {
|
|
171
|
+
export async function resetContinuationStreak(ref, options = {}) {
|
|
168
172
|
return enqueueGoalMutation(ref, async () => {
|
|
169
173
|
const goal = await readGoalFile(ref);
|
|
170
174
|
if (!goal)
|
|
171
175
|
return goal;
|
|
172
176
|
const next = { ...goal, consecutiveContinuations: 0 };
|
|
177
|
+
if (options.unattended === true)
|
|
178
|
+
next.unattendedContinuations = 0;
|
|
173
179
|
delete next.lastContinuationSignature;
|
|
174
180
|
await writeGoalFile(ref, next);
|
|
175
181
|
return next;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AASxD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE7F,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAE3D,SAAS,mBAAmB,CAAI,GAAiB,EAAE,QAA0B;IAC5E,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IACjE,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CACpB,GAAG,EAAE,CAAC,SAAS,EACf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,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,MAAM,IAAI,GAAS,EAAE,GAAG,IAAI,EAAE,wBAAwB,EAAE,CAAC,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC,yBAAyB,CAAC;QACtC,MAAM,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAU,EAAE,IAAwB;IAChE,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC;IACvD,IAAI,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IAC7F,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC;AAC/D,CAAC;AAED,SAAS,aAAa,CAAC,iBAAyB;IAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,iBAAiB,GAAG,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,UAAU;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { appendFile, mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { GoalAlreadyExistsError, GoalNotFoundError } from \"./errors.ts\";\nimport { encodedThreadId, goalFilePath, readGoalFile, writeGoalFile } from \"./persistence.ts\";\nimport { transitionGoalStatus } from \"./transitions.ts\";\nimport type {\n\tGoal,\n\tGoalAccountingMode,\n\tGoalStoreRef,\n\tGoalUpdate,\n\tGoalUpdateSource,\n\tTokenUsageSnapshot,\n} from \"./types.ts\";\nimport { resolveTokenBudget, validateObjective, validateTokenBudget } from \"./validation.ts\";\n\nexport { goalFilePath };\n\nconst goalMutationTails = new Map<string, Promise<void>>();\n\nfunction enqueueGoalMutation<T>(ref: GoalStoreRef, mutation: () => Promise<T>): Promise<T> {\n\tconst key = goalFilePath(ref);\n\tconst previous = goalMutationTails.get(key) ?? Promise.resolve();\n\tconst run = previous.then(mutation);\n\tconst tail = run.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tgoalMutationTails.set(key, tail);\n\tvoid tail.then(() => {\n\t\tif (goalMutationTails.get(key) === tail) goalMutationTails.delete(key);\n\t});\n\treturn run;\n}\n\nexport function goalHistoryFilePath(ref: GoalStoreRef): string {\n\treturn join(ref.baseDir, `${encodedThreadId(ref)}.history.jsonl`);\n}\n\nexport function objectiveFullTextFileName(ref: GoalStoreRef): string {\n\treturn `${encodedThreadId(ref)}.objective-full.txt`;\n}\n\nexport function objectiveFullTextFilePath(ref: GoalStoreRef): string {\n\treturn join(ref.baseDir, objectiveFullTextFileName(ref));\n}\n\nexport async function readGoal(ref: GoalStoreRef): Promise<Goal | null> {\n\treturn readGoalFile(ref);\n}\n\nexport async function writeGoal(ref: GoalStoreRef, goal: Goal | null): Promise<void> {\n\tawait enqueueGoalMutation(ref, () => writeGoalFile(ref, goal));\n}\n\nexport async function createGoal(ref: GoalStoreRef, objective: string, tokenBudget?: number): Promise<Goal> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst validatedObjective = validateObjective(objective, objectiveFullTextFileName(ref));\n\t\tconst current = await readGoalFile(ref);\n\t\tif (current !== null && current.status !== \"complete\") {\n\t\t\tthrow new GoalAlreadyExistsError(\"cannot create a new goal because this thread already has a goal\");\n\t\t}\n\t\tif (validatedObjective.truncated) await writeFullObjectiveText(ref, objective);\n\t\tif (current?.status === \"complete\") await archiveGoal(ref, current);\n\t\tconst now = nowSeconds();\n\t\tconst goal: Goal = {\n\t\t\tid: randomUUID(),\n\t\t\tthreadId: ref.threadId,\n\t\t\tobjective: validatedObjective.objective,\n\t\t\tstatus: \"active\",\n\t\t\ttokensUsed: 0,\n\t\t\ttimeUsedSeconds: 0,\n\t\t\tconsecutiveContinuations: 0,\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t\tlastStartedAt: now,\n\t\t\t...(tokenBudget === undefined ? {} : { tokenBudget: validateTokenBudget(tokenBudget) }),\n\t\t};\n\t\tawait writeGoalFile(ref, goal);\n\t\treturn goal;\n\t});\n}\n\nexport async function updateGoal(\n\tref: GoalStoreRef,\n\tupdate: GoalUpdate,\n\tsource: GoalUpdateSource = \"model\",\n): Promise<Goal> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst current = await readGoalFile(ref);\n\t\tif (!current) throw new GoalNotFoundError(\"cannot update goal: no goal exists\");\n\n\t\tconst validatedObjective =\n\t\t\tupdate.objective === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateObjective(update.objective, objectiveFullTextFileName(ref));\n\t\tconst objective = validatedObjective?.objective ?? current.objective;\n\t\tconst tokenBudget = resolveTokenBudget(current.tokenBudget, update.tokenBudget);\n\t\tconst now = nextUpdatedAt(current.updatedAt);\n\t\tconst hasObjectiveUpdate = update.objective !== undefined;\n\t\tconst replacesGoal = hasObjectiveUpdate && (objective !== current.objective || current.status === \"complete\");\n\t\tconst requestedStatus = update.status ?? (hasObjectiveUpdate ? \"active\" : undefined);\n\n\t\tif (replacesGoal) {\n\t\t\tconst status = requestedStatus ?? \"active\";\n\t\t\tif (status === \"blocked\") throw new Error(\"objective replacement cannot create a blocked goal\");\n\t\t\tconst next: Goal = {\n\t\t\t\tid: randomUUID(),\n\t\t\t\tthreadId: ref.threadId,\n\t\t\t\tobjective,\n\t\t\t\tstatus,\n\t\t\t\ttokensUsed: 0,\n\t\t\t\ttimeUsedSeconds: 0,\n\t\t\t\tconsecutiveContinuations: 0,\n\t\t\t\tcreatedAt: now,\n\t\t\t\tupdatedAt: now,\n\t\t\t\t...(tokenBudget === undefined ? {} : { tokenBudget }),\n\t\t\t};\n\t\t\tif (status === \"active\") next.lastStartedAt = now;\n\t\t\tif (status === \"complete\") next.completedAt = now;\n\t\t\tif (validatedObjective?.truncated) await writeFullObjectiveText(ref, update.objective ?? \"\");\n\t\t\tawait writeGoalFile(ref, next);\n\t\t\treturn next;\n\t\t}\n\n\t\tconst next = transitionGoalStatus(\n\t\t\t{ ...current, objective },\n\t\t\trequestedStatus ?? current.status,\n\t\t\tsource,\n\t\t\tupdate.reason,\n\t\t\tnow,\n\t\t);\n\t\tif (next.status !== current.status) {\n\t\t\tnext.consecutiveContinuations = 0;\n\t\t\tdelete next.lastContinuationSignature;\n\t\t}\n\t\tif (tokenBudget === undefined) delete next.tokenBudget;\n\t\telse next.tokenBudget = tokenBudget;\n\t\tif (validatedObjective?.truncated) await writeFullObjectiveText(ref, update.objective ?? \"\");\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nexport async function archiveGoal(ref: GoalStoreRef, goal: Goal): Promise<void> {\n\tconst filePath = goalHistoryFilePath(ref);\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tawait appendFile(filePath, `${JSON.stringify(goal)}\\n`, \"utf8\");\n}\n\nasync function writeFullObjectiveText(ref: GoalStoreRef, objective: string): Promise<void> {\n\tconst filePath = objectiveFullTextFilePath(ref);\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tawait writeFile(filePath, objective, \"utf8\");\n}\n\nexport async function clearGoal(ref: GoalStoreRef): Promise<boolean> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst hadGoal = (await readGoalFile(ref)) !== null;\n\t\tawait writeGoalFile(ref, null);\n\t\treturn hadGoal;\n\t});\n}\n\nexport async function accountGoalUsage(\n\tref: GoalStoreRef,\n\tusage: TokenUsageSnapshot,\n\telapsedSeconds: number,\n\tmode: GoalAccountingMode = \"active\",\n\texpectedGoalId?: string,\n): Promise<Goal | null> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst goal = await readGoalFile(ref);\n\t\tif (!goal || (expectedGoalId !== undefined && goal.id !== expectedGoalId) || !canAccountGoalUsage(goal, mode)) {\n\t\t\treturn goal;\n\t\t}\n\t\tconst next: Goal = {\n\t\t\t...goal,\n\t\t\ttokensUsed: goal.tokensUsed + Math.max(0, usage.input) + Math.max(0, usage.output),\n\t\t\ttimeUsedSeconds: goal.timeUsedSeconds + Math.max(0, Math.trunc(elapsedSeconds)),\n\t\t\tupdatedAt: nextUpdatedAt(goal.updatedAt),\n\t\t};\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nexport async function recordContinuationDelivered(\n\tref: GoalStoreRef,\n\tsignature: string,\n\texpectedGoalId?: string,\n): Promise<Goal | null> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst goal = await readGoalFile(ref);\n\t\tif (!goal || (expectedGoalId !== undefined && goal.id !== expectedGoalId)) return null;\n\t\tconst next: Goal = {\n\t\t\t...goal,\n\t\t\tconsecutiveContinuations: (goal.consecutiveContinuations ?? 0) + 1,\n\t\t\tlastContinuationSignature: signature,\n\t\t};\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nexport async function resetContinuationStreak(ref: GoalStoreRef): Promise<Goal | null> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst goal = await readGoalFile(ref);\n\t\tif (!goal) return goal;\n\t\tconst next: Goal = { ...goal, consecutiveContinuations: 0 };\n\t\tdelete next.lastContinuationSignature;\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nfunction canAccountGoalUsage(goal: Goal, mode: GoalAccountingMode): boolean {\n\tif (mode === \"active\") return goal.status === \"active\";\n\tif (mode === \"activeOrBlocked\") return goal.status === \"active\" || goal.status === \"blocked\";\n\treturn goal.status === \"active\" || goal.status === \"complete\";\n}\n\nfunction nextUpdatedAt(previousUpdatedAt: number): number {\n\treturn Math.max(nowSeconds(), previousUpdatedAt + 1);\n}\n\nfunction nowSeconds(): number {\n\treturn Math.trunc(Date.now() / 1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AAE;QAC1C,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,MAAM,IAAI,GAAS,EAAE,GAAG,IAAI,EAAE,wBAAwB,EAAE,CAAC,EAAE,CAAC;QAC5D,IAAI,OAAO,CAAC,UAAU,KAAK,IAAI;YAAE,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QAClE,OAAO,IAAI,CAAC,yBAAyB,CAAC;QACtC,MAAM,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC;IACb,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAU,EAAE,IAAwB;IAChE,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC;IACvD,IAAI,IAAI,KAAK,iBAAiB;QAAE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC;IAC7F,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,CAAC;AAC/D,CAAC;AAED,SAAS,aAAa,CAAC,iBAAyB;IAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,EAAE,iBAAiB,GAAG,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,UAAU;IAClB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { appendFile, mkdir, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { GoalAlreadyExistsError, GoalNotFoundError } from \"./errors.ts\";\nimport { encodedThreadId, goalFilePath, readGoalFile, writeGoalFile } from \"./persistence.ts\";\nimport { transitionGoalStatus } from \"./transitions.ts\";\nimport type {\n\tGoal,\n\tGoalAccountingMode,\n\tGoalStoreRef,\n\tGoalUpdate,\n\tGoalUpdateSource,\n\tTokenUsageSnapshot,\n} from \"./types.ts\";\nimport { resolveTokenBudget, validateObjective, validateTokenBudget } from \"./validation.ts\";\n\nexport { goalFilePath };\n\nconst goalMutationTails = new Map<string, Promise<void>>();\n\nfunction enqueueGoalMutation<T>(ref: GoalStoreRef, mutation: () => Promise<T>): Promise<T> {\n\tconst key = goalFilePath(ref);\n\tconst previous = goalMutationTails.get(key) ?? Promise.resolve();\n\tconst run = previous.then(mutation);\n\tconst tail = run.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\tgoalMutationTails.set(key, tail);\n\tvoid tail.then(() => {\n\t\tif (goalMutationTails.get(key) === tail) goalMutationTails.delete(key);\n\t});\n\treturn run;\n}\n\nexport function goalHistoryFilePath(ref: GoalStoreRef): string {\n\treturn join(ref.baseDir, `${encodedThreadId(ref)}.history.jsonl`);\n}\n\nexport function objectiveFullTextFileName(ref: GoalStoreRef): string {\n\treturn `${encodedThreadId(ref)}.objective-full.txt`;\n}\n\nexport function objectiveFullTextFilePath(ref: GoalStoreRef): string {\n\treturn join(ref.baseDir, objectiveFullTextFileName(ref));\n}\n\nexport async function readGoal(ref: GoalStoreRef): Promise<Goal | null> {\n\treturn readGoalFile(ref);\n}\n\nexport async function writeGoal(ref: GoalStoreRef, goal: Goal | null): Promise<void> {\n\tawait enqueueGoalMutation(ref, () => writeGoalFile(ref, goal));\n}\n\nexport async function createGoal(ref: GoalStoreRef, objective: string, tokenBudget?: number): Promise<Goal> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst validatedObjective = validateObjective(objective, objectiveFullTextFileName(ref));\n\t\tconst current = await readGoalFile(ref);\n\t\tif (current !== null && current.status !== \"complete\") {\n\t\t\tthrow new GoalAlreadyExistsError(\"cannot create a new goal because this thread already has a goal\");\n\t\t}\n\t\tif (validatedObjective.truncated) await writeFullObjectiveText(ref, objective);\n\t\tif (current?.status === \"complete\") await archiveGoal(ref, current);\n\t\tconst now = nowSeconds();\n\t\tconst goal: Goal = {\n\t\t\tid: randomUUID(),\n\t\t\tthreadId: ref.threadId,\n\t\t\tobjective: validatedObjective.objective,\n\t\t\tstatus: \"active\",\n\t\t\ttokensUsed: 0,\n\t\t\ttimeUsedSeconds: 0,\n\t\t\tconsecutiveContinuations: 0,\n\t\t\tunattendedContinuations: 0,\n\t\t\tcreatedAt: now,\n\t\t\tupdatedAt: now,\n\t\t\tlastStartedAt: now,\n\t\t\t...(tokenBudget === undefined ? {} : { tokenBudget: validateTokenBudget(tokenBudget) }),\n\t\t};\n\t\tawait writeGoalFile(ref, goal);\n\t\treturn goal;\n\t});\n}\n\nexport async function updateGoal(\n\tref: GoalStoreRef,\n\tupdate: GoalUpdate,\n\tsource: GoalUpdateSource = \"model\",\n): Promise<Goal> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst current = await readGoalFile(ref);\n\t\tif (!current) throw new GoalNotFoundError(\"cannot update goal: no goal exists\");\n\n\t\tconst validatedObjective =\n\t\t\tupdate.objective === undefined\n\t\t\t\t? undefined\n\t\t\t\t: validateObjective(update.objective, objectiveFullTextFileName(ref));\n\t\tconst objective = validatedObjective?.objective ?? current.objective;\n\t\tconst tokenBudget = resolveTokenBudget(current.tokenBudget, update.tokenBudget);\n\t\tconst now = nextUpdatedAt(current.updatedAt);\n\t\tconst hasObjectiveUpdate = update.objective !== undefined;\n\t\tconst replacesGoal = hasObjectiveUpdate && (objective !== current.objective || current.status === \"complete\");\n\t\tconst requestedStatus = update.status ?? (hasObjectiveUpdate ? \"active\" : undefined);\n\n\t\tif (replacesGoal) {\n\t\t\tconst status = requestedStatus ?? \"active\";\n\t\t\tif (status === \"blocked\") throw new Error(\"objective replacement cannot create a blocked goal\");\n\t\t\tconst next: Goal = {\n\t\t\t\tid: randomUUID(),\n\t\t\t\tthreadId: ref.threadId,\n\t\t\t\tobjective,\n\t\t\t\tstatus,\n\t\t\t\ttokensUsed: 0,\n\t\t\t\ttimeUsedSeconds: 0,\n\t\t\t\tconsecutiveContinuations: 0,\n\t\t\t\tunattendedContinuations: 0,\n\t\t\t\tcreatedAt: now,\n\t\t\t\tupdatedAt: now,\n\t\t\t\t...(tokenBudget === undefined ? {} : { tokenBudget }),\n\t\t\t};\n\t\t\tif (status === \"active\") next.lastStartedAt = now;\n\t\t\tif (status === \"complete\") next.completedAt = now;\n\t\t\tif (validatedObjective?.truncated) await writeFullObjectiveText(ref, update.objective ?? \"\");\n\t\t\tawait writeGoalFile(ref, next);\n\t\t\treturn next;\n\t\t}\n\n\t\tconst next = transitionGoalStatus(\n\t\t\t{ ...current, objective },\n\t\t\trequestedStatus ?? current.status,\n\t\t\tsource,\n\t\t\tupdate.reason,\n\t\t\tnow,\n\t\t);\n\t\tif (next.status !== current.status) {\n\t\t\tnext.consecutiveContinuations = 0;\n\t\t\tnext.unattendedContinuations = 0;\n\t\t\tdelete next.lastContinuationSignature;\n\t\t}\n\t\tif (tokenBudget === undefined) delete next.tokenBudget;\n\t\telse next.tokenBudget = tokenBudget;\n\t\tif (validatedObjective?.truncated) await writeFullObjectiveText(ref, update.objective ?? \"\");\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nexport async function archiveGoal(ref: GoalStoreRef, goal: Goal): Promise<void> {\n\tconst filePath = goalHistoryFilePath(ref);\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tawait appendFile(filePath, `${JSON.stringify(goal)}\\n`, \"utf8\");\n}\n\nasync function writeFullObjectiveText(ref: GoalStoreRef, objective: string): Promise<void> {\n\tconst filePath = objectiveFullTextFilePath(ref);\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tawait writeFile(filePath, objective, \"utf8\");\n}\n\nexport async function clearGoal(ref: GoalStoreRef): Promise<boolean> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst hadGoal = (await readGoalFile(ref)) !== null;\n\t\tawait writeGoalFile(ref, null);\n\t\treturn hadGoal;\n\t});\n}\n\nexport async function accountGoalUsage(\n\tref: GoalStoreRef,\n\tusage: TokenUsageSnapshot,\n\telapsedSeconds: number,\n\tmode: GoalAccountingMode = \"active\",\n\texpectedGoalId?: string,\n): Promise<Goal | null> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst goal = await readGoalFile(ref);\n\t\tif (!goal || (expectedGoalId !== undefined && goal.id !== expectedGoalId) || !canAccountGoalUsage(goal, mode)) {\n\t\t\treturn goal;\n\t\t}\n\t\tconst next: Goal = {\n\t\t\t...goal,\n\t\t\ttokensUsed: goal.tokensUsed + Math.max(0, usage.input) + Math.max(0, usage.output),\n\t\t\ttimeUsedSeconds: goal.timeUsedSeconds + Math.max(0, Math.trunc(elapsedSeconds)),\n\t\t\tupdatedAt: nextUpdatedAt(goal.updatedAt),\n\t\t};\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nexport async function recordContinuationDelivered(\n\tref: GoalStoreRef,\n\tsignature: string,\n\texpectedGoalId?: string,\n\toptions: { countUnattended?: boolean } = {},\n): Promise<Goal | null> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst goal = await readGoalFile(ref);\n\t\tif (!goal || (expectedGoalId !== undefined && goal.id !== expectedGoalId)) return null;\n\t\tconst next: Goal = {\n\t\t\t...goal,\n\t\t\tconsecutiveContinuations: (goal.consecutiveContinuations ?? 0) + 1,\n\t\t\tunattendedContinuations: (goal.unattendedContinuations ?? 0) + (options.countUnattended === false ? 0 : 1),\n\t\t\tlastContinuationSignature: signature,\n\t\t};\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nexport async function resetContinuationStreak(\n\tref: GoalStoreRef,\n\toptions: { unattended?: boolean } = {},\n): Promise<Goal | null> {\n\treturn enqueueGoalMutation(ref, async () => {\n\t\tconst goal = await readGoalFile(ref);\n\t\tif (!goal) return goal;\n\t\tconst next: Goal = { ...goal, consecutiveContinuations: 0 };\n\t\tif (options.unattended === true) next.unattendedContinuations = 0;\n\t\tdelete next.lastContinuationSignature;\n\t\tawait writeGoalFile(ref, next);\n\t\treturn next;\n\t});\n}\n\nfunction canAccountGoalUsage(goal: Goal, mode: GoalAccountingMode): boolean {\n\tif (mode === \"active\") return goal.status === \"active\";\n\tif (mode === \"activeOrBlocked\") return goal.status === \"active\" || goal.status === \"blocked\";\n\treturn goal.status === \"active\" || goal.status === \"complete\";\n}\n\nfunction nextUpdatedAt(previousUpdatedAt: number): number {\n\treturn Math.max(nowSeconds(), previousUpdatedAt + 1);\n}\n\nfunction nowSeconds(): number {\n\treturn Math.trunc(Date.now() / 1000);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-registration.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAmB,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAKtF,OAAO,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAMzE,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,YAAY,CAAC;IAC/D,QAAQ,CAAC,uBAAuB,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC5G,QAAQ,CAAC,wBAAwB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,uBAAuB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACvD,QAAQ,CAAC,yBAAyB,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACzD,QAAQ,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3E,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,wBAAwB,GAAG,IAAI,CA+FxF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
import { formatGoalToolResponse } from "./format.js";
|
|
2
|
+
import { formatGoalToolResponse, goalToolRenderDetails } from "./format.js";
|
|
3
|
+
import { renderGoalToolCall, renderGoalToolResult } from "./renderers.js";
|
|
3
4
|
import { createGoal, objectiveFullTextFileName, readGoal, updateGoal } from "./store.js";
|
|
4
5
|
import { openTodoCompletionError, openTodoTaskContents } from "./todo-gate.js";
|
|
5
6
|
import { MODEL_SETTABLE_GOAL_STATUS_VALUES } from "./types.js";
|
|
@@ -24,8 +25,13 @@ export function registerGoalTools(pi, deps) {
|
|
|
24
25
|
const goal = await createGoal(ref, params.objective);
|
|
25
26
|
deps.beginAgentGoalAccounting(goal);
|
|
26
27
|
deps.refreshGoalUi(ctx, goal);
|
|
27
|
-
|
|
28
|
+
const notice = validatedObjective.truncated
|
|
29
|
+
? objectiveTruncationNotice(objectiveFullTextFileName(ref))
|
|
30
|
+
: undefined;
|
|
31
|
+
return toolText(formatGoalToolResponse(goal, notice), goalToolRenderDetails(goal, notice));
|
|
28
32
|
},
|
|
33
|
+
renderCall: (args, theme) => renderGoalToolCall("create_goal", args, theme),
|
|
34
|
+
renderResult: (result, options, theme) => renderGoalToolResult(result, options, theme),
|
|
29
35
|
});
|
|
30
36
|
pi.registerTool({
|
|
31
37
|
name: "update_goal",
|
|
@@ -57,8 +63,10 @@ export function registerGoalTools(pi, deps) {
|
|
|
57
63
|
else
|
|
58
64
|
deps.markGoalCompletedThisTurn(goal);
|
|
59
65
|
deps.refreshGoalUi(ctx, goal);
|
|
60
|
-
return toolText(formatGoalToolResponse(goal));
|
|
66
|
+
return toolText(formatGoalToolResponse(goal), goalToolRenderDetails(goal));
|
|
61
67
|
},
|
|
68
|
+
renderCall: (args, theme) => renderGoalToolCall("update_goal", args, theme),
|
|
69
|
+
renderResult: (result, options, theme) => renderGoalToolResult(result, options, theme),
|
|
62
70
|
});
|
|
63
71
|
pi.registerTool({
|
|
64
72
|
name: "get_goal",
|
|
@@ -68,11 +76,13 @@ export function registerGoalTools(pi, deps) {
|
|
|
68
76
|
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
69
77
|
const goal = await deps.accountCurrentAgentTurn(ctx, "active");
|
|
70
78
|
deps.refreshGoalUi(ctx, goal);
|
|
71
|
-
return toolText(formatGoalToolResponse(goal));
|
|
79
|
+
return toolText(formatGoalToolResponse(goal), goalToolRenderDetails(goal));
|
|
72
80
|
},
|
|
81
|
+
renderCall: (args, theme) => renderGoalToolCall("get_goal", args, theme),
|
|
82
|
+
renderResult: (result, options, theme) => renderGoalToolResult(result, options, theme),
|
|
73
83
|
});
|
|
74
84
|
}
|
|
75
|
-
function toolText(text) {
|
|
76
|
-
return { content: [{ type: "text", text }], details
|
|
85
|
+
function toolText(text, details) {
|
|
86
|
+
return { content: [{ type: "text", text }], details };
|
|
77
87
|
}
|
|
78
88
|
//# sourceMappingURL=tool-registration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,yBAAyB,EAAE,QAAQ,EAAE,UAAU,EA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AuB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC/D,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY;IAC7B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport type { AgentToolResult, ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { formatGoalToolResponse } from \"./format.ts\";\nimport { createGoal, objectiveFullTextFileName, readGoal, updateGoal } from \"./store.ts\";\nimport { openTodoCompletionError, openTodoTaskContents } from \"./todo-gate.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { MODEL_SETTABLE_GOAL_STATUS_VALUES } from \"./types.ts\";\nimport { objectiveTruncationNotice, validateObjective } from \"./validation.ts\";\n\ntype GoalToolResult = AgentToolResult<Record<string, never>>;\n\nexport type GoalToolRegistrationDeps = {\n\treadonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;\n\treadonly accountCurrentAgentTurn: (ctx: ExtensionContext, mode: GoalAccountingMode) => Promise<Goal | null>;\n\treadonly beginAgentGoalAccounting: (goal: Goal) => void;\n\treadonly markGoalBlockedThisTurn: (goal: Goal) => void;\n\treadonly markGoalCompletedThisTurn: (goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;\n};\n\nexport function registerGoalTools(pi: ExtensionAPI, deps: GoalToolRegistrationDeps): void {\n\tpi.registerTool({\n\t\tname: \"create_goal\",\n\t\tlabel: \"Create Goal\",\n\t\tdescription:\n\t\t\t\"Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks.\\nObjectives are limited to 4,000 characters. For longer instructions, put the full objective in a file and refer to that file.\\nReplaces the current goal when it is complete and archives it; fails if an unfinished goal exists.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tobjective: Type.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Required. The concrete objective to start pursuing. Limit: 4,000 characters. For longer instructions, put the full objective in a file and refer to that file.\",\n\t\t\t\t}),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst ref = deps.goalStoreRef(ctx);\n\t\t\tconst current = await readGoal(ref);\n\t\t\tif (current !== null && current.status !== \"complete\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"cannot create a new goal because this thread already has an unfinished goal; use update_goal only when the existing goal is complete\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst validatedObjective = validateObjective(params.objective, objectiveFullTextFileName(ref));\n\t\t\tconst goal = await createGoal(ref, params.objective);\n\t\t\tdeps.beginAgentGoalAccounting(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(\n\t\t\t\tformatGoalToolResponse(\n\t\t\t\t\tgoal,\n\t\t\t\t\tvalidatedObjective.truncated ? objectiveTruncationNotice(objectiveFullTextFileName(ref)) : undefined,\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t});\n\n\tpi.registerTool({\n\t\tname: \"update_goal\",\n\t\tlabel: \"Update Goal\",\n\t\tdescription:\n\t\t\t\"Update the existing goal.\\nSet status to `complete` only when the completion audit proves the objective has actually been achieved and no required work remains. Completion is rejected while the todo list has open tasks: finish or drop them first. When the audit passes, call this tool in that same turn instead of repeating that the work is done. Do not mark a goal complete merely because you are stopping work.\\nSet status to `blocked` only at a true impasse: first confirm no live monitor, subscription, background task, or other resumption channel can still deliver the change the goal is waiting on (a wait on such a channel is not an impasse - end the turn and let it wake the goal instead of blocking), the blocking condition is unmistakably clear, and it has recurred for at least 3 consecutive goal turns. If the user resumes a blocked goal, start a fresh blocked audit after resume. Never mark a goal blocked merely because the work is hard, slow, or uncertain.\\nA non-empty reason is required when blocking; reason must not be provided when completing.\\nYou cannot use this tool to pause or resume a goal; those status changes are controlled by the user or system.\\nWhen marking the goal achieved with status `complete`, report the final elapsed time and token usage from the tool result to the user.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tstatus: Type.Union(\n\t\t\t\t\tMODEL_SETTABLE_GOAL_STATUS_VALUES.map((status) => Type.Literal(status)),\n\t\t\t\t\t{ description: \"Required. Set to complete when achieved or blocked with a non-empty reason.\" },\n\t\t\t\t),\n\t\t\t\treason: Type.Optional(\n\t\t\t\t\tType.String({\n\t\t\t\t\t\tdescription: \"Required and non-empty when status is blocked; rejected when status is complete.\",\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst reason = typeof params.reason === \"string\" ? params.reason.trim() : undefined;\n\t\t\tif (params.status === \"blocked\" && (reason === undefined || reason.length === 0)) {\n\t\t\t\tthrow new Error(\"reason is required when status is blocked\");\n\t\t\t}\n\t\t\tif (params.status === \"complete\" && reason !== undefined && reason.length > 0) {\n\t\t\t\tthrow new Error(\"reason must not be provided when status is complete\");\n\t\t\t}\n\t\t\tif (params.status === \"complete\") {\n\t\t\t\tconst openTasks = openTodoTaskContents(ctx.sessionManager.getBranch());\n\t\t\t\tif (openTasks.length > 0) throw new Error(openTodoCompletionError(openTasks));\n\t\t\t}\n\t\t\tawait deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\tconst goal = await updateGoal(\n\t\t\t\tdeps.goalStoreRef(ctx),\n\t\t\t\tparams.status === \"blocked\" ? { status: \"blocked\", reason } : { status: \"complete\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tif (goal.status === \"blocked\") deps.markGoalBlockedThisTurn(goal);\n\t\t\telse deps.markGoalCompletedThisTurn(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n\n\tpi.registerTool({\n\t\tname: \"get_goal\",\n\t\tlabel: \"Get Goal\",\n\t\tdescription: \"Get the current goal for this thread, including status, token and elapsed-time usage.\",\n\t\tparameters: Type.Object({}, { additionalProperties: false }),\n\t\tasync execute(_toolCallId, _params, _signal, _onUpdate, ctx) {\n\t\t\tconst goal = await deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal));\n\t\t},\n\t});\n}\n\nfunction toolText(text: string): GoalToolResult {\n\treturn { content: [{ type: \"text\" as const, text }], details: {} };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-registration.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/tool-registration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAA8B,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,yBAAyB,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE/E,OAAO,EAAE,iCAAiC,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAa/E,MAAM,UAAU,iBAAiB,CAAC,EAAgB,EAAE,IAA8B;IACjF,EAAE,CAAC,YAAY,CAAC;QACf,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,aAAa;QACpB,WAAW,EACV,uW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AAuF;QACpG,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAAC;QAC5D,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG;YAC1D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;YAC/D,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAC9B,OAAO,QAAQ,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5E,CAAC;QACD,UAAU,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC;QACxE,YAAY,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;KACtF,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,IAAY,EAAE,OAA8B;IAC7D,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;AAChE,CAAC","sourcesContent":["import { Type } from \"typebox\";\nimport type { AgentToolResult, ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { formatGoalToolResponse, type GoalToolRenderDetails, goalToolRenderDetails } from \"./format.ts\";\nimport { renderGoalToolCall, renderGoalToolResult } from \"./renderers.ts\";\nimport { createGoal, objectiveFullTextFileName, readGoal, updateGoal } from \"./store.ts\";\nimport { openTodoCompletionError, openTodoTaskContents } from \"./todo-gate.ts\";\nimport type { Goal, GoalAccountingMode, GoalStoreRef } from \"./types.ts\";\nimport { MODEL_SETTABLE_GOAL_STATUS_VALUES } from \"./types.ts\";\nimport { objectiveTruncationNotice, validateObjective } from \"./validation.ts\";\n\ntype GoalToolResult = AgentToolResult<GoalToolRenderDetails>;\n\nexport type GoalToolRegistrationDeps = {\n\treadonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;\n\treadonly accountCurrentAgentTurn: (ctx: ExtensionContext, mode: GoalAccountingMode) => Promise<Goal | null>;\n\treadonly beginAgentGoalAccounting: (goal: Goal) => void;\n\treadonly markGoalBlockedThisTurn: (goal: Goal) => void;\n\treadonly markGoalCompletedThisTurn: (goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal | null) => void;\n};\n\nexport function registerGoalTools(pi: ExtensionAPI, deps: GoalToolRegistrationDeps): void {\n\tpi.registerTool({\n\t\tname: \"create_goal\",\n\t\tlabel: \"Create Goal\",\n\t\tdescription:\n\t\t\t\"Create a goal only when explicitly requested by the user or system/developer instructions; do not infer goals from ordinary tasks.\\nObjectives are limited to 4,000 characters. For longer instructions, put the full objective in a file and refer to that file.\\nReplaces the current goal when it is complete and archives it; fails if an unfinished goal exists.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tobjective: Type.String({\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t\"Required. The concrete objective to start pursuing. Limit: 4,000 characters. For longer instructions, put the full objective in a file and refer to that file.\",\n\t\t\t\t}),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst ref = deps.goalStoreRef(ctx);\n\t\t\tconst current = await readGoal(ref);\n\t\t\tif (current !== null && current.status !== \"complete\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"cannot create a new goal because this thread already has an unfinished goal; use update_goal only when the existing goal is complete\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst validatedObjective = validateObjective(params.objective, objectiveFullTextFileName(ref));\n\t\t\tconst goal = await createGoal(ref, params.objective);\n\t\t\tdeps.beginAgentGoalAccounting(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\tconst notice = validatedObjective.truncated\n\t\t\t\t? objectiveTruncationNotice(objectiveFullTextFileName(ref))\n\t\t\t\t: undefined;\n\t\t\treturn toolText(formatGoalToolResponse(goal, notice), goalToolRenderDetails(goal, notice));\n\t\t},\n\t\trenderCall: (args, theme) => renderGoalToolCall(\"create_goal\", args, theme),\n\t\trenderResult: (result, options, theme) => renderGoalToolResult(result, options, theme),\n\t});\n\n\tpi.registerTool({\n\t\tname: \"update_goal\",\n\t\tlabel: \"Update Goal\",\n\t\tdescription:\n\t\t\t\"Update the existing goal.\\nSet status to `complete` only when the completion audit proves the objective has actually been achieved and no required work remains. Completion is rejected while the todo list has open tasks: finish or drop them first. When the audit passes, call this tool in that same turn instead of repeating that the work is done. Do not mark a goal complete merely because you are stopping work.\\nSet status to `blocked` only at a true impasse: first confirm no live monitor, subscription, background task, or other resumption channel can still deliver the change the goal is waiting on (a wait on such a channel is not an impasse - end the turn and let it wake the goal instead of blocking), the blocking condition is unmistakably clear, and it has recurred for at least 3 consecutive goal turns. If the user resumes a blocked goal, start a fresh blocked audit after resume. Never mark a goal blocked merely because the work is hard, slow, or uncertain.\\nA non-empty reason is required when blocking; reason must not be provided when completing.\\nYou cannot use this tool to pause or resume a goal; those status changes are controlled by the user or system.\\nWhen marking the goal achieved with status `complete`, report the final elapsed time and token usage from the tool result to the user.\",\n\t\tparameters: Type.Object(\n\t\t\t{\n\t\t\t\tstatus: Type.Union(\n\t\t\t\t\tMODEL_SETTABLE_GOAL_STATUS_VALUES.map((status) => Type.Literal(status)),\n\t\t\t\t\t{ description: \"Required. Set to complete when achieved or blocked with a non-empty reason.\" },\n\t\t\t\t),\n\t\t\t\treason: Type.Optional(\n\t\t\t\t\tType.String({\n\t\t\t\t\t\tdescription: \"Required and non-empty when status is blocked; rejected when status is complete.\",\n\t\t\t\t\t}),\n\t\t\t\t),\n\t\t\t},\n\t\t\t{ additionalProperties: false },\n\t\t),\n\t\tasync execute(_toolCallId, params, _signal, _onUpdate, ctx) {\n\t\t\tconst reason = typeof params.reason === \"string\" ? params.reason.trim() : undefined;\n\t\t\tif (params.status === \"blocked\" && (reason === undefined || reason.length === 0)) {\n\t\t\t\tthrow new Error(\"reason is required when status is blocked\");\n\t\t\t}\n\t\t\tif (params.status === \"complete\" && reason !== undefined && reason.length > 0) {\n\t\t\t\tthrow new Error(\"reason must not be provided when status is complete\");\n\t\t\t}\n\t\t\tif (params.status === \"complete\") {\n\t\t\t\tconst openTasks = openTodoTaskContents(ctx.sessionManager.getBranch());\n\t\t\t\tif (openTasks.length > 0) throw new Error(openTodoCompletionError(openTasks));\n\t\t\t}\n\t\t\tawait deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\tconst goal = await updateGoal(\n\t\t\t\tdeps.goalStoreRef(ctx),\n\t\t\t\tparams.status === \"blocked\" ? { status: \"blocked\", reason } : { status: \"complete\" },\n\t\t\t\t\"model\",\n\t\t\t);\n\t\t\tif (goal.status === \"blocked\") deps.markGoalBlockedThisTurn(goal);\n\t\t\telse deps.markGoalCompletedThisTurn(goal);\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal), goalToolRenderDetails(goal));\n\t\t},\n\t\trenderCall: (args, theme) => renderGoalToolCall(\"update_goal\", args, theme),\n\t\trenderResult: (result, options, theme) => renderGoalToolResult(result, options, theme),\n\t});\n\n\tpi.registerTool({\n\t\tname: \"get_goal\",\n\t\tlabel: \"Get Goal\",\n\t\tdescription: \"Get the current goal for this thread, including status, token and elapsed-time usage.\",\n\t\tparameters: Type.Object({}, { additionalProperties: false }),\n\t\tasync execute(_toolCallId, _params, _signal, _onUpdate, ctx) {\n\t\t\tconst goal = await deps.accountCurrentAgentTurn(ctx, \"active\");\n\t\t\tdeps.refreshGoalUi(ctx, goal);\n\t\t\treturn toolText(formatGoalToolResponse(goal), goalToolRenderDetails(goal));\n\t\t},\n\t\trenderCall: (args, theme) => renderGoalToolCall(\"get_goal\", args, theme),\n\t\trenderResult: (result, options, theme) => renderGoalToolResult(result, options, theme),\n\t});\n}\n\nfunction toolText(text: string, details: GoalToolRenderDetails): GoalToolResult {\n\treturn { content: [{ type: \"text\" as const, text }], details };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,sDAAuD,CAAC;AACvF,eAAO,MAAM,iCAAiC,kCAAmC,CAAC;AAElF,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,iCAAiC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzF,MAAM,MAAM,YAAY,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,iBAAiB,GAAG,kBAAkB,CAAC;AACnF,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,CAAC;AAEhD,MAAM,MAAM,IAAI,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,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C;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AACvF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AACvF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAU,CAAC;AAoElF,MAAM,UAAU,QAAQ,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC","sourcesContent":["export const GOAL_STATUS_VALUES = [\"active\", \"paused\", \"blocked\", \"complete\"] as const;\nexport const MODEL_SETTABLE_GOAL_STATUS_VALUES = [\"complete\", \"blocked\"] as const;\n\nexport type GoalStatus = (typeof GOAL_STATUS_VALUES)[number];\nexport type ModelSettableGoalStatus = (typeof MODEL_SETTABLE_GOAL_STATUS_VALUES)[number];\n\nexport type GoalStoreRef = {\n\tbaseDir: string;\n\tthreadId: string;\n};\n\nexport type GoalAccountingMode = \"active\" | \"activeOrBlocked\" | \"activeOrComplete\";\nexport type GoalUpdateSource = \"model\" | \"user\";\n\nexport type Goal = {\n\tid: string;\n\tthreadId: string;\n\tobjective: string;\n\tstatus: GoalStatus;\n\ttokenBudget?: number;\n\ttokensUsed: number;\n\ttimeUsedSeconds: number;\n\tconsecutiveContinuations?: number;\n\tunattendedContinuations?: number;\n\tlastContinuationSignature?: string;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\tlastStartedAt?: number;\n\tblockedReason?: string;\n\tblockedAt?: number;\n\tcompletedAt?: number;\n};\n\nexport type GoalFile = {\n\tversion: 1;\n\tgoal: Goal | null;\n};\n\nexport type TokenUsageSnapshot = {\n\tinput: number;\n\toutput: number;\n\tcacheRead: number;\n\tcacheWrite: number;\n\ttotalTokens: number;\n};\n\nexport type GoalUpdate = {\n\tobjective?: string;\n\tstatus?: GoalStatus;\n\treason?: string;\n\ttokenBudget?: number | null;\n};\n\nexport type GoalToolSnapshot = {\n\tthreadId: string;\n\tobjective: string;\n\tstatus: GoalStatus;\n\ttokensUsed: number;\n\ttimeUsedSeconds: number;\n\tcreatedAt: number;\n\tupdatedAt: number;\n\tblockedReason?: string;\n\tblockedAt?: number;\n};\n\nexport type GoalToolResponse = {\n\tgoal: GoalToolSnapshot | null;\n};\n\nexport function isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACN,WAAW,EACX,gCAAgC,GAGhC,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,SAAS,eAAe,CAAC,GAAqB;IAC7C,OAAO,gCAAgC,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EAAgB;IAC1D,IAAI,aAAa,GAAgB,EAAE,CAAC;IAEpC,MAAM,gBAAgB,GAAG,GAAgB,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IAEvE,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAQ,EAAE;QACtD,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC,CAAC;IAEF,MAAM,UAAU,GAAG,CAAC,GAAqB,EAAE,i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B,GASrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC","sourcesContent":["import type { ExtensionAPI, ExtensionContext } from \"../../types.ts\";\nimport { registerTodoCommand } from \"./commands.ts\";\nimport { phasesFromCursorTodos } from \"./native-todo-mirror.ts\";\nimport { TASK_MANAGEMENT_SECTION } from \"./prompt.ts\";\nimport {\n\tclonePhases,\n\tgetLatestPhasesFromBranchEntries,\n\ttype TodoCompletionTransition,\n\ttype TodoPhase,\n} from \"./state.ts\";\nimport { TODO_STATE_ENTRY_TYPE } from \"./todo-types.ts\";\nimport { getTodoWidgetModel } from \"./todo-widget.ts\";\nimport { TodoWidgetComponent } from \"./todo-widget-component.ts\";\nimport { registerTodoTool } from \"./tools/todo.ts\";\n\nfunction getLatestPhases(ctx: ExtensionContext): TodoPhase[] {\n\treturn getLatestPhasesFromBranchEntries(ctx.sessionManager.getBranch());\n}\n\nexport default function todotoolsExtension(pi: ExtensionAPI): void {\n\tlet currentPhases: TodoPhase[] = [];\n\n\tconst getCurrentPhases = (): TodoPhase[] => clonePhases(currentPhases);\n\n\tconst setCurrentPhases = (phases: TodoPhase[]): void => {\n\t\tcurrentPhases = clonePhases(phases);\n\t};\n\n\tconst syncWidget = (ctx: ExtensionContext, completedTasks: readonly TodoCompletionTransition[] = []): void => {\n\t\tconst model = getTodoWidgetModel(currentPhases);\n\t\tctx.ui.setWidget(\n\t\t\t\"todo-sidebar\",\n\t\t\tmodel ? (tui, theme) => new TodoWidgetComponent(tui, theme, model, completedTasks) : undefined,\n\t\t);\n\t};\n\n\tconst syncFromSession = (ctx: ExtensionContext): void => {\n\t\tcurrentPhases = getLatestPhases(ctx);\n\t\tsyncWidget(ctx);\n\t};\n\n\tpi.on(\"session_start\", async (_event, ctx) => {\n\t\tsyncFromSession(ctx);\n\t});\n\n\tpi.on(\"session_tree\", async (_event, ctx) => {\n\t\tsyncFromSession(ctx);\n\t});\n\n\tpi.on(\"message_end\", async (event, ctx) => {\n\t\tconst message = event.message;\n\t\tif (message?.role !== \"assistant\" || !Array.isArray(message.content)) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const block of message.content) {\n\t\t\tif (block.type !== \"toolCall\" || block.name !== \"todo\" || block.arguments?.op) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst phases = phasesFromCursorTodos(block.arguments?.todos);\n\t\t\tif (phases === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tsetCurrentPhases(phases);\n\t\t\tpi.appendEntry(TODO_STATE_ENTRY_TYPE, { schema: \"v2\", phases });\n\t\t\tsyncWidget(ctx);\n\t\t}\n\t});\n\n\tpi.on(\"before_agent_start\", async (event) => {\n\t\treturn {\n\t\t\tsystemPrompt: `${event.systemPrompt}\\n${TASK_MANAGEMENT_SECTION}`,\n\t\t};\n\t});\n\n\tregisterTodoTool(pi, { getCurrentPhases, setCurrentPhases, syncWidget });\n\tregisterTodoCommand(pi, { getCurrentPhases, setCurrentPhases, syncWidget });\n}\n\nexport { findPhaseFuzzy, findTaskFuzzy, registerTodoCommand, tokenizeTodoArgs } from \"./commands.ts\";\nexport { markdownToPhases, phasesToMarkdown, resolveTodoMarkdownPath } from \"./markdown.ts\";\nexport { TASK_MANAGEMENT_SECTION } from \"./prompt.ts\";\nexport {\n\tappendItems,\n\tapplyEntry,\n\tapplyOpsToPhases,\n\tapplyParams,\n\tclonePhases,\n\tcloneTask,\n\tDEFAULT_INIT_PHASE,\n\tfindPhaseByName,\n\tfindTaskByContent,\n\tformatSummary,\n\tgetCompletionTransitions,\n\tgetLatestPhasesFromBranchEntries,\n\tgetLatestTodosFromBranchEntries,\n\tgetTaskTargets,\n\tgetTodoMarker,\n\tgetTodoResultLines,\n\tgetTodoWidgetLines,\n\tinitPhases,\n\tisIncompleteTodo,\n\tisTerminalTodoStatus,\n\tisTodoItem,\n\tisTodoItemArray,\n\tisTodoPhase,\n\tisTodoPhaseArray,\n\tnextActionableTask,\n\tnormalizeInProgressTask,\n\tremoveTasks,\n\tresolvePhaseOrError,\n\tresolveTaskOrError,\n\tsanitizeTodoText,\n\tTODO_STATE_ENTRY_TYPE,\n\ttype TodoCompletionTransition,\n\ttype TodoItem,\n\ttype TodoOpEntry,\n\ttype TodoOperation,\n\ttype TodoPhase,\n\ttype TodoStateEntry,\n\ttype TodoStatus,\n\ttype TodoToolDetails,\n} from \"./state.ts\";\nexport { phaseRomanNumeral } from \"./tools/todo.ts\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-todo-mirror.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/native-todo-mirror.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAC;AAK7D,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"native-todo-mirror.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/native-todo-mirror.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAc,MAAM,iBAAiB,CAAC;AAK7D,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,SAAS,CAkB7E"}
|
|
@@ -2,7 +2,7 @@ const STATUSES = new Set(["pending", "in_progress", "completed", "abandoned"]);
|
|
|
2
2
|
const DEFAULT_PHASE_NAME = "Tasks";
|
|
3
3
|
export function phasesFromCursorTodos(todos) {
|
|
4
4
|
if (!Array.isArray(todos)) {
|
|
5
|
-
return
|
|
5
|
+
return undefined;
|
|
6
6
|
}
|
|
7
7
|
const tasks = [];
|
|
8
8
|
for (const item of todos) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-todo-mirror.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/native-todo-mirror.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,IAA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E,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtE,CAAC","sourcesContent":["import type { TodoPhase, TodoStatus } from \"./todo-types.ts\";\n\nconst STATUSES = new Set<TodoStatus>([\"pending\", \"in_progress\", \"completed\", \"abandoned\"]);\nconst DEFAULT_PHASE_NAME = \"Tasks\";\n\nexport function phasesFromCursorTodos(todos: unknown): TodoPhase[] | undefined {\n\tif (!Array.isArray(todos)) {\n\t\treturn undefined;\n\t}\n\tconst tasks = [];\n\tfor (const item of todos) {\n\t\tif (!item || typeof item !== \"object\") {\n\t\t\tcontinue;\n\t\t}\n\t\tconst raw = item as { content?: unknown; status?: unknown };\n\t\tconst content = typeof raw.content === \"string\" ? raw.content.trim() : \"\";\n\t\tif (!content) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst status = STATUSES.has(raw.status as TodoStatus) ? (raw.status as TodoStatus) : \"pending\";\n\t\ttasks.push({ content, status });\n\t}\n\treturn tasks.length > 0 ? [{ name: DEFAULT_PHASE_NAME, tasks }] : [];\n}\n"]}
|