operon-agents-core 0.1.0-alpha.2 → 0.1.0-alpha.21
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/agent.d.ts +8 -7
- package/dist/agent/compose-hooks.d.ts +10 -1
- package/dist/agent/compose-hooks.js +61 -6
- package/dist/agent/concurrency.js +1 -1
- package/dist/agent/context-report.d.ts +2 -2
- package/dist/agent/durable-state.d.ts +22 -0
- package/dist/agent/durable-state.js +54 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1 -1
- package/dist/agent/instruction-context.d.ts +6 -6
- package/dist/agent/instruction-context.js +23 -23
- package/dist/agent/profile-builtins.js +1 -1
- package/dist/agent/run-support.d.ts +1 -1
- package/dist/agent/run-support.js +6 -5
- package/dist/agent/runner.d.ts +25 -22
- package/dist/agent/runner.js +217 -121
- package/dist/agent/session.d.ts +262 -156
- package/dist/agent/session.js +590 -418
- package/dist/agent/subagent-tools.js +3 -3
- package/dist/agent/subagent.js +28 -13
- package/dist/agent/toolset.d.ts +1 -0
- package/dist/agent/toolset.js +13 -7
- package/dist/agent/workflow/journal.d.ts +2 -2
- package/dist/agent/workflow/journal.js +2 -2
- package/dist/agent/workflow/manager.d.ts +1 -1
- package/dist/agent/workflow/manager.js +1 -1
- package/dist/agent/workflow/prompt.js +2 -2
- package/dist/agent/workflow/sandbox.d.ts +1 -1
- package/dist/agent/workflow/sandbox.js +1 -1
- package/dist/agent/workflow/tool.js +30 -43
- package/dist/agent/worktree.d.ts +8 -8
- package/dist/agent/worktree.js +15 -15
- package/dist/capabilities/assembler.d.ts +29 -5
- package/dist/capabilities/assembler.js +85 -9
- package/dist/capabilities/background/code-task.d.ts +43 -0
- package/dist/capabilities/background/code-task.js +75 -0
- package/dist/capabilities/background/command-task.d.ts +9 -2
- package/dist/capabilities/background/command-task.js +22 -6
- package/dist/capabilities/background/index.d.ts +6 -1
- package/dist/capabilities/background/index.js +26 -20
- package/dist/capabilities/background/manager.d.ts +57 -1
- package/dist/capabilities/background/manager.js +210 -45
- package/dist/capabilities/background/persist-disk.d.ts +1 -1
- package/dist/capabilities/background/persist-disk.js +1 -1
- package/dist/capabilities/background/persist.js +4 -2
- package/dist/capabilities/background/projections.d.ts +16 -0
- package/dist/capabilities/background/projections.js +86 -0
- package/dist/capabilities/background/stall-watchdog.d.ts +41 -0
- package/dist/capabilities/background/stall-watchdog.js +85 -0
- package/dist/capabilities/background/task.d.ts +8 -7
- package/dist/capabilities/background/tools.js +33 -7
- package/dist/capabilities/capability-data.d.ts +52 -0
- package/dist/capabilities/capability-data.js +88 -0
- package/dist/capabilities/capability-state.d.ts +2 -4
- package/dist/capabilities/capability-state.js +5 -23
- package/dist/capabilities/capability.d.ts +203 -38
- package/dist/capabilities/compaction/index.js +10 -4
- package/dist/capabilities/compaction/service.d.ts +20 -5
- package/dist/capabilities/compaction/service.js +27 -11
- package/dist/capabilities/goal/goal-store.d.ts +76 -12
- package/dist/capabilities/goal/goal-store.js +137 -53
- package/dist/capabilities/goal/index.d.ts +1 -1
- package/dist/capabilities/goal/index.js +30 -7
- package/dist/capabilities/index.d.ts +9 -6
- package/dist/capabilities/index.js +4 -3
- package/dist/capabilities/plan/index.js +22 -5
- package/dist/capabilities/plan/plan-mode.d.ts +30 -9
- package/dist/capabilities/plan/plan-mode.js +57 -32
- package/dist/capabilities/plan/tools.js +1 -1
- package/dist/capabilities/skills/flow-provider.js +3 -3
- package/dist/capabilities/skills/index.d.ts +13 -1
- package/dist/capabilities/skills/index.js +30 -21
- package/dist/capabilities/skills/parser.d.ts +2 -2
- package/dist/capabilities/skills/parser.js +3 -3
- package/dist/capabilities/skills/registry.d.ts +5 -6
- package/dist/capabilities/skills/registry.js +6 -9
- package/dist/capabilities/skills/scanner.d.ts +3 -3
- package/dist/capabilities/skills/scanner.js +14 -14
- package/dist/capabilities/skills/service.d.ts +2 -1
- package/dist/capabilities/skills/service.js +3 -3
- package/dist/capabilities/skills/skill-tool.d.ts +2 -0
- package/dist/capabilities/skills/skill-tool.js +1 -1
- package/dist/capabilities/task/index.js +2 -1
- package/dist/capabilities/task/persist-disk.d.ts +1 -1
- package/dist/capabilities/task/persist-disk.js +1 -1
- package/dist/capabilities/task/persist.js +1 -1
- package/dist/capabilities/todo/index.js +11 -6
- package/dist/capabilities/todo/injector.js +2 -1
- package/dist/capabilities/todo/todo-store.d.ts +28 -7
- package/dist/capabilities/todo/todo-store.js +44 -11
- package/dist/capabilities/todo/tools.js +8 -3
- package/dist/capabilities/tool-provider.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.d.ts +3 -3
- package/dist/capabilities/user-hooks/engine.js +7 -7
- package/dist/capabilities/user-hooks/index.js +2 -1
- package/dist/capabilities/workflow/index.d.ts +5 -3
- package/dist/capabilities/workflow/index.js +3 -2
- package/dist/commands/index.js +34 -32
- package/dist/config/index.d.ts +1 -1
- package/dist/config/provider-manager.js +0 -28
- package/dist/config/schema.d.ts +53 -4
- package/dist/config/schema.js +53 -1
- package/dist/events/events.d.ts +43 -11
- package/dist/events/events.js +1 -0
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/projection.d.ts +49 -1
- package/dist/events/projection.js +144 -19
- package/dist/events/publisher.js +2 -21
- package/dist/home.d.ts +1 -1
- package/dist/home.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.js +5 -2
- package/dist/llm/define-model.d.ts +4 -0
- package/dist/llm/define-model.js +63 -25
- package/dist/llm/index.d.ts +1 -0
- package/dist/llm/index.js +1 -0
- package/dist/llm/model.d.ts +2 -0
- package/dist/llm/provider.d.ts +17 -0
- package/dist/llm/provider.js +14 -0
- package/dist/llm/retry.js +1 -1
- package/dist/loop/context.d.ts +21 -1
- package/dist/loop/context.js +47 -9
- package/dist/loop/events.d.ts +5 -1
- package/dist/loop/index.d.ts +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/interruption.d.ts +9 -4
- package/dist/loop/interruption.js +11 -25
- package/dist/loop/run-turn.d.ts +16 -3
- package/dist/loop/run-turn.js +13 -4
- package/dist/loop/steer.d.ts +78 -12
- package/dist/loop/steer.js +101 -38
- package/dist/loop/tool-call.d.ts +13 -2
- package/dist/loop/tool-call.js +135 -5
- package/dist/loop/turn-step.d.ts +13 -2
- package/dist/loop/turn-step.js +29 -7
- package/dist/loop/types.d.ts +6 -0
- package/dist/mcp/auth-tool.d.ts +3 -1
- package/dist/mcp/auth-tool.js +2 -2
- package/dist/mcp/capability.d.ts +13 -0
- package/dist/mcp/capability.js +36 -17
- package/dist/mcp/config-loader.d.ts +5 -5
- package/dist/mcp/config-loader.js +17 -17
- package/dist/mcp/credentials.d.ts +35 -0
- package/dist/mcp/credentials.js +2 -0
- package/dist/mcp/filter.d.ts +2 -2
- package/dist/mcp/index.d.ts +4 -3
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/manager.d.ts +108 -6
- package/dist/mcp/manager.js +262 -18
- package/dist/mcp/oauth/callback-server.d.ts +10 -1
- package/dist/mcp/oauth/callback-server.js +82 -16
- package/dist/mcp/oauth/index.d.ts +2 -2
- package/dist/mcp/oauth/provider.d.ts +18 -0
- package/dist/mcp/oauth/provider.js +31 -1
- package/dist/mcp/oauth/service.d.ts +9 -3
- package/dist/mcp/oauth/service.js +29 -4
- package/dist/mcp/sdk-transport.js +1 -1
- package/dist/mcp/server.js +1 -1
- package/dist/permission/auto-approver/prompts-data.d.ts +1 -1
- package/dist/permission/auto-approver/prompts-data.js +1 -1
- package/dist/permission/manager.d.ts +5 -3
- package/dist/permission/manager.js +7 -3
- package/dist/permission/policies.d.ts +2 -2
- package/dist/permission/policies.js +4 -4
- package/dist/plugins/fields.d.ts +14 -0
- package/dist/plugins/fields.js +30 -0
- package/dist/plugins/hooks.d.ts +2 -2
- package/dist/plugins/hooks.js +12 -12
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/manager.d.ts +8 -3
- package/dist/plugins/manager.js +18 -7
- package/dist/plugins/manifest.d.ts +2 -2
- package/dist/plugins/manifest.js +101 -91
- package/dist/plugins/marketplace.js +76 -57
- package/dist/plugins/store.d.ts +3 -3
- package/dist/plugins/store.js +6 -6
- package/dist/protocol/index.d.ts +1 -1
- package/dist/store/catalog-store.d.ts +4 -1
- package/dist/store/catalog-store.js +5 -1
- package/dist/store/checkpointing-store.d.ts +41 -0
- package/dist/store/checkpointing-store.js +86 -0
- package/dist/store/disk-store.d.ts +8 -0
- package/dist/store/disk-store.js +127 -5
- package/dist/store/index.d.ts +3 -2
- package/dist/store/index.js +2 -1
- package/dist/store/log-store.d.ts +9 -1
- package/dist/store/log-store.js +68 -4
- package/dist/store/migrate.d.ts +8 -2
- package/dist/store/migrate.js +9 -2
- package/dist/store/origin.d.ts +31 -6
- package/dist/store/origin.js +0 -14
- package/dist/store/pg.d.ts +1 -0
- package/dist/store/pg.js +37 -2
- package/dist/store/redis.d.ts +1 -0
- package/dist/store/redis.js +30 -0
- package/dist/store/repository.d.ts +13 -1
- package/dist/store/repository.js +45 -2
- package/dist/store/session-catalog.d.ts +4 -0
- package/dist/store/session-catalog.js +6 -0
- package/dist/store/storage.js +3 -0
- package/dist/store/store.d.ts +97 -34
- package/dist/store/store.js +64 -10
- package/dist/telemetry/appender.d.ts +43 -0
- package/dist/telemetry/appender.js +46 -0
- package/dist/telemetry/events.d.ts +142 -0
- package/dist/telemetry/events.js +141 -0
- package/dist/telemetry/index.d.ts +10 -0
- package/dist/telemetry/index.js +6 -0
- package/dist/telemetry/projection.d.ts +23 -0
- package/dist/telemetry/projection.js +185 -0
- package/dist/telemetry/redact.d.ts +20 -0
- package/dist/telemetry/redact.js +40 -0
- package/dist/telemetry/service.d.ts +49 -0
- package/dist/telemetry/service.js +137 -0
- package/dist/testing.d.ts +58 -0
- package/dist/testing.js +123 -0
- package/dist/tool/background.d.ts +9 -6
- package/dist/tool/background.js +7 -1
- package/dist/tool/builtin/ask-user-question.js +6 -5
- package/dist/tool/builtin/bash.d.ts +6 -0
- package/dist/tool/builtin/bash.js +79 -42
- package/dist/tool/builtin/edit.js +82 -109
- package/dist/tool/builtin/glob.js +13 -13
- package/dist/tool/builtin/grep.js +13 -13
- package/dist/tool/builtin/read.js +25 -15
- package/dist/tool/builtin/write.js +49 -33
- package/dist/tool/define.d.ts +14 -8
- package/dist/tool/define.js +8 -2
- package/dist/tool/{machine-base.d.ts → environment-base.d.ts} +37 -37
- package/dist/tool/{machine-base.js → environment-base.js} +45 -119
- package/dist/tool/{machine-local.d.ts → environment-local.d.ts} +9 -8
- package/dist/tool/{machine-local.js → environment-local.js} +60 -81
- package/dist/tool/{machine-null.d.ts → environment-null.d.ts} +9 -9
- package/dist/tool/{machine-null.js → environment-null.js} +9 -9
- package/dist/tool/{machine-ssh.d.ts → environment-ssh.d.ts} +33 -18
- package/dist/tool/{machine-ssh.js → environment-ssh.js} +118 -149
- package/dist/tool/{machine.d.ts → environment.d.ts} +53 -82
- package/dist/tool/environment.js +2 -0
- package/dist/tool/file-freshness.d.ts +33 -19
- package/dist/tool/file-freshness.js +39 -30
- package/dist/tool/filesystem-tools.d.ts +1 -1
- package/dist/tool/filesystem-tools.js +1 -1
- package/dist/tool/git-context.d.ts +2 -2
- package/dist/tool/git-context.js +8 -8
- package/dist/tool/index.d.ts +12 -12
- package/dist/tool/index.js +12 -10
- package/dist/tool/policies/path-access.d.ts +4 -4
- package/dist/tool/policies/path-access.js +12 -12
- package/dist/tool/questions.d.ts +8 -0
- package/dist/tool/search/catalog.d.ts +37 -0
- package/dist/tool/search/catalog.js +182 -0
- package/dist/tool/search/deferral.d.ts +3 -2
- package/dist/tool/search/loaded.d.ts +32 -0
- package/dist/tool/search/loaded.js +96 -0
- package/dist/tool/search/search-tool.d.ts +2 -6
- package/dist/tool/search/search-tool.js +16 -15
- package/dist/tool/shell-env.js +4 -0
- package/dist/tool/support/bash-paths.js +38 -7
- package/dist/tool/support/{machine-ops.d.ts → environment-ops.d.ts} +12 -14
- package/dist/tool/support/{machine-ops.js → environment-ops.js} +21 -2
- package/dist/tool/support/git-worktree.d.ts +3 -3
- package/dist/tool/support/git-worktree.js +6 -6
- package/dist/tool/support/rg-locator.d.ts +6 -6
- package/dist/tool/support/rg-locator.js +6 -6
- package/dist/tool/support/ripgrep-run.d.ts +5 -5
- package/dist/tool/support/ripgrep-run.js +3 -3
- package/dist/tool/support/tool-path.d.ts +3 -3
- package/dist/tool/support/tool-path.js +7 -7
- package/dist/tool/types.d.ts +54 -10
- package/dist/tool/web/fetch-url.js +1 -1
- package/dist/tool/web/web-search.js +1 -1
- package/dist/tool/workspace-spec.d.ts +3 -3
- package/dist/tool/workspace-spec.js +27 -27
- package/dist/tracing/bridge.d.ts +9 -1
- package/dist/tracing/bridge.js +307 -77
- package/dist/tracing/index.d.ts +2 -2
- package/dist/tracing/otel.d.ts +28 -1
- package/dist/tracing/otel.js +150 -38
- package/dist/tracing/processor.d.ts +22 -0
- package/dist/tracing/processor.js +2 -0
- package/dist/tracing/spans.d.ts +54 -0
- package/dist/tracing/spans.js +5 -0
- package/package.json +6 -2
- package/dist/tool/machine.js +0 -15
- package/dist/tool/search/activation.d.ts +0 -13
- package/dist/tool/search/activation.js +0 -31
|
@@ -6,7 +6,7 @@ export function flowSkillToolName(skillName) {
|
|
|
6
6
|
const suffix = skillName.replace(/[^a-zA-Z0-9_-]+/g, "_").toLowerCase() || "skill";
|
|
7
7
|
return `skill_${suffix}`;
|
|
8
8
|
}
|
|
9
|
-
function flowSkillTool(skill, registry, executor) {
|
|
9
|
+
function flowSkillTool(skill, registry, executor, sessionId) {
|
|
10
10
|
const toolName = flowSkillToolName(skill.name);
|
|
11
11
|
return defineTool({
|
|
12
12
|
name: toolName,
|
|
@@ -34,7 +34,7 @@ function flowSkillTool(skill, registry, executor) {
|
|
|
34
34
|
isError: true,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
const instructions = registry.renderSkillPrompt(skill, "");
|
|
37
|
+
const instructions = registry.renderSkillPrompt(skill, "", sessionId);
|
|
38
38
|
const output = await executor({ skill, instructions, input: args.input, signal: ctx.signal });
|
|
39
39
|
return { content: [{ type: "text", text: output }], details: { skill: skill.name, source: skill.source } };
|
|
40
40
|
},
|
|
@@ -44,7 +44,7 @@ function flowSkillTool(skill, registry, executor) {
|
|
|
44
44
|
export function flowSkillProvider(registry, executor) {
|
|
45
45
|
return {
|
|
46
46
|
id: "skill-flow",
|
|
47
|
-
listTools: () => registry.listFlowSkills().map((skill) => flowSkillTool(skill, registry, executor)),
|
|
47
|
+
listTools: (ctx) => registry.listFlowSkills().map((skill) => flowSkillTool(skill, registry, executor, ctx.sessionId)),
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
//# sourceMappingURL=flow-provider.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Capability } from "../capability.ts";
|
|
2
|
+
import type { Environment } from "../../tool/environment.ts";
|
|
2
3
|
import { SkillRegistry } from "./registry.ts";
|
|
3
4
|
import type { FlowSkillExecutor, SkillDefinition, SkillRoot } from "./types.ts";
|
|
4
5
|
export type { SkillRegistryOptions } from "./registry.ts";
|
|
5
6
|
export { SkillRegistry, SkillNotFoundError } from "./registry.ts";
|
|
6
|
-
export { parseSkillText,
|
|
7
|
+
export { parseSkillText, parseSkillFromEnvironment, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, } from "./parser.ts";
|
|
7
8
|
export { discoverSkills, resolveSkillRoots } from "./scanner.ts";
|
|
8
9
|
export type { ResolveSkillRootsOptions, DiscoverSkillsOptions } from "./scanner.ts";
|
|
9
10
|
export { skillTool, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError } from "./skill-tool.ts";
|
|
@@ -14,7 +15,11 @@ export type { ActivateSkillRequest, SkillActivationResult, SkillActivationTrigge
|
|
|
14
15
|
export { normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./types.ts";
|
|
15
16
|
export type { SkillCatalog, SkillDefinition, SkillMetadata, SkillSource, SkillSummary, SkillRoot, SkillPluginContext, SkippedSkill, FlowSkillExecutor, FlowSkillRequest, } from "./types.ts";
|
|
16
17
|
export interface SkillsOptions {
|
|
18
|
+
/** A pre-built registry — e.g. the harness's shared one (`HarnessParts.skillRegistry`). */
|
|
17
19
|
readonly registry?: SkillRegistry;
|
|
20
|
+
/** `false` = the registry is already loaded (the harness scanned it once); skip the per-session
|
|
21
|
+
* scan and only bind this session to it. Default `true`. */
|
|
22
|
+
readonly scan?: boolean;
|
|
18
23
|
readonly roots?: readonly SkillRoot[];
|
|
19
24
|
/**
|
|
20
25
|
* Additional skill roots resolved lazily at session-open (merged after `roots`). Use this for
|
|
@@ -39,5 +44,12 @@ export interface SkillsOptions {
|
|
|
39
44
|
readonly flowExecutor?: FlowSkillExecutor;
|
|
40
45
|
readonly onWarning?: (message: string, cause?: unknown) => void;
|
|
41
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Scan the skill roots into `registry` — the static roots, the lazily-provided ones (e.g. enabled
|
|
49
|
+
* plugins' skill dirs), and the default project/user roots when asked. Called per session by
|
|
50
|
+
* `skillsCapability` (unless `scan: false`), or once per process by a host that shares one
|
|
51
|
+
* registry across all its sessions.
|
|
52
|
+
*/
|
|
53
|
+
export declare function loadSkillRoots(environment: Environment, registry: SkillRegistry, options?: Omit<SkillsOptions, "registry" | "scan" | "flowExecutor" | "onWarning">): Promise<void>;
|
|
42
54
|
export declare function skillsCapability(options?: SkillsOptions): Capability;
|
|
43
55
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -5,42 +5,51 @@ import { flowSkillProvider } from "./flow-provider.js";
|
|
|
5
5
|
import { SkillCatalogInjector } from "./injector.js";
|
|
6
6
|
import { SkillsService } from "./service.js";
|
|
7
7
|
export { SkillRegistry, SkillNotFoundError } from "./registry.js";
|
|
8
|
-
export { parseSkillText,
|
|
8
|
+
export { parseSkillText, parseSkillFromEnvironment, parseFrontmatter, expandSkillParameters, skillArgumentNames, SkillParseError, FrontmatterError, UnsupportedSkillTypeError, } from "./parser.js";
|
|
9
9
|
export { discoverSkills, resolveSkillRoots } from "./scanner.js";
|
|
10
10
|
export { skillTool, MAX_SKILL_QUERY_DEPTH, NestedSkillTooDeepError } from "./skill-tool.js";
|
|
11
11
|
export { flowSkillProvider, flowSkillToolName } from "./flow-provider.js";
|
|
12
12
|
export { SkillCatalogInjector } from "./injector.js";
|
|
13
13
|
export { SkillsService, UnsupportedSkillActivationError } from "./service.js";
|
|
14
14
|
export { normalizeSkillName, isInlineSkillType, isFlowSkillType, isUserActivatableSkillType, isSupportedSkillType, summarizeSkill, } from "./types.js";
|
|
15
|
+
/**
|
|
16
|
+
* Scan the skill roots into `registry` — the static roots, the lazily-provided ones (e.g. enabled
|
|
17
|
+
* plugins' skill dirs), and the default project/user roots when asked. Called per session by
|
|
18
|
+
* `skillsCapability` (unless `scan: false`), or once per process by a host that shares one
|
|
19
|
+
* registry across all its sessions.
|
|
20
|
+
*/
|
|
21
|
+
export async function loadSkillRoots(environment, registry, options = {}) {
|
|
22
|
+
for (const skill of options.builtinSkills ?? [])
|
|
23
|
+
registry.registerBuiltinSkill(skill);
|
|
24
|
+
const dynamic = options.dynamicRoots ? await options.dynamicRoots() : [];
|
|
25
|
+
const explicitRoots = [...(options.roots ?? []), ...dynamic];
|
|
26
|
+
const roots = await resolveSkillRoots(environment, {
|
|
27
|
+
...(explicitRoots.length > 0 ? { explicitRoots } : {}),
|
|
28
|
+
...(options.includeDefaultRoots === true ? { includeDefaults: true } : {}),
|
|
29
|
+
// Default the project root to the environment's working directory, so `<cwd>/.agents/skills`
|
|
30
|
+
// is scanned for the directory this environment actually operates.
|
|
31
|
+
projectDir: options.projectDir ?? environment.getcwd(),
|
|
32
|
+
...(options.userHomeDir !== undefined ? { userHomeDir: options.userHomeDir } : {}),
|
|
33
|
+
...(options.builtinDir !== undefined ? { builtinDir: options.builtinDir } : {}),
|
|
34
|
+
...(options.extraDirs !== undefined ? { extraDirs: options.extraDirs } : {}),
|
|
35
|
+
});
|
|
36
|
+
await registry.loadRoots(environment, roots);
|
|
37
|
+
}
|
|
15
38
|
export function skillsCapability(options = {}) {
|
|
16
39
|
const registry = options.registry ?? new SkillRegistry({ onWarning: options.onWarning });
|
|
17
40
|
const service = new SkillsService(registry);
|
|
41
|
+
let sessionId;
|
|
18
42
|
return {
|
|
19
43
|
name: "skills",
|
|
20
|
-
|
|
44
|
+
contract: "detachable",
|
|
45
|
+
tools: [skillTool(registry, { sessionId: () => sessionId })],
|
|
21
46
|
toolProviders: [flowSkillProvider(registry, options.flowExecutor)],
|
|
22
47
|
injectors: [new SkillCatalogInjector(registry)],
|
|
23
48
|
service,
|
|
24
49
|
openSession: async (ctx) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
registry
|
|
28
|
-
// Static roots + any lazily-provided ones (e.g. enabled plugins' skill dirs). The provider
|
|
29
|
-
// runs per session-open so it reflects the current set even though the harness is shared.
|
|
30
|
-
const dynamic = options.dynamicRoots ? await options.dynamicRoots() : [];
|
|
31
|
-
const explicitRoots = [...(options.roots ?? []), ...dynamic];
|
|
32
|
-
const roots = await resolveSkillRoots(ctx.machine, {
|
|
33
|
-
...(explicitRoots.length > 0 ? { explicitRoots } : {}),
|
|
34
|
-
...(options.includeDefaultRoots === true ? { includeDefaults: true } : {}),
|
|
35
|
-
// Default the project root to the session's working directory so
|
|
36
|
-
// `<cwd>/.agents/skills` is scanned per-session (the harness is shared,
|
|
37
|
-
// so this can't be a static option).
|
|
38
|
-
projectDir: options.projectDir ?? ctx.machine.getcwd(),
|
|
39
|
-
...(options.userHomeDir !== undefined ? { userHomeDir: options.userHomeDir } : {}),
|
|
40
|
-
...(options.builtinDir !== undefined ? { builtinDir: options.builtinDir } : {}),
|
|
41
|
-
...(options.extraDirs !== undefined ? { extraDirs: options.extraDirs } : {}),
|
|
42
|
-
});
|
|
43
|
-
await registry.loadRoots(ctx.machine, roots);
|
|
50
|
+
sessionId = ctx.sessionId;
|
|
51
|
+
if (options.scan !== false)
|
|
52
|
+
await loadSkillRoots(ctx.environment, registry, options);
|
|
44
53
|
service.attach({ sessionId: ctx.sessionId, events: ctx.events, steer: ctx.steer });
|
|
45
54
|
},
|
|
46
55
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Environment } from "../../tool/environment.ts";
|
|
2
2
|
import type { SkillDefinition, SkillMetadata, SkillSource } from "./types.ts";
|
|
3
3
|
export declare class FrontmatterError extends Error {
|
|
4
4
|
constructor(message: string, cause?: unknown);
|
|
@@ -28,7 +28,7 @@ export interface ParsedFrontmatter {
|
|
|
28
28
|
readonly data: Record<string, unknown> | null;
|
|
29
29
|
readonly body: string;
|
|
30
30
|
}
|
|
31
|
-
export declare function
|
|
31
|
+
export declare function parseSkillFromEnvironment(environment: Environment, options: ParseSkillOptions): Promise<SkillDefinition>;
|
|
32
32
|
export declare function parseFrontmatter(text: string): ParsedFrontmatter;
|
|
33
33
|
export declare function parseSkillText(options: ParseSkillTextOptions): SkillDefinition;
|
|
34
34
|
export declare function expandSkillParameters(body: string, rawArgs: string, context: SkillExpandContext): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "pathe";
|
|
2
2
|
import { isSupportedSkillType } from "./types.js";
|
|
3
|
-
import { readTextFile } from "../../tool/support/
|
|
3
|
+
import { readTextFile } from "../../tool/support/environment-ops.js";
|
|
4
4
|
export class FrontmatterError extends Error {
|
|
5
5
|
constructor(message, cause) {
|
|
6
6
|
super(message);
|
|
@@ -33,10 +33,10 @@ const METADATA_ALIASES = {
|
|
|
33
33
|
"disable-model-invocation": "disableModelInvocation",
|
|
34
34
|
disable_model_invocation: "disableModelInvocation",
|
|
35
35
|
};
|
|
36
|
-
export async function
|
|
36
|
+
export async function parseSkillFromEnvironment(environment, options) {
|
|
37
37
|
let text;
|
|
38
38
|
try {
|
|
39
|
-
text = await readTextFile(
|
|
39
|
+
text = await readTextFile(environment, options.skillMdPath);
|
|
40
40
|
}
|
|
41
41
|
catch (error) {
|
|
42
42
|
throw new SkillParseError(`Failed to read ${options.skillMdPath}`, error);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Environment } from "../../tool/environment.ts";
|
|
2
2
|
import type { SkillCatalog, SkillDefinition, SkillRoot, SkippedSkill } from "./types.ts";
|
|
3
3
|
export declare class SkillNotFoundError extends Error {
|
|
4
4
|
readonly skillName: string;
|
|
@@ -6,17 +6,14 @@ export declare class SkillNotFoundError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
export interface SkillRegistryOptions {
|
|
8
8
|
readonly onWarning?: (message: string, cause?: unknown) => void;
|
|
9
|
-
readonly sessionId?: string;
|
|
10
9
|
}
|
|
11
10
|
export declare class SkillRegistry implements SkillCatalog {
|
|
12
11
|
private readonly byName;
|
|
13
12
|
private readonly roots;
|
|
14
13
|
private readonly skipped;
|
|
15
14
|
private readonly onWarning;
|
|
16
|
-
private sessionId?;
|
|
17
15
|
constructor(options?: SkillRegistryOptions);
|
|
18
|
-
|
|
19
|
-
loadRoots(machine: Machine, roots: readonly SkillRoot[]): Promise<void>;
|
|
16
|
+
loadRoots(environment: Environment, roots: readonly SkillRoot[]): Promise<void>;
|
|
20
17
|
registerBuiltinSkill(skill: SkillDefinition): void;
|
|
21
18
|
register(skill: SkillDefinition, options?: {
|
|
22
19
|
readonly replace?: boolean;
|
|
@@ -27,7 +24,9 @@ export declare class SkillRegistry implements SkillCatalog {
|
|
|
27
24
|
listFlowSkills(): readonly SkillDefinition[];
|
|
28
25
|
getSkillRoots(): readonly string[];
|
|
29
26
|
getSkippedByPolicy(): readonly SkippedSkill[];
|
|
30
|
-
|
|
27
|
+
/** `sessionId` fills `${SESSION_ID}`: the registry is shareable across sessions, so the
|
|
28
|
+
* caller (a session's tool or service) supplies its own. */
|
|
29
|
+
renderSkillPrompt(skill: SkillDefinition, rawArgs: string, sessionId?: string): string;
|
|
31
30
|
getModelSkillListing(): string;
|
|
32
31
|
}
|
|
33
32
|
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -15,20 +15,15 @@ export class SkillRegistry {
|
|
|
15
15
|
roots = [];
|
|
16
16
|
skipped = [];
|
|
17
17
|
onWarning;
|
|
18
|
-
sessionId;
|
|
19
18
|
constructor(options = {}) {
|
|
20
19
|
this.onWarning = options.onWarning ?? (() => { });
|
|
21
|
-
this.sessionId = options.sessionId;
|
|
22
20
|
}
|
|
23
|
-
|
|
24
|
-
this.sessionId = sessionId;
|
|
25
|
-
}
|
|
26
|
-
async loadRoots(machine, roots) {
|
|
21
|
+
async loadRoots(environment, roots) {
|
|
27
22
|
for (const root of roots) {
|
|
28
23
|
if (!this.roots.includes(root.path))
|
|
29
24
|
this.roots.push(root.path);
|
|
30
25
|
}
|
|
31
|
-
const skills = await discoverSkills(
|
|
26
|
+
const skills = await discoverSkills(environment, {
|
|
32
27
|
roots,
|
|
33
28
|
onWarning: this.onWarning,
|
|
34
29
|
onSkippedByPolicy: (skill) => this.skipped.push(skill),
|
|
@@ -65,10 +60,12 @@ export class SkillRegistry {
|
|
|
65
60
|
getSkippedByPolicy() {
|
|
66
61
|
return [...this.skipped];
|
|
67
62
|
}
|
|
68
|
-
|
|
63
|
+
/** `sessionId` fills `${SESSION_ID}`: the registry is shareable across sessions, so the
|
|
64
|
+
* caller (a session's tool or service) supplies its own. */
|
|
65
|
+
renderSkillPrompt(skill, rawArgs, sessionId) {
|
|
69
66
|
const content = expandSkillParameters(skill.content, rawArgs, {
|
|
70
67
|
skillDir: skill.dir,
|
|
71
|
-
sessionId
|
|
68
|
+
sessionId,
|
|
72
69
|
argumentNames: skillArgumentNames(skill.metadata),
|
|
73
70
|
});
|
|
74
71
|
const plugin = skill.plugin;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Environment } from "../../tool/environment.ts";
|
|
2
2
|
import type { SkillDefinition, SkillRoot, SkippedSkill } from "./types.ts";
|
|
3
3
|
export interface ResolveSkillRootsOptions {
|
|
4
4
|
readonly projectDir?: string;
|
|
@@ -21,6 +21,6 @@ export interface DiscoverSkillsOptions {
|
|
|
21
21
|
readonly onSkippedByPolicy?: (skill: SkippedSkill) => void;
|
|
22
22
|
readonly onDiscoveredSkill?: (skill: SkillDefinition) => void;
|
|
23
23
|
}
|
|
24
|
-
export declare function resolveSkillRoots(
|
|
25
|
-
export declare function discoverSkills(
|
|
24
|
+
export declare function resolveSkillRoots(environment: Environment, options: ResolveSkillRootsOptions): Promise<readonly SkillRoot[]>;
|
|
25
|
+
export declare function discoverSkills(environment: Environment, options: DiscoverSkillsOptions): Promise<readonly SkillDefinition[]>;
|
|
26
26
|
//# sourceMappingURL=scanner.d.ts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import path from "pathe";
|
|
3
|
-
import { SkillParseError, UnsupportedSkillTypeError,
|
|
3
|
+
import { SkillParseError, UnsupportedSkillTypeError, parseSkillFromEnvironment } from "./parser.js";
|
|
4
4
|
import { normalizeSkillName } from "./types.js";
|
|
5
5
|
const PROJECT_SKILL_DIR = ".agents/skills";
|
|
6
6
|
const USER_SKILL_DIR = ".agents/skills";
|
|
7
7
|
const MAX_SKILL_SCAN_DEPTH = 8;
|
|
8
|
-
async function statKind(
|
|
8
|
+
async function statKind(environment, p) {
|
|
9
9
|
try {
|
|
10
|
-
const kind = (await
|
|
10
|
+
const kind = (await environment.fileInfo(p)).kind;
|
|
11
11
|
if (kind === "dir")
|
|
12
12
|
return "dir";
|
|
13
13
|
if (kind === "file")
|
|
@@ -18,29 +18,29 @@ async function statKind(machine, p) {
|
|
|
18
18
|
return "none";
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
async function listDir(
|
|
21
|
+
async function listDir(environment, p) {
|
|
22
22
|
// Sorted so first-wins collision resolution across siblings is deterministic.
|
|
23
|
-
return (await
|
|
23
|
+
return (await environment.listDir(p)).toSorted((a, b) => a.name.localeCompare(b.name));
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* The listing's kind, with symlinks resolved to what they point AT — a skills root full of
|
|
27
27
|
* symlinked bundles is normal, and treating those as neither file nor dir would silently
|
|
28
28
|
* hide them. Only `"symlink"` entries cost a stat; everything else is already decided.
|
|
29
29
|
*/
|
|
30
|
-
async function resolveEntryKind(
|
|
30
|
+
async function resolveEntryKind(environment, dirPath, entry) {
|
|
31
31
|
if (entry.kind === "dir")
|
|
32
32
|
return "dir";
|
|
33
33
|
if (entry.kind === "file")
|
|
34
34
|
return "file";
|
|
35
35
|
if (entry.kind !== "symlink")
|
|
36
36
|
return "none";
|
|
37
|
-
return statKind(
|
|
37
|
+
return statKind(environment, path.join(dirPath, entry.name));
|
|
38
38
|
}
|
|
39
|
-
export async function resolveSkillRoots(
|
|
39
|
+
export async function resolveSkillRoots(environment, options) {
|
|
40
40
|
const roots = [];
|
|
41
41
|
const push = async (dir, source, plugin) => {
|
|
42
42
|
const resolved = path.resolve(dir);
|
|
43
|
-
if ((await statKind(
|
|
43
|
+
if ((await statKind(environment, resolved)) !== "dir")
|
|
44
44
|
return;
|
|
45
45
|
if (roots.some((root) => root.path === resolved))
|
|
46
46
|
return;
|
|
@@ -62,7 +62,7 @@ export async function resolveSkillRoots(machine, options) {
|
|
|
62
62
|
await push(options.builtinDir, "builtin");
|
|
63
63
|
return roots;
|
|
64
64
|
}
|
|
65
|
-
export async function discoverSkills(
|
|
65
|
+
export async function discoverSkills(environment, options) {
|
|
66
66
|
const warn = options.onWarning ?? (() => { });
|
|
67
67
|
const skip = options.onSkippedByPolicy ?? (() => { });
|
|
68
68
|
const byName = new Map();
|
|
@@ -73,7 +73,7 @@ export async function discoverSkills(machine, options) {
|
|
|
73
73
|
*/
|
|
74
74
|
const parseSkill = async (skillMdPath, skillDirName, root) => {
|
|
75
75
|
try {
|
|
76
|
-
const parsed = await
|
|
76
|
+
const parsed = await parseSkillFromEnvironment(environment, { skillMdPath, skillDirName, source: root.source });
|
|
77
77
|
return root.plugin === undefined ? parsed : { ...parsed, plugin: root.plugin };
|
|
78
78
|
}
|
|
79
79
|
catch (error) {
|
|
@@ -102,13 +102,13 @@ export async function discoverSkills(machine, options) {
|
|
|
102
102
|
return [];
|
|
103
103
|
let entries;
|
|
104
104
|
try {
|
|
105
|
-
entries = await listDir(
|
|
105
|
+
entries = await listDir(environment, dirPath);
|
|
106
106
|
}
|
|
107
107
|
catch (error) {
|
|
108
108
|
warn(`Failed to read skill directory ${dirPath}`, error);
|
|
109
109
|
return [];
|
|
110
110
|
}
|
|
111
|
-
const kinds = await Promise.all(entries.map((entry) => resolveEntryKind(
|
|
111
|
+
const kinds = await Promise.all(entries.map((entry) => resolveEntryKind(environment, dirPath, entry)));
|
|
112
112
|
const dirNames = [];
|
|
113
113
|
const fileNames = [];
|
|
114
114
|
for (const [i, entry] of entries.entries()) {
|
|
@@ -119,7 +119,7 @@ export async function discoverSkills(machine, options) {
|
|
|
119
119
|
}
|
|
120
120
|
// A directory is a bundle iff it holds a SKILL.md. Probed for directories only — the old
|
|
121
121
|
// scan asked this of every entry, including plain files, which can never answer yes.
|
|
122
|
-
const bundleFlags = await Promise.all(dirNames.map(async (name) => (await statKind(
|
|
122
|
+
const bundleFlags = await Promise.all(dirNames.map(async (name) => (await statKind(environment, path.join(dirPath, name, "SKILL.md"))) === "file"));
|
|
123
123
|
const bundles = new Set(dirNames.filter((_, i) => bundleFlags[i]));
|
|
124
124
|
const bundleSkills = await Promise.all([...bundles].map((name) => parseSkill(path.join(dirPath, name, "SKILL.md"), name, root)));
|
|
125
125
|
// Flat `.md` skills count only at a root's top level; deeper `.md` files are payload.
|
|
@@ -16,7 +16,8 @@ export interface SkillActivationResult {
|
|
|
16
16
|
readonly trigger: SkillActivationTrigger;
|
|
17
17
|
readonly skillPath: string;
|
|
18
18
|
readonly skillSource: SkillSource;
|
|
19
|
-
|
|
19
|
+
/** Matches `steer.queued.steerId` and the consuming `message.appended.origin.steerId`. */
|
|
20
|
+
readonly steerId: string;
|
|
20
21
|
}
|
|
21
22
|
export declare class UnsupportedSkillActivationError extends Error {
|
|
22
23
|
readonly skillName: string;
|
|
@@ -36,10 +36,10 @@ export class SkillsService {
|
|
|
36
36
|
const activationId = randomUUID();
|
|
37
37
|
const skillArgs = request.args ?? "";
|
|
38
38
|
const trigger = request.trigger ?? "user-slash";
|
|
39
|
-
const body = this.registry.renderSkillPrompt(skill, skillArgs);
|
|
39
|
+
const body = this.registry.renderSkillPrompt(skill, skillArgs, runtime.sessionId);
|
|
40
40
|
const argsAttr = skillArgs.length > 0 ? ` args="${escapeXmlAttr(skillArgs)}"` : "";
|
|
41
41
|
const wrapped = systemReminder(`<skill-loaded name="${escapeXmlAttr(skill.name)}"${argsAttr}>\n${body}\n</skill-loaded>`);
|
|
42
|
-
const {
|
|
42
|
+
const { steerId } = runtime.steer.steer(wrapped, { kind: "user" });
|
|
43
43
|
await runtime.events.emit({
|
|
44
44
|
type: "skill.activated",
|
|
45
45
|
address: request.address ?? "main",
|
|
@@ -58,7 +58,7 @@ export class SkillsService {
|
|
|
58
58
|
trigger,
|
|
59
59
|
skillPath: skill.path,
|
|
60
60
|
skillSource: skill.source,
|
|
61
|
-
|
|
61
|
+
steerId,
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -8,6 +8,8 @@ export declare class NestedSkillTooDeepError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
export interface SkillToolOptions {
|
|
10
10
|
readonly initialQueryDepth?: number;
|
|
11
|
+
/** The session whose `${SESSION_ID}` a rendered skill expands to (the registry is shareable). */
|
|
12
|
+
readonly sessionId?: () => string | undefined;
|
|
11
13
|
}
|
|
12
14
|
export declare function skillTool(registry: SkillRegistry, options?: SkillToolOptions): Tool;
|
|
13
15
|
//# sourceMappingURL=skill-tool.d.ts.map
|
|
@@ -51,7 +51,7 @@ export function skillTool(registry, options = {}) {
|
|
|
51
51
|
return errorResult(`Skill "${skill.name}" is a flow skill — invoke it via its skill_${toToolSuffix(skill.name)} tool, not Skill.`);
|
|
52
52
|
}
|
|
53
53
|
const skillArgs = args.args ?? "";
|
|
54
|
-
const body = registry.renderSkillPrompt(skill, skillArgs);
|
|
54
|
+
const body = registry.renderSkillPrompt(skill, skillArgs, options.sessionId?.());
|
|
55
55
|
const argsAttr = skillArgs.length > 0 ? ` args="${escapeXmlAttr(skillArgs)}"` : "";
|
|
56
56
|
return {
|
|
57
57
|
content: [
|
|
@@ -18,9 +18,10 @@ export { taskCreateTool, taskUpdateTool, taskListTool, taskGetTool, renderTaskLi
|
|
|
18
18
|
export function taskCapability(store = new TaskStore()) {
|
|
19
19
|
return {
|
|
20
20
|
name: "task",
|
|
21
|
+
contract: "detachable",
|
|
21
22
|
tools: [taskCreateTool(store), taskUpdateTool(store), taskListTool(store), taskGetTool(store)],
|
|
22
|
-
service: store,
|
|
23
23
|
injectors: [new TaskListInjector(store)],
|
|
24
|
+
service: store,
|
|
24
25
|
openSession: async (ctx) => {
|
|
25
26
|
store.attach(makeTaskListPersistence(ctx.store));
|
|
26
27
|
await store.load();
|
|
@@ -2,7 +2,7 @@ import { type Task, type TaskListPersistence } from "./persist.ts";
|
|
|
2
2
|
/**
|
|
3
3
|
* Disk-directory task list: one JSON file per task under `<sessionDir>/tasklist/<id>.json`,
|
|
4
4
|
* co-located under the SessionStore's home (next
|
|
5
|
-
* to `agents/`, `blobs/`, `tasks/`), off the
|
|
5
|
+
* to `agents/`, `blobs/`, `tasks/`), off the Environment sandbox. Atomic writes (temp + rename)
|
|
6
6
|
* so a crash mid-write never leaves a torn file. Single live loop per session ⇒ no file locking.
|
|
7
7
|
*/
|
|
8
8
|
export declare class DiskTaskListPersistence implements TaskListPersistence {
|
|
@@ -7,7 +7,7 @@ const ID_RE = /^[A-Za-z0-9_-]+$/;
|
|
|
7
7
|
/**
|
|
8
8
|
* Disk-directory task list: one JSON file per task under `<sessionDir>/tasklist/<id>.json`,
|
|
9
9
|
* co-located under the SessionStore's home (next
|
|
10
|
-
* to `agents/`, `blobs/`, `tasks/`), off the
|
|
10
|
+
* to `agents/`, `blobs/`, `tasks/`), off the Environment sandbox. Atomic writes (temp + rename)
|
|
11
11
|
* so a crash mid-write never leaves a torn file. Single live loop per session ⇒ no file locking.
|
|
12
12
|
*/
|
|
13
13
|
export class DiskTaskListPersistence {
|
|
@@ -35,7 +35,7 @@ export function isValidTask(value) {
|
|
|
35
35
|
}
|
|
36
36
|
// ── SessionStore KV backend ──────────────────────────────────────────────────
|
|
37
37
|
// One key per task + an index + the high-water-mark, mirroring the background task store's KV
|
|
38
|
-
// backend. Kept off the
|
|
38
|
+
// backend. Kept off the Environment (agent bookkeeping, per the cron/background rule).
|
|
39
39
|
const INDEX_KEY = "tasklist:index";
|
|
40
40
|
const HWM_KEY = "tasklist:hwm";
|
|
41
41
|
const taskKey = (id) => `tasklist:task:${id}`;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { readSessionLog } from "../capability-state.js";
|
|
2
1
|
import { TodoListInjector } from "./injector.js";
|
|
3
2
|
import { TodoStore } from "./todo-store.js";
|
|
4
3
|
import { todoListTool } from "./tools.js";
|
|
@@ -8,13 +7,19 @@ export { TodoListInjector } from "./injector.js";
|
|
|
8
7
|
export function todoCapability(store = new TodoStore()) {
|
|
9
8
|
return {
|
|
10
9
|
name: "todo",
|
|
10
|
+
contract: "detachable",
|
|
11
11
|
tools: [todoListTool(store)],
|
|
12
|
-
service: store,
|
|
13
12
|
injectors: [new TodoListInjector(store)],
|
|
14
|
-
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
service: store,
|
|
14
|
+
// FRAME state: each address stores and restores its own agent's list. A lost write only
|
|
15
|
+
// leaves the list one change behind, which the agent's next TodoList call rewrites — so
|
|
16
|
+
// nothing waits for it.
|
|
17
|
+
durableState: {
|
|
18
|
+
snapshot: (address) => store.snapshot(address),
|
|
19
|
+
restore: (address, value) => store.restore(address, value),
|
|
20
|
+
},
|
|
21
|
+
openSession: (ctx) => {
|
|
22
|
+
store.attachPersistence((address) => void ctx.persistState(address));
|
|
18
23
|
},
|
|
19
24
|
};
|
|
20
25
|
}
|
|
@@ -14,7 +14,8 @@ export class TodoListInjector extends BoundaryInjector {
|
|
|
14
14
|
}
|
|
15
15
|
getInjection(ctx) {
|
|
16
16
|
this.restoreInjectedAt(ctx, ["todo_reminder"]);
|
|
17
|
-
|
|
17
|
+
// The reminder is for the frame being injected into — never another agent's list.
|
|
18
|
+
const todos = this.store.get(ctx.address);
|
|
18
19
|
if (todos.length === 0)
|
|
19
20
|
return null;
|
|
20
21
|
const turnsSinceWrite = assistantTurnsSinceTodoWrite(ctx.history);
|
|
@@ -1,19 +1,40 @@
|
|
|
1
|
-
import type { AgentRecord } from "../../store/index.ts";
|
|
2
1
|
export declare const TODO_LIST_TOOL_NAME = "TodoList";
|
|
3
2
|
export type TodoStatus = "pending" | "in_progress" | "done";
|
|
4
3
|
export interface TodoItem {
|
|
5
4
|
readonly title: string;
|
|
6
5
|
readonly status: TodoStatus;
|
|
7
6
|
}
|
|
8
|
-
/**
|
|
7
|
+
/** The frame's whole list: carried in the TodoList tool result `details` for the transcript,
|
|
8
|
+
* and what is stored as the frame's durable state. */
|
|
9
9
|
export interface TodoDetails {
|
|
10
10
|
readonly todos: readonly TodoItem[];
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* One todo list PER FRAME, keyed by journal address (`main`, `main/<agentId>`).
|
|
14
|
+
*
|
|
15
|
+
* A task list belongs to the agent working through it, not to the conversation: a subagent plans
|
|
16
|
+
* its own work, and until this was keyed, its first `TodoList` call replaced the main agent's
|
|
17
|
+
* list outright — silently, since the parent's transcript still carried its own last result.
|
|
18
|
+
* The service stays a single session-lived object (it owns nothing that needs closing); what is
|
|
19
|
+
* per-frame is the DATA, so it is indexed rather than duplicated. See docs/state-and-lifetime.md.
|
|
20
|
+
*/
|
|
12
21
|
export declare class TodoStore {
|
|
13
|
-
private
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
|
|
22
|
+
private readonly byFrame;
|
|
23
|
+
/** Persists one frame's list after a change. Absent in a bare store (tests). */
|
|
24
|
+
private persist;
|
|
25
|
+
/** Where a change to a frame's list becomes durable (`SessionContext.persistState`). */
|
|
26
|
+
attachPersistence(persist: (address: string) => void): void;
|
|
27
|
+
/** The list for one frame. Defaults to the root agent's, which is what `session.todo` reads. */
|
|
28
|
+
get(address?: string): readonly TodoItem[];
|
|
29
|
+
set(address: string, todos: readonly TodoItem[]): readonly TodoItem[];
|
|
30
|
+
/** Every frame that has one, in insertion order. */
|
|
31
|
+
frames(): readonly string[];
|
|
32
|
+
/** One frame's list as its durable state; undefined when the frame has none. */
|
|
33
|
+
snapshot(address: string): TodoDetails | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Restore one frame's list from the value stored for it (undefined: none). A frame's list is
|
|
36
|
+
* restored when its shard is reopened — `main` at open, a subagent's on resume.
|
|
37
|
+
*/
|
|
38
|
+
restore(address: string, value: unknown): void;
|
|
18
39
|
}
|
|
19
40
|
//# sourceMappingURL=todo-store.d.ts.map
|
|
@@ -1,18 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DEFAULT_ADDRESS } from "../../store/index.js";
|
|
2
2
|
export const TODO_LIST_TOOL_NAME = "TodoList";
|
|
3
|
+
const NO_TODOS = [];
|
|
4
|
+
/**
|
|
5
|
+
* One todo list PER FRAME, keyed by journal address (`main`, `main/<agentId>`).
|
|
6
|
+
*
|
|
7
|
+
* A task list belongs to the agent working through it, not to the conversation: a subagent plans
|
|
8
|
+
* its own work, and until this was keyed, its first `TodoList` call replaced the main agent's
|
|
9
|
+
* list outright — silently, since the parent's transcript still carried its own last result.
|
|
10
|
+
* The service stays a single session-lived object (it owns nothing that needs closing); what is
|
|
11
|
+
* per-frame is the DATA, so it is indexed rather than duplicated. See docs/state-and-lifetime.md.
|
|
12
|
+
*/
|
|
3
13
|
export class TodoStore {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
byFrame = new Map();
|
|
15
|
+
/** Persists one frame's list after a change. Absent in a bare store (tests). */
|
|
16
|
+
persist;
|
|
17
|
+
/** Where a change to a frame's list becomes durable (`SessionContext.persistState`). */
|
|
18
|
+
attachPersistence(persist) {
|
|
19
|
+
this.persist = persist;
|
|
7
20
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return this.
|
|
21
|
+
/** The list for one frame. Defaults to the root agent's, which is what `session.todo` reads. */
|
|
22
|
+
get(address = DEFAULT_ADDRESS) {
|
|
23
|
+
return this.byFrame.get(address) ?? NO_TODOS;
|
|
11
24
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
this.
|
|
25
|
+
set(address, todos) {
|
|
26
|
+
const normalized = normalizeTodos(todos);
|
|
27
|
+
this.byFrame.set(address, normalized);
|
|
28
|
+
this.persist?.(address);
|
|
29
|
+
return normalized;
|
|
30
|
+
}
|
|
31
|
+
/** Every frame that has one, in insertion order. */
|
|
32
|
+
frames() {
|
|
33
|
+
return [...this.byFrame.keys()];
|
|
34
|
+
}
|
|
35
|
+
/** One frame's list as its durable state; undefined when the frame has none. */
|
|
36
|
+
snapshot(address) {
|
|
37
|
+
const todos = this.byFrame.get(address);
|
|
38
|
+
return todos === undefined ? undefined : { todos };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Restore one frame's list from the value stored for it (undefined: none). A frame's list is
|
|
42
|
+
* restored when its shard is reopened — `main` at open, a subagent's on resume.
|
|
43
|
+
*/
|
|
44
|
+
restore(address, value) {
|
|
45
|
+
if (isTodoDetails(value))
|
|
46
|
+
this.byFrame.set(address, normalizeTodos(value.todos));
|
|
47
|
+
else
|
|
48
|
+
this.byFrame.delete(address);
|
|
16
49
|
}
|
|
17
50
|
}
|
|
18
51
|
function normalizeTodos(todos) {
|