neoctl 0.1.0
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/README.md +146 -0
- package/dist/agents/agent-definition.d.ts +39 -0
- package/dist/agents/agent-definition.js +57 -0
- package/dist/agents/agent-definition.js.map +1 -0
- package/dist/agents/agent-tool.d.ts +38 -0
- package/dist/agents/agent-tool.js +336 -0
- package/dist/agents/agent-tool.js.map +1 -0
- package/dist/agents/local-agent-task.d.ts +52 -0
- package/dist/agents/local-agent-task.js +63 -0
- package/dist/agents/local-agent-task.js.map +1 -0
- package/dist/agents/smoke-agents.d.ts +1 -0
- package/dist/agents/smoke-agents.js +142 -0
- package/dist/agents/smoke-agents.js.map +1 -0
- package/dist/agents/team.d.ts +10 -0
- package/dist/agents/team.js +2 -0
- package/dist/agents/team.js.map +1 -0
- package/dist/app/app-state.d.ts +21 -0
- package/dist/app/app-state.js +24 -0
- package/dist/app/app-state.js.map +1 -0
- package/dist/context/compaction.d.ts +49 -0
- package/dist/context/compaction.js +334 -0
- package/dist/context/compaction.js.map +1 -0
- package/dist/context/context-manager.d.ts +53 -0
- package/dist/context/context-manager.js +98 -0
- package/dist/context/context-manager.js.map +1 -0
- package/dist/context/prompts.d.ts +22 -0
- package/dist/context/prompts.js +84 -0
- package/dist/context/prompts.js.map +1 -0
- package/dist/context/smoke-context.d.ts +1 -0
- package/dist/context/smoke-context.js +151 -0
- package/dist/context/smoke-context.js.map +1 -0
- package/dist/core/assistant-output-filter.d.ts +9 -0
- package/dist/core/assistant-output-filter.js +78 -0
- package/dist/core/assistant-output-filter.js.map +1 -0
- package/dist/core/context-metrics.d.ts +10 -0
- package/dist/core/context-metrics.js +77 -0
- package/dist/core/context-metrics.js.map +1 -0
- package/dist/core/message-pipeline.d.ts +10 -0
- package/dist/core/message-pipeline.js +138 -0
- package/dist/core/message-pipeline.js.map +1 -0
- package/dist/core/query-engine.d.ts +86 -0
- package/dist/core/query-engine.js +337 -0
- package/dist/core/query-engine.js.map +1 -0
- package/dist/core/query.d.ts +47 -0
- package/dist/core/query.js +408 -0
- package/dist/core/query.js.map +1 -0
- package/dist/core/run-agent.d.ts +48 -0
- package/dist/core/run-agent.js +150 -0
- package/dist/core/run-agent.js.map +1 -0
- package/dist/core/smoke-core-loop.d.ts +1 -0
- package/dist/core/smoke-core-loop.js +42 -0
- package/dist/core/smoke-core-loop.js.map +1 -0
- package/dist/core/state.d.ts +37 -0
- package/dist/core/state.js +31 -0
- package/dist/core/state.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/model/communication-logger.d.ts +30 -0
- package/dist/model/communication-logger.js +218 -0
- package/dist/model/communication-logger.js.map +1 -0
- package/dist/model/config.d.ts +25 -0
- package/dist/model/config.js +65 -0
- package/dist/model/config.js.map +1 -0
- package/dist/model/context-window.d.ts +32 -0
- package/dist/model/context-window.js +76 -0
- package/dist/model/context-window.js.map +1 -0
- package/dist/model/credentials.d.ts +13 -0
- package/dist/model/credentials.js +19 -0
- package/dist/model/credentials.js.map +1 -0
- package/dist/model/env.d.ts +8 -0
- package/dist/model/env.js +36 -0
- package/dist/model/env.js.map +1 -0
- package/dist/model/errors.d.ts +42 -0
- package/dist/model/errors.js +74 -0
- package/dist/model/errors.js.map +1 -0
- package/dist/model/http-transport.d.ts +26 -0
- package/dist/model/http-transport.js +118 -0
- package/dist/model/http-transport.js.map +1 -0
- package/dist/model/model-gateway.d.ts +103 -0
- package/dist/model/model-gateway.js +15 -0
- package/dist/model/model-gateway.js.map +1 -0
- package/dist/model/model-metadata.json +677 -0
- package/dist/model/openai-adapter.d.ts +34 -0
- package/dist/model/openai-adapter.js +152 -0
- package/dist/model/openai-adapter.js.map +1 -0
- package/dist/model/openai-chat-mapper.d.ts +11 -0
- package/dist/model/openai-chat-mapper.js +114 -0
- package/dist/model/openai-chat-mapper.js.map +1 -0
- package/dist/model/openai-mappers.d.ts +21 -0
- package/dist/model/openai-mappers.js +261 -0
- package/dist/model/openai-mappers.js.map +1 -0
- package/dist/model/openai-responses-adapter.d.ts +2 -0
- package/dist/model/openai-responses-adapter.js +2 -0
- package/dist/model/openai-responses-adapter.js.map +1 -0
- package/dist/model/openai-responses-mapper.d.ts +11 -0
- package/dist/model/openai-responses-mapper.js +218 -0
- package/dist/model/openai-responses-mapper.js.map +1 -0
- package/dist/model/provider-adapter.d.ts +17 -0
- package/dist/model/provider-adapter.js +2 -0
- package/dist/model/provider-adapter.js.map +1 -0
- package/dist/model/provider-factory.d.ts +4 -0
- package/dist/model/provider-factory.js +29 -0
- package/dist/model/provider-factory.js.map +1 -0
- package/dist/model/retry-runner.d.ts +8 -0
- package/dist/model/retry-runner.js +28 -0
- package/dist/model/retry-runner.js.map +1 -0
- package/dist/model/smoke-openai.d.ts +1 -0
- package/dist/model/smoke-openai.js +44 -0
- package/dist/model/smoke-openai.js.map +1 -0
- package/dist/model/smoke-responses-mapper.d.ts +1 -0
- package/dist/model/smoke-responses-mapper.js +72 -0
- package/dist/model/smoke-responses-mapper.js.map +1 -0
- package/dist/model/sse-decoder.d.ts +5 -0
- package/dist/model/sse-decoder.js +79 -0
- package/dist/model/sse-decoder.js.map +1 -0
- package/dist/repl/clipboard.d.ts +14 -0
- package/dist/repl/clipboard.js +92 -0
- package/dist/repl/clipboard.js.map +1 -0
- package/dist/repl/commands.d.ts +38 -0
- package/dist/repl/commands.js +86 -0
- package/dist/repl/commands.js.map +1 -0
- package/dist/repl/index.d.ts +2 -0
- package/dist/repl/index.js +2836 -0
- package/dist/repl/index.js.map +1 -0
- package/dist/repl/markdown-renderer.d.ts +81 -0
- package/dist/repl/markdown-renderer.js +546 -0
- package/dist/repl/markdown-renderer.js.map +1 -0
- package/dist/repl/render.d.ts +2 -0
- package/dist/repl/render.js +45 -0
- package/dist/repl/render.js.map +1 -0
- package/dist/repl/status-line.d.ts +19 -0
- package/dist/repl/status-line.js +160 -0
- package/dist/repl/status-line.js.map +1 -0
- package/dist/safety/audit.d.ts +10 -0
- package/dist/safety/audit.js +2 -0
- package/dist/safety/audit.js.map +1 -0
- package/dist/safety/permissions.d.ts +10 -0
- package/dist/safety/permissions.js +2 -0
- package/dist/safety/permissions.js.map +1 -0
- package/dist/safety/sandbox.d.ts +6 -0
- package/dist/safety/sandbox.js +2 -0
- package/dist/safety/sandbox.js.map +1 -0
- package/dist/session/session-store.d.ts +98 -0
- package/dist/session/session-store.js +249 -0
- package/dist/session/session-store.js.map +1 -0
- package/dist/session/smoke-session.d.ts +1 -0
- package/dist/session/smoke-session.js +85 -0
- package/dist/session/smoke-session.js.map +1 -0
- package/dist/session/tool-result-memory.d.ts +64 -0
- package/dist/session/tool-result-memory.js +303 -0
- package/dist/session/tool-result-memory.js.map +1 -0
- package/dist/skills/skill-tool.d.ts +28 -0
- package/dist/skills/skill-tool.js +107 -0
- package/dist/skills/skill-tool.js.map +1 -0
- package/dist/skills/smoke-skills.d.ts +1 -0
- package/dist/skills/smoke-skills.js +60 -0
- package/dist/skills/smoke-skills.js.map +1 -0
- package/dist/tasks/task-store.d.ts +43 -0
- package/dist/tasks/task-store.js +150 -0
- package/dist/tasks/task-store.js.map +1 -0
- package/dist/tasks/task-tools.d.ts +31 -0
- package/dist/tasks/task-tools.js +232 -0
- package/dist/tasks/task-tools.js.map +1 -0
- package/dist/tools/builtins/echo-tool.d.ts +4 -0
- package/dist/tools/builtins/echo-tool.js +26 -0
- package/dist/tools/builtins/echo-tool.js.map +1 -0
- package/dist/tools/builtins/edit-tool.d.ts +30 -0
- package/dist/tools/builtins/edit-tool.js +423 -0
- package/dist/tools/builtins/edit-tool.js.map +1 -0
- package/dist/tools/builtins/exec-tool.d.ts +18 -0
- package/dist/tools/builtins/exec-tool.js +290 -0
- package/dist/tools/builtins/exec-tool.js.map +1 -0
- package/dist/tools/builtins/filesystem-tools.d.ts +16 -0
- package/dist/tools/builtins/filesystem-tools.js +306 -0
- package/dist/tools/builtins/filesystem-tools.js.map +1 -0
- package/dist/tools/builtins/grep-tool.d.ts +56 -0
- package/dist/tools/builtins/grep-tool.js +320 -0
- package/dist/tools/builtins/grep-tool.js.map +1 -0
- package/dist/tools/builtins/ripgrep-binary.d.ts +6 -0
- package/dist/tools/builtins/ripgrep-binary.js +51 -0
- package/dist/tools/builtins/ripgrep-binary.js.map +1 -0
- package/dist/tools/builtins/search-providers.d.ts +49 -0
- package/dist/tools/builtins/search-providers.js +240 -0
- package/dist/tools/builtins/search-providers.js.map +1 -0
- package/dist/tools/builtins/search-tool.d.ts +18 -0
- package/dist/tools/builtins/search-tool.js +171 -0
- package/dist/tools/builtins/search-tool.js.map +1 -0
- package/dist/tools/registry.d.ts +18 -0
- package/dist/tools/registry.js +69 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/run-tool-use.d.ts +13 -0
- package/dist/tools/run-tool-use.js +113 -0
- package/dist/tools/run-tool-use.js.map +1 -0
- package/dist/tools/schema.d.ts +2 -0
- package/dist/tools/schema.js +61 -0
- package/dist/tools/schema.js.map +1 -0
- package/dist/tools/smoke-tool-system.d.ts +1 -0
- package/dist/tools/smoke-tool-system.js +204 -0
- package/dist/tools/smoke-tool-system.js.map +1 -0
- package/dist/tools/streaming-tool-executor.d.ts +19 -0
- package/dist/tools/streaming-tool-executor.js +89 -0
- package/dist/tools/streaming-tool-executor.js.map +1 -0
- package/dist/tools/tool-orchestration.d.ts +15 -0
- package/dist/tools/tool-orchestration.js +89 -0
- package/dist/tools/tool-orchestration.js.map +1 -0
- package/dist/tools/tool.d.ts +121 -0
- package/dist/tools/tool.js +4 -0
- package/dist/tools/tool.js.map +1 -0
- package/dist/types/events.d.ts +66 -0
- package/dist/types/events.js +2 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/messages.d.ts +57 -0
- package/dist/types/messages.js +42 -0
- package/dist/types/messages.js.map +1 -0
- package/package.json +49 -0
- package/scripts/copy-model-metadata.mjs +4 -0
- package/scripts/install-ripgrep.cjs +152 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Agent Scaffold Source
|
|
2
|
+
|
|
3
|
+
This directory is a TypeScript implementation scaffold for the parent README. Chapters 01, 02, 03, 04, 05-core, and 07 now have runnable paths; later chapters still expose stable module boundaries and placeholders.
|
|
4
|
+
|
|
5
|
+
## Shape
|
|
6
|
+
|
|
7
|
+
- `src/repl`: the UI layer. It owns terminal input, slash commands, system init events, and rendering streamed events.
|
|
8
|
+
- `src/core`: the multi-turn query loop, loop state, message pipeline, `QueryEngine`, and child-agent runner entry points.
|
|
9
|
+
- `src/model`: provider-neutral model gateway/config/factory, provider adapters, OpenAI Responses/Chat mappers, HTTP transport, SSE decoder, retry, and normalized errors.
|
|
10
|
+
- `src/tools`: lifecycle tool contracts, registry, schema validation, execution pipeline, batch orchestration, streaming executor, and built-in tools.
|
|
11
|
+
- `src/context`: system prompt sections, runtime user/system context, deterministic compaction helpers, and model-driven compaction.
|
|
12
|
+
- `src/session`: JSONL session transcripts, tool-result persistence, latest/specific session resume, and session listing.
|
|
13
|
+
- `src/agents`: agent definitions, `AgentTool`, prompt rules, fork constraints, local task lifecycle, and agent smoke coverage.
|
|
14
|
+
- `src/tasks`: background task store, task-control tools, named-agent message routing, and persisted task output files.
|
|
15
|
+
- `src/skills`: inline workflow-as-tool injection and fork-skill boundary.
|
|
16
|
+
- `src/safety`: optional permission, sandbox, and audit ports.
|
|
17
|
+
- `src/app`: app-state ports used by tools and runtime code.
|
|
18
|
+
- `vendor/ripgrep`: per-platform bundled `rg` binaries installed by `npm run vendor:rg` or optional `postinstall`.
|
|
19
|
+
|
|
20
|
+
## Commands
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
npm run vendor:rg
|
|
25
|
+
npm run typecheck
|
|
26
|
+
npm run build
|
|
27
|
+
npm run smoke:core
|
|
28
|
+
npm run smoke:tools
|
|
29
|
+
npm run smoke:context
|
|
30
|
+
npm run smoke:agents
|
|
31
|
+
npm run smoke:skills
|
|
32
|
+
npm run smoke:openai -- "Say pong"
|
|
33
|
+
npm run dev
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Core Loop
|
|
37
|
+
|
|
38
|
+
`src/core/query.ts` implements the Chapter 01 main path as a streaming state machine:
|
|
39
|
+
|
|
40
|
+
- prepares each turn from a single `QueryState`
|
|
41
|
+
- applies compact-boundary filtering and tool-result budgeting before model calls
|
|
42
|
+
- builds system/user context into the model request
|
|
43
|
+
- streams assistant deltas and messages to the UI
|
|
44
|
+
- collects `tool_use` events, executes tools, and feeds `tool_result` messages into the next model turn
|
|
45
|
+
- tracks `previousResponseId` for Responses API tool-result continuation
|
|
46
|
+
- emits terminal reasons such as `completed`, `max_turns`, `model_error`, and abort states
|
|
47
|
+
- keeps max-output-token recovery and reactive compact continuation points explicit
|
|
48
|
+
|
|
49
|
+
`npm run smoke:core` verifies the tool-call follow-up loop with a fake model and the built-in `echo` tool.
|
|
50
|
+
|
|
51
|
+
## Tool System
|
|
52
|
+
|
|
53
|
+
`src/tools` implements the Chapter 02 tool system contract:
|
|
54
|
+
|
|
55
|
+
- tools are lifecycle objects with identity, aliases, schemas, metadata, validators, execution, result mapping, progress rendering, and optional context modifiers
|
|
56
|
+
- `ToolRegistry` keeps built-in tools as a stable prompt-cache prefix, supports aliases, filters deferred tools, and merges external tools deterministically
|
|
57
|
+
- `runToolUse()` performs schema validation, custom validation, permission decision, progress emission, abort handling, result mapping, max-result truncation, new messages, and context modifier propagation
|
|
58
|
+
- `runTools()` partitions tool calls into concurrency-safe batches and serial batches, applying context modifiers in tool-use order
|
|
59
|
+
- `StreamingToolExecutor` can start tools as tool calls arrive and can synthesize discarded results on fallback/abort
|
|
60
|
+
- `grepTool` calls the bundled ripgrep binary through `ripgrep-binary.ts`, supports smart/sensitive/insensitive case modes, glob filters, hidden-file opt-in, bounded context lines, and bounded total results
|
|
61
|
+
- `searchTool` performs web search through a pluggable `SearchProvider`; the initial backend is Exa MCP, with provider factory seams for future Bing/Tavily/custom implementations
|
|
62
|
+
- `scripts/install-ripgrep.cjs` resolves the current OS/CPU, downloads the matching official ripgrep release asset, extracts `rg`, and writes a manifest beside the binary; runtime lookup does not depend on PATH
|
|
63
|
+
|
|
64
|
+
`npm run smoke:tools` verifies aliases, schema/custom validation, unknown-tool errors, max result truncation, bundled-rg grep, pluggable web search, and concurrent batch execution.
|
|
65
|
+
|
|
66
|
+
## Context And Prompts
|
|
67
|
+
|
|
68
|
+
`src/context` implements the Chapter 03 and Chapter 05 prompt/context path:
|
|
69
|
+
|
|
70
|
+
- `prompts.ts` builds system prompt sections with `__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__`, replacement priority, proactive agent append mode, and prefix splitting for cache-aware providers
|
|
71
|
+
- `DefaultContextManager` memoizes user context (`currentDate`, project memory files) and system context (`cwd`, platform, git branch/status/recent commit)
|
|
72
|
+
- `message-pipeline.ts` prepends user context as a user message, appends system context to the system prompt, respects compact boundaries, and budgets oversized tool results
|
|
73
|
+
- `ModelDrivenCompactor` uses the configured model gateway for autocompact and reactive compact summaries
|
|
74
|
+
- deterministic snip, microcompact, and summary fallback remain available when model summarization fails or when tests need predictable output
|
|
75
|
+
- `query.ts` persists compact-boundary messages into the event stream and retries once after provider `context_length` errors
|
|
76
|
+
|
|
77
|
+
`npm run smoke:context` verifies prompt boundary splitting, context injection, tool result budgeting, deterministic compaction, model-driven autocompact, and prompt-too-long recovery.
|
|
78
|
+
|
|
79
|
+
## Session Resume
|
|
80
|
+
|
|
81
|
+
The REPL writes JSONL transcripts under `.agent/sessions` by default. After each user message, a background title subagent check is scheduled after 5s: it creates one initial title, then performs one later refinement with the conversation and previous title if the prior title agent has finished. `/sessions` opens an interactive browser (default 10 per page): use ↑/↓ to select a session, ←/→ to switch pages when more than one page exists, Enter to resume the selected session, and Esc to close.
|
|
82
|
+
|
|
83
|
+
Startup resume is available with environment variables:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
set AGENT_SESSION_RESUME=1
|
|
87
|
+
npm run dev
|
|
88
|
+
|
|
89
|
+
set AGENT_SESSION_ID=<session_id>
|
|
90
|
+
set AGENT_SESSION_RESUME=1
|
|
91
|
+
npm run dev
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Set `AGENT_SESSION_TRANSCRIPT=0` to disable transcript persistence, or `AGENT_SESSION_DIR=<absolute-or-relative-dir>` to store transcripts elsewhere. `/reset` clears the active history and records a reset marker so future resumes start after the reset.
|
|
95
|
+
|
|
96
|
+
`npm run smoke:session` verifies transcript recording, latest-session lookup, specific-session resume, tool-result output persistence, and reset markers.
|
|
97
|
+
|
|
98
|
+
## Subagents And Tasks
|
|
99
|
+
|
|
100
|
+
`src/agents` and `src/tasks` implement the Chapter 04 core path:
|
|
101
|
+
|
|
102
|
+
- `AgentTool` is a normal tool with `prompt`, `description`, `subagent_type`, `model`, `run_in_background`, `name`, `team_name`, `mode`, `isolation`, and `cwd` inputs
|
|
103
|
+
- `AgentTool` now exports prompt rules covering fresh/fork/background/parallel/prompt-quality behavior
|
|
104
|
+
- `runAgent()` creates isolated child messages/context/tool pools and reuses the same `query()` loop
|
|
105
|
+
- `AgentDefinition` supports tool allow/deny lists, model, effort, permission mode, background, max turns, memory, isolation, and custom system prompts
|
|
106
|
+
- sync agents return a completed structured result; background/fork agents register `LocalAgentTask` and return `async_launched`
|
|
107
|
+
- `TaskOutput`, `TaskList`, `TaskGet`, `TaskStop`, and `SendMessage` provide the minimum control surface for background agents
|
|
108
|
+
- completed background tasks write `.agent-tasks/<task_id>.txt`; the directory is gitignored
|
|
109
|
+
- fork children get explicit anti-recursion and scope boilerplate; teammate/team inputs are represented as named background agents for now
|
|
110
|
+
|
|
111
|
+
`npm run smoke:agents` verifies sync delegation, async launch, task output, output-file persistence, task listing, and named-agent message routing.
|
|
112
|
+
|
|
113
|
+
## Skills
|
|
114
|
+
|
|
115
|
+
`src/skills` implements the low-risk part of Chapter 05 SkillTool:
|
|
116
|
+
|
|
117
|
+
- `SkillTool` validates skill existence and model invocation eligibility
|
|
118
|
+
- inline skills inject a meta user message into the next model turn through `newMessages`
|
|
119
|
+
- inline skills can update main loop model and effort through `contextModifier`
|
|
120
|
+
- fork skills are recognized and return a structured `fork_required` result instead of silently pretending to run
|
|
121
|
+
|
|
122
|
+
`npm run smoke:skills` verifies inline injection, context modification, fork-skill rejection, and unknown-skill validation.
|
|
123
|
+
|
|
124
|
+
## Model Providers
|
|
125
|
+
|
|
126
|
+
The REPL calls `createModelGatewayFromEnv()`, which loads `.env`, reads `MODEL_*` settings into a small discriminated provider config, and constructs a provider through `provider-factory.ts`. Provider-specific switches stay inside provider-owned config (`OpenAIProviderConfig.openai.endpoint` today), while `OPENAI_*` variables remain supported as compatibility aliases.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
set MODEL_PROVIDER=openai
|
|
130
|
+
set MODEL_API_KEY=your-api-key
|
|
131
|
+
set MODEL_BASE_URL=https://api.openai.com
|
|
132
|
+
set MODEL_ID=gpt-5.5
|
|
133
|
+
set MODEL_REASONING_EFFORT=high
|
|
134
|
+
set MODEL_ENDPOINT=auto
|
|
135
|
+
npm run smoke:openai -- "Say pong"
|
|
136
|
+
npm run dev
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The OpenAI adapter is split into a small provider facade plus mappers:
|
|
140
|
+
|
|
141
|
+
- `openai-adapter.ts`: endpoint selection, auth, transport, retry, and Responses-to-Chat fallback
|
|
142
|
+
- `openai-responses-mapper.ts`: `/v1/responses` request and event mapping
|
|
143
|
+
- `openai-chat-mapper.ts`: OpenAI-compatible `/v1/chat/completions` fallback mapping
|
|
144
|
+
- `openai-mappers.ts`: shared tool/message/usage helpers
|
|
145
|
+
|
|
146
|
+
`MODEL_ENDPOINT=auto` tries `/v1/responses` first and falls back to `/v1/chat/completions` for OpenAI-compatible gateways that do not expose Responses API.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ToolUseContext } from "../tools/tool.js";
|
|
2
|
+
export type AgentIsolation = "shared" | "worktree" | "remote";
|
|
3
|
+
export type AgentPermissionMode = "inherit" | "readonly" | "workspace-write" | "bubble";
|
|
4
|
+
export interface AgentDefinition {
|
|
5
|
+
agentType: string;
|
|
6
|
+
whenToUse: string;
|
|
7
|
+
tools?: readonly string[];
|
|
8
|
+
disallowedTools?: readonly string[];
|
|
9
|
+
skills?: readonly string[];
|
|
10
|
+
mcpServers?: readonly string[];
|
|
11
|
+
color?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
effort?: "minimal" | "low" | "medium" | "high";
|
|
14
|
+
permissionMode?: AgentPermissionMode;
|
|
15
|
+
maxTurns?: number;
|
|
16
|
+
criticalSystemReminder?: string;
|
|
17
|
+
requiredMcpServers?: readonly string[];
|
|
18
|
+
background?: boolean;
|
|
19
|
+
initialPrompt?: string;
|
|
20
|
+
memory?: "user" | "project" | "local";
|
|
21
|
+
isolation?: AgentIsolation;
|
|
22
|
+
omitProjectMemory?: boolean;
|
|
23
|
+
buildSystemPrompt?: (context?: ToolUseContext) => string;
|
|
24
|
+
}
|
|
25
|
+
export declare const FORK_BOILERPLATE_TAG = "<fork-child-agent>";
|
|
26
|
+
export declare const FORK_AGENT: AgentDefinition;
|
|
27
|
+
export declare const GENERAL_PURPOSE_AGENT: AgentDefinition;
|
|
28
|
+
export interface AgentCatalog {
|
|
29
|
+
resolve(agentType?: string): AgentDefinition;
|
|
30
|
+
list(): AgentDefinition[];
|
|
31
|
+
}
|
|
32
|
+
export declare class StaticAgentCatalog implements AgentCatalog {
|
|
33
|
+
private readonly definitions;
|
|
34
|
+
constructor(definitions?: readonly AgentDefinition[]);
|
|
35
|
+
resolve(agentType?: string): AgentDefinition;
|
|
36
|
+
list(): AgentDefinition[];
|
|
37
|
+
}
|
|
38
|
+
export declare function isForkChildContext(context: ToolUseContext): boolean;
|
|
39
|
+
export declare function buildForkChildPrompt(directive: string): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export const FORK_BOILERPLATE_TAG = "<fork-child-agent>";
|
|
2
|
+
export const FORK_AGENT = {
|
|
3
|
+
agentType: "fork",
|
|
4
|
+
whenToUse: "Fork the current conversation into an isolated worker for scoped parallel work.",
|
|
5
|
+
tools: ["*"],
|
|
6
|
+
model: "inherit",
|
|
7
|
+
permissionMode: "bubble",
|
|
8
|
+
maxTurns: 40,
|
|
9
|
+
buildSystemPrompt: () => "",
|
|
10
|
+
};
|
|
11
|
+
export const GENERAL_PURPOSE_AGENT = {
|
|
12
|
+
agentType: "general-purpose",
|
|
13
|
+
whenToUse: "General engineering worker for scoped implementation, investigation, or verification tasks.",
|
|
14
|
+
tools: ["*"],
|
|
15
|
+
permissionMode: "inherit",
|
|
16
|
+
maxTurns: 40,
|
|
17
|
+
buildSystemPrompt: () => [
|
|
18
|
+
"You are a subagent worker inside the same neo runtime.",
|
|
19
|
+
"You may identify yourself as neo when referring to your operating identity.",
|
|
20
|
+
"Stay within the assigned prompt. Use available tools when needed and return a concise final result.",
|
|
21
|
+
].join("\n"),
|
|
22
|
+
};
|
|
23
|
+
export class StaticAgentCatalog {
|
|
24
|
+
definitions = new Map();
|
|
25
|
+
constructor(definitions = [GENERAL_PURPOSE_AGENT]) {
|
|
26
|
+
for (const definition of definitions)
|
|
27
|
+
this.definitions.set(definition.agentType, definition);
|
|
28
|
+
}
|
|
29
|
+
resolve(agentType) {
|
|
30
|
+
if (!agentType)
|
|
31
|
+
return this.definitions.get(GENERAL_PURPOSE_AGENT.agentType) ?? GENERAL_PURPOSE_AGENT;
|
|
32
|
+
const definition = this.definitions.get(agentType);
|
|
33
|
+
if (!definition)
|
|
34
|
+
throw new Error(`Unknown agent type: ${agentType}`);
|
|
35
|
+
return definition;
|
|
36
|
+
}
|
|
37
|
+
list() {
|
|
38
|
+
return [...this.definitions.values()].sort((left, right) => left.agentType.localeCompare(right.agentType));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function isForkChildContext(context) {
|
|
42
|
+
if (context.agentType === FORK_AGENT.agentType)
|
|
43
|
+
return true;
|
|
44
|
+
return Boolean(context.messages?.some((message) => message.blocks.some((block) => block.type === "text" && block.text.includes(FORK_BOILERPLATE_TAG))));
|
|
45
|
+
}
|
|
46
|
+
export function buildForkChildPrompt(directive) {
|
|
47
|
+
return [
|
|
48
|
+
FORK_BOILERPLATE_TAG,
|
|
49
|
+
"You are a worker, not the main agent.",
|
|
50
|
+
"Do not spawn subagents from this fork child.",
|
|
51
|
+
"Do not ask follow-up questions. Stay strictly within the directive.",
|
|
52
|
+
"Final report must start with `Scope:`.",
|
|
53
|
+
"",
|
|
54
|
+
directive,
|
|
55
|
+
].join("\n");
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=agent-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-definition.js","sourceRoot":"","sources":["../../src/agents/agent-definition.ts"],"names":[],"mappings":"AA2BA,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AAEzD,MAAM,CAAC,MAAM,UAAU,GAAoB;IACzC,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,iFAAiF;IAC5F,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,KAAK,EAAE,SAAS;IAChB,cAAc,EAAE,QAAQ;IACxB,QAAQ,EAAE,EAAE;IACZ,iBAAiB,EAAE,GAAG,EAAE,CAAC,EAAE;CAC5B,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAoB;IACpD,SAAS,EAAE,iBAAiB;IAC5B,SAAS,EAAE,6FAA6F;IACxG,KAAK,EAAE,CAAC,GAAG,CAAC;IACZ,cAAc,EAAE,SAAS;IACzB,QAAQ,EAAE,EAAE;IACZ,iBAAiB,EAAE,GAAG,EAAE,CAAC;QACvB,wDAAwD;QACxD,6EAA6E;QAC7E,qGAAqG;KACtG,CAAC,IAAI,CAAC,IAAI,CAAC;CACb,CAAC;AAOF,MAAM,OAAO,kBAAkB;IACZ,WAAW,GAAG,IAAI,GAAG,EAA2B,CAAC;IAElE,YAAY,c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AAqE;QACrE,wCAAwC;QACxC,EAAE;QACF,SAAS;KACV,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ContextManager } from "../context/context-manager.js";
|
|
2
|
+
import type { Compactor, ContextBudgetOptions } from "../context/compaction.js";
|
|
3
|
+
import type { ModelGateway } from "../model/model-gateway.js";
|
|
4
|
+
import type { Tool, ToolUseContext } from "../tools/tool.js";
|
|
5
|
+
import type { ToolRegistry } from "../tools/registry.js";
|
|
6
|
+
import { type AgentCatalog, type AgentIsolation, type AgentPermissionMode } from "./agent-definition.js";
|
|
7
|
+
import { type TaskStore } from "../tasks/task-store.js";
|
|
8
|
+
export declare const AGENT_TOOL_NAME = "agent";
|
|
9
|
+
export declare const AGENT_TOOL_PROMPT_RULES: string;
|
|
10
|
+
export interface AgentToolInput {
|
|
11
|
+
prompt: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
subagent_type?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
run_in_background?: boolean;
|
|
16
|
+
/** When true with sync mode, allow concurrent execution with other parallel-safe agent calls in the same turn (multiple model streams). */
|
|
17
|
+
parallel?: boolean;
|
|
18
|
+
name?: string;
|
|
19
|
+
team_name?: string;
|
|
20
|
+
mode?: AgentPermissionMode | "sync" | "background" | "fork";
|
|
21
|
+
isolation?: AgentIsolation;
|
|
22
|
+
/** Working directory for this subagent's tools (resolved against parent cwd when relative). */
|
|
23
|
+
cwd?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface AgentToolRuntime {
|
|
26
|
+
modelGateway: ModelGateway;
|
|
27
|
+
tools: ToolRegistry;
|
|
28
|
+
contextManager?: ContextManager;
|
|
29
|
+
compactor?: Compactor;
|
|
30
|
+
contextBudget?: ContextBudgetOptions;
|
|
31
|
+
taskStore?: TaskStore;
|
|
32
|
+
agentCatalog?: AgentCatalog;
|
|
33
|
+
}
|
|
34
|
+
export declare function createAgentTool(runtime?: AgentToolRuntime): Tool<AgentToolInput>;
|
|
35
|
+
export declare function resumeAgentTask(taskId: string, directive: string | undefined, runtime: AgentToolRuntime, taskStore: TaskStore, parentContext: ToolUseContext): Promise<{
|
|
36
|
+
ok: boolean;
|
|
37
|
+
error?: string;
|
|
38
|
+
}>;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { createTextMessage } from "../types/messages.js";
|
|
2
|
+
import { runAgent } from "../core/run-agent.js";
|
|
3
|
+
import { createLocalAgentTask, updateProgressFromMessage } from "./local-agent-task.js";
|
|
4
|
+
import { FORK_AGENT, GENERAL_PURPOSE_AGENT, StaticAgentCatalog, isForkChildContext, } from "./agent-definition.js";
|
|
5
|
+
import { globalTaskStore } from "../tasks/task-store.js";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
export const AGENT_TOOL_NAME = "agent";
|
|
8
|
+
export const AGENT_TOOL_PROMPT_RULES = [
|
|
9
|
+
"Fresh agents do not inherit conversation context; prompts must include goal, relevant files, constraints, and expected output.",
|
|
10
|
+
"Fork agents inherit parent context and should receive a scoped directive, not a full background briefing.",
|
|
11
|
+
"Background agents return an output file and task notification; do not fabricate results before the task completes.",
|
|
12
|
+
"To run multiple subagents truly in parallel in one model turn: set parallel=true (sync but concurrent), or run_in_background/mode=background (fire-and-forget with task_id). Without those, subagents run one after another and wall time stacks.",
|
|
13
|
+
"Subagents are bounded by max turns (see agent definitions / AGENT_SUBAGENT_MAX_TURNS) and optional wall time (AGENT_SUBAGENT_WALL_TIMEOUT_MS) so they cannot run indefinitely.",
|
|
14
|
+
"Launch independent agents in the same model turn when parallel work is useful.",
|
|
15
|
+
"Avoid vague delegation; give each worker a concrete scope and say whether edits are allowed.",
|
|
16
|
+
].join("\n");
|
|
17
|
+
export function createAgentTool(runtime) {
|
|
18
|
+
return {
|
|
19
|
+
name: AGENT_TOOL_NAME,
|
|
20
|
+
searchHint: "delegate work to a subagent",
|
|
21
|
+
description: [
|
|
22
|
+
"Delegate a scoped task to a subagent.",
|
|
23
|
+
"Use parallel=true when issuing multiple agent calls in one turn so they run concurrently; otherwise they execute sequentially.",
|
|
24
|
+
AGENT_TOOL_PROMPT_RULES,
|
|
25
|
+
].join("\n"),
|
|
26
|
+
inputSchema: {
|
|
27
|
+
type: "object",
|
|
28
|
+
properties: {
|
|
29
|
+
prompt: { type: "string", description: "Complete task instructions for the child agent." },
|
|
30
|
+
description: { type: "string", description: "Short task label for progress and task lists." },
|
|
31
|
+
subagent_type: { type: "string", description: "Agent definition to use. Omit for general-purpose or fork mode." },
|
|
32
|
+
model: { type: "string" },
|
|
33
|
+
run_in_background: { type: "boolean" },
|
|
34
|
+
name: { type: "string", description: "Optional stable name for later SendMessage routing." },
|
|
35
|
+
team_name: { type: "string" },
|
|
36
|
+
mode: { type: "string" },
|
|
37
|
+
isolation: { type: "string", enum: ["shared", "worktree", "remote"] },
|
|
38
|
+
cwd: { type: "string", description: "Working directory for child tools (list/read/exec); resolved against parent cwd if relative." },
|
|
39
|
+
parallel: { type: "boolean", description: "Set true when launching multiple independent agents in the same turn so they run concurrently." },
|
|
40
|
+
},
|
|
41
|
+
required: ["prompt"],
|
|
42
|
+
additionalProperties: false,
|
|
43
|
+
},
|
|
44
|
+
outputSchema: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: {
|
|
47
|
+
status: { type: "string", enum: ["completed", "async_launched"] },
|
|
48
|
+
agent_id: { type: "string" },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
metadata: { readOnly: false, concurrent: true, visible: true, requiresApproval: false, searchHint: "delegate subagent work" },
|
|
52
|
+
validate(input) {
|
|
53
|
+
const value = input;
|
|
54
|
+
if (!value.prompt?.trim())
|
|
55
|
+
throw new Error("agent.prompt is required");
|
|
56
|
+
return value;
|
|
57
|
+
},
|
|
58
|
+
isConcurrencySafe(input) {
|
|
59
|
+
return Boolean(input.run_in_background || input.mode === "background" || input.mode === "fork" || input.parallel === true);
|
|
60
|
+
},
|
|
61
|
+
async call(input, context, options) {
|
|
62
|
+
if (!runtime) {
|
|
63
|
+
return { ok: false, output: { error: "AgentTool runtime is not configured" } };
|
|
64
|
+
}
|
|
65
|
+
if ((input.mode === "fork" || (!input.subagent_type && input.run_in_background)) && isForkChildContext(context)) {
|
|
66
|
+
return { ok: false, output: { error: "Fork child agents cannot spawn additional subagents" } };
|
|
67
|
+
}
|
|
68
|
+
const catalog = runtime.agentCatalog ?? new StaticAgentCatalog([GENERAL_PURPOSE_AGENT]);
|
|
69
|
+
const fork = input.mode === "fork";
|
|
70
|
+
const agent = fork ? FORK_AGENT : catalog.resolve(input.subagent_type);
|
|
71
|
+
const description = input.description ?? input.prompt.slice(0, 80);
|
|
72
|
+
const background = Boolean(input.run_in_background || input.mode === "background" || fork || agent.background);
|
|
73
|
+
const agentId = makeAgentId(input.name ?? agent.agentType);
|
|
74
|
+
if (input.team_name && input.name) {
|
|
75
|
+
return {
|
|
76
|
+
ok: true,
|
|
77
|
+
output: {
|
|
78
|
+
status: "async_launched",
|
|
79
|
+
agent_id: agentId,
|
|
80
|
+
team_name: input.team_name,
|
|
81
|
+
name: input.name,
|
|
82
|
+
description,
|
|
83
|
+
message: "Teammate routing is represented as a named background agent in this scaffold.",
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (background) {
|
|
88
|
+
return launchAsyncAgent({ input, context, options, runtime, agent, fork, agentId, description });
|
|
89
|
+
}
|
|
90
|
+
return runSyncAgent({ input, context, runtime, agent, fork, agentId, description });
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function runSyncAgent(input) {
|
|
95
|
+
const agentMessages = [];
|
|
96
|
+
const workspaceCwd = resolveAgentWorkspaceCwd(input.input.cwd, input.context);
|
|
97
|
+
const wall = mergeAbortWithWallClock(input.context.abortSignal, resolveSubagentWallTimeoutMs());
|
|
98
|
+
try {
|
|
99
|
+
const stream = runAgent({
|
|
100
|
+
agentId: input.agentId,
|
|
101
|
+
agent: input.agent,
|
|
102
|
+
prompt: input.input.prompt,
|
|
103
|
+
parentContext: input.context,
|
|
104
|
+
parentMessages: input.fork ? input.context.messages : undefined,
|
|
105
|
+
dependencies: buildRunAgentDependencies(input.runtime),
|
|
106
|
+
model: input.input.model,
|
|
107
|
+
abortSignal: wall?.signal ?? input.context.abortSignal,
|
|
108
|
+
fork: input.fork,
|
|
109
|
+
workspaceCwd,
|
|
110
|
+
});
|
|
111
|
+
let completed = await stream.next();
|
|
112
|
+
while (!completed.done) {
|
|
113
|
+
if (completed.value.type === "message")
|
|
114
|
+
agentMessages.push(completed.value.message);
|
|
115
|
+
completed = await stream.next();
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
ok: true,
|
|
119
|
+
output: {
|
|
120
|
+
status: "completed",
|
|
121
|
+
description: input.description,
|
|
122
|
+
...completed.value.result,
|
|
123
|
+
},
|
|
124
|
+
newMessages: [createTextMessage("progress", `Subagent ${input.agentId} completed: ${input.description}`)],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
129
|
+
return {
|
|
130
|
+
ok: false,
|
|
131
|
+
output: { error: message, description: input.description },
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
wall?.dispose();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function launchAsyncAgent(input) {
|
|
139
|
+
const taskStore = input.runtime.taskStore ?? globalTaskStore;
|
|
140
|
+
const taskId = makeTaskId();
|
|
141
|
+
const abortController = new AbortController();
|
|
142
|
+
const task = createLocalAgentTask({
|
|
143
|
+
taskId,
|
|
144
|
+
agentId: input.agentId,
|
|
145
|
+
description: input.description,
|
|
146
|
+
prompt: input.input.prompt,
|
|
147
|
+
abortController,
|
|
148
|
+
});
|
|
149
|
+
taskStore.upsert(task);
|
|
150
|
+
if (input.input.name)
|
|
151
|
+
taskStore.registerName(input.input.name, input.agentId);
|
|
152
|
+
void runAsyncAgentLifecycle({ ...input, taskId, taskStore, abortController }).catch((error) => {
|
|
153
|
+
taskStore.fail(taskId, error instanceof Error ? error.message : String(error));
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
ok: true,
|
|
157
|
+
output: {
|
|
158
|
+
status: "async_launched",
|
|
159
|
+
agent_id: input.agentId,
|
|
160
|
+
task_id: taskId,
|
|
161
|
+
description: input.description,
|
|
162
|
+
prompt: input.input.prompt,
|
|
163
|
+
output_file: task.outputFile,
|
|
164
|
+
can_read_output_file: true,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
async function runAsyncAgentLifecycle(input) {
|
|
169
|
+
input.taskStore.markRunning(input.taskId);
|
|
170
|
+
const task = input.taskStore.get(input.taskId);
|
|
171
|
+
const workspaceCwd = resolveAgentWorkspaceCwd(input.input.cwd, input.context);
|
|
172
|
+
const wall = mergeAbortWithWallClock(input.abortController.signal, resolveSubagentWallTimeoutMs());
|
|
173
|
+
try {
|
|
174
|
+
const stream = runAgent({
|
|
175
|
+
agentId: input.agentId,
|
|
176
|
+
agent: input.agent,
|
|
177
|
+
prompt: input.input.prompt,
|
|
178
|
+
parentContext: input.context,
|
|
179
|
+
parentMessages: input.fork ? input.context.messages : undefined,
|
|
180
|
+
dependencies: buildRunAgentDependencies(input.runtime),
|
|
181
|
+
model: input.input.model,
|
|
182
|
+
abortSignal: wall?.signal ?? input.abortController.signal,
|
|
183
|
+
fork: input.fork,
|
|
184
|
+
existingMessages: input.existingMessages,
|
|
185
|
+
workspaceCwd,
|
|
186
|
+
});
|
|
187
|
+
let completed = await stream.next();
|
|
188
|
+
while (!completed.done) {
|
|
189
|
+
const event = completed.value;
|
|
190
|
+
const current = input.taskStore.get(input.taskId);
|
|
191
|
+
if (!current || current.status === "killed")
|
|
192
|
+
return;
|
|
193
|
+
if (event.type === "message") {
|
|
194
|
+
current.messages.push(event.message);
|
|
195
|
+
updateProgressFromMessage(current, event.message);
|
|
196
|
+
input.taskStore.upsert(current);
|
|
197
|
+
}
|
|
198
|
+
if (event.type === "terminal" || completed.done)
|
|
199
|
+
break;
|
|
200
|
+
const pending = input.taskStore.drainPendingMessages(input.taskId);
|
|
201
|
+
if (pending.length > 0) {
|
|
202
|
+
const currentTask = input.taskStore.get(input.taskId);
|
|
203
|
+
if (currentTask) {
|
|
204
|
+
for (const msg of pending) {
|
|
205
|
+
currentTask.messages.push(msg);
|
|
206
|
+
}
|
|
207
|
+
input.taskStore.upsert(currentTask);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
completed = await stream.next();
|
|
211
|
+
}
|
|
212
|
+
if (!completed.done) {
|
|
213
|
+
let remaining = await stream.next();
|
|
214
|
+
while (!remaining.done) {
|
|
215
|
+
const event = remaining.value;
|
|
216
|
+
const current = input.taskStore.get(input.taskId);
|
|
217
|
+
if (!current || current.status === "killed")
|
|
218
|
+
return;
|
|
219
|
+
if (event.type === "message") {
|
|
220
|
+
current.messages.push(event.message);
|
|
221
|
+
updateProgressFromMessage(current, event.message);
|
|
222
|
+
input.taskStore.upsert(current);
|
|
223
|
+
}
|
|
224
|
+
remaining = await stream.next();
|
|
225
|
+
}
|
|
226
|
+
completed = remaining;
|
|
227
|
+
}
|
|
228
|
+
input.taskStore.complete(input.taskId, completed.value.result);
|
|
229
|
+
const finished = input.taskStore.get(input.taskId);
|
|
230
|
+
if (finished) {
|
|
231
|
+
finished.messages.push(createTaskNotification(finished.agentId, finished.taskId, finished.status, completed.value.result.content));
|
|
232
|
+
input.taskStore.upsert(finished);
|
|
233
|
+
}
|
|
234
|
+
if (task)
|
|
235
|
+
task.notified = false;
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
input.taskStore.fail(input.taskId, error instanceof Error ? error.message : String(error));
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
wall?.dispose();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export function resumeAgentTask(taskId, directive, runtime, taskStore, parentContext) {
|
|
245
|
+
const task = taskStore.get(taskId);
|
|
246
|
+
if (!task)
|
|
247
|
+
return Promise.resolve({ ok: false, error: `Unknown task: ${taskId}` });
|
|
248
|
+
if (task.type !== "agent")
|
|
249
|
+
return Promise.resolve({ ok: false, error: `Only agent tasks can be resumed` });
|
|
250
|
+
const catalog = runtime.agentCatalog ?? new StaticAgentCatalog([GENERAL_PURPOSE_AGENT]);
|
|
251
|
+
const agent = catalog.resolve(undefined);
|
|
252
|
+
const abortController = new AbortController();
|
|
253
|
+
task.status = "pending";
|
|
254
|
+
task.abortController = abortController;
|
|
255
|
+
task.error = undefined;
|
|
256
|
+
task.completedAt = undefined;
|
|
257
|
+
task.notified = false;
|
|
258
|
+
taskStore.upsert(task);
|
|
259
|
+
void runAsyncAgentLifecycle({
|
|
260
|
+
input: { prompt: directive ?? "Continue where you left off." },
|
|
261
|
+
context: parentContext,
|
|
262
|
+
runtime,
|
|
263
|
+
agent,
|
|
264
|
+
fork: false,
|
|
265
|
+
agentId: task.agentId,
|
|
266
|
+
description: task.description,
|
|
267
|
+
taskId: task.taskId,
|
|
268
|
+
taskStore,
|
|
269
|
+
abortController,
|
|
270
|
+
isResume: true,
|
|
271
|
+
existingMessages: [...task.messages],
|
|
272
|
+
}).catch((error) => {
|
|
273
|
+
taskStore.fail(taskId, error instanceof Error ? error.message : String(error));
|
|
274
|
+
});
|
|
275
|
+
return Promise.resolve({ ok: true });
|
|
276
|
+
}
|
|
277
|
+
function buildRunAgentDependencies(runtime) {
|
|
278
|
+
return {
|
|
279
|
+
modelGateway: runtime.modelGateway,
|
|
280
|
+
tools: runtime.tools,
|
|
281
|
+
contextManager: runtime.contextManager,
|
|
282
|
+
compactor: runtime.compactor,
|
|
283
|
+
contextBudget: runtime.contextBudget,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function createTaskNotification(agentId, taskId, status, content) {
|
|
287
|
+
return createTextMessage("user", `<task-notification agent_id="${agentId}" task_id="${taskId}" status="${status}">\n${content}\n</task-notification>`);
|
|
288
|
+
}
|
|
289
|
+
function makeAgentId(prefix) {
|
|
290
|
+
return `${slug(prefix)}_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 7)}`;
|
|
291
|
+
}
|
|
292
|
+
function makeTaskId() {
|
|
293
|
+
return `task_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`;
|
|
294
|
+
}
|
|
295
|
+
function resolveAgentWorkspaceCwd(inputCwd, parentContext) {
|
|
296
|
+
if (!inputCwd?.trim())
|
|
297
|
+
return undefined;
|
|
298
|
+
const root = path.resolve(parentContext.appState.snapshot().cwd ?? process.cwd());
|
|
299
|
+
const trimmed = inputCwd.trim();
|
|
300
|
+
return path.isAbsolute(trimmed) ? path.normalize(trimmed) : path.resolve(root, trimmed);
|
|
301
|
+
}
|
|
302
|
+
/** Wall-clock limit for a single subagent run. Default 10 minutes; set AGENT_SUBAGENT_WALL_TIMEOUT_MS=0 to disable. */
|
|
303
|
+
function resolveSubagentWallTimeoutMs() {
|
|
304
|
+
const raw = process.env.AGENT_SUBAGENT_WALL_TIMEOUT_MS;
|
|
305
|
+
if (raw === undefined || raw === "")
|
|
306
|
+
return 600000;
|
|
307
|
+
const n = Number(raw);
|
|
308
|
+
if (!Number.isFinite(n) || n < 0)
|
|
309
|
+
return 600000;
|
|
310
|
+
return n === 0 ? 0 : Math.floor(n);
|
|
311
|
+
}
|
|
312
|
+
function mergeAbortWithWallClock(parent, wallMs) {
|
|
313
|
+
if (wallMs <= 0)
|
|
314
|
+
return undefined;
|
|
315
|
+
const controller = new AbortController();
|
|
316
|
+
const tid = setTimeout(() => {
|
|
317
|
+
controller.abort(new Error(`Subagent wall-clock timeout after ${wallMs}ms (set AGENT_SUBAGENT_WALL_TIMEOUT_MS=0 to disable)`));
|
|
318
|
+
}, wallMs);
|
|
319
|
+
const onParentAbort = () => {
|
|
320
|
+
clearTimeout(tid);
|
|
321
|
+
if (!controller.signal.aborted)
|
|
322
|
+
controller.abort(parent?.reason ?? new Error("Aborted"));
|
|
323
|
+
};
|
|
324
|
+
parent?.addEventListener("abort", onParentAbort, { once: true });
|
|
325
|
+
return {
|
|
326
|
+
signal: controller.signal,
|
|
327
|
+
dispose: () => {
|
|
328
|
+
clearTimeout(tid);
|
|
329
|
+
parent?.removeEventListener("abort", onParentAbort);
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function slug(value) {
|
|
334
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "") || "agent";
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=agent-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tool.js","sourceRoot":"","sources":["../../src/agents/agent-tool.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAgB,MAAM,sBAAsB,CAAC;AAGvE,OAAO,EAAE,QAAQ,EAA6B,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AACxF,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,GAKnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC;AAEvC,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,gIAAgI;IAChI,2GAA2G;IAC3G,oHAAoH;IACpH,mPAAmP;IACnP,gLAAgL;IAChL,gFAAgF;IAChF,8FAA8F;CAC/F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AA4Bb,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,UAAU,EAAE,6BAA6B;QACzC,WAAW,EAAE;YACX,uCAAuC;YACvC,gIA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