@a3s-lab/code 2.0.1 → 2.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.
Files changed (4) hide show
  1. package/README.md +37 -42
  2. package/index.d.ts +35 -166
  3. package/index.js +1 -5
  4. package/package.json +8 -11
package/README.md CHANGED
@@ -24,10 +24,6 @@ async function main() {
24
24
  main().catch(console.error)
25
25
  ```
26
26
 
27
- ## Tool Metadata Helpers
28
-
29
- `session.tool(...)` returns a `ToolResult` enriched with parsed metadata helpers.
30
-
31
27
  ## Programmatic Tool Calling
32
28
 
33
29
  `session.program(...)` runs a bounded JavaScript script in the embedded QuickJS
@@ -54,58 +50,57 @@ Omit `allowedTools` to allow every registered session tool except `program`.
54
50
  Scripts can also be loaded from workspace-relative `.js` or `.mjs` files with
55
51
  `{ path: 'scripts/ptc/search.js' }`.
56
52
 
57
- ### Agentic Parse LLM Blocks
53
+ ## Planning Events
58
54
 
59
- When `agentic_parse` runs with a query, the SDK exposes the exact structured
60
- document blocks selected for the LLM input.
55
+ Planning is automatic by default. Prefer the explicit tri-state
56
+ `planningMode` contract for SDK callers:
61
57
 
62
58
  ```js
63
- const tool = await session.tool('agentic_parse', {
64
- path: 'docs/scanned.pdf',
65
- query: 'overview',
66
- })
67
-
68
- for (const block of tool.agenticParseLlmBlocks ?? []) {
69
- console.log(block.index, block.kind, block.label, block.location?.display)
70
- }
59
+ agent.session('/my-project', { planningMode: 'auto' }) // default
60
+ agent.session('/my-project', { planningMode: 'enabled' }) // force planning
61
+ agent.session('/my-project', { planningMode: 'disabled' }) // explicitly off
71
62
  ```
72
63
 
73
- ### Agentic Search Match Locators
64
+ The legacy boolean shortcut still works: `{ planning: true }` forces planning
65
+ and `{ planning: false }` disables it.
66
+
67
+ When streaming, `task_updated` is the authoritative task-list snapshot for UI
68
+ rendering. `planning_end` contains the initial plan, while `step_start` and
69
+ `step_end` are fine-grained progress events.
70
+
71
+ ## Delegation And Tool Introspection
74
72
 
75
- `agentic_search` results expose typed match metadata, including page / section
76
- locators derived from `CompositeDocumentParser` blocks.
73
+ The SDK exposes the core `task` / `parallel_task` tools as direct helpers:
77
74
 
78
75
  ```js
79
- const search = await session.tool('agentic_search', {
80
- query: 'overview',
81
- mode: 'fast',
76
+ await session.delegateTask({
77
+ agent: 'explore',
78
+ description: 'Find auth entry points',
79
+ prompt: 'Inspect the repository and summarize the auth-related files.',
82
80
  })
83
81
 
84
- for (const result of search.agenticSearchResults ?? []) {
85
- for (const match of result.matches ?? []) {
86
- console.log(match.lineNumber, match.locator, match.content)
87
- }
88
- }
82
+ await session.parallelTask([
83
+ { agent: 'explore', description: 'Find tests', prompt: 'Locate auth tests.' },
84
+ { agent: 'verification', description: 'Check risk', prompt: 'Review auth edge cases.' },
85
+ ])
89
86
  ```
90
87
 
91
- Deep search also exposes `sampledLines` with `locator`, `distance`, and `weight`.
88
+ Use `session.toolNames()` for names and `session.toolDefinitions()` when a UI
89
+ needs the full model-visible schemas.
90
+
91
+ ## Run Replay
92
+
93
+ Each `send(...)` or `stream(...)` call records a run snapshot and replayable
94
+ runtime events:
92
95
 
93
96
  ```js
94
- const deep = await session.tool('agentic_search', {
95
- query: 'overview',
96
- mode: 'deep',
97
- })
97
+ await session.send('Fix the failing test')
98
98
 
99
- for (const result of deep.agenticSearchResults ?? []) {
100
- for (const sampled of result.sampledLines ?? []) {
101
- console.log(sampled.lineNumber, sampled.locator, sampled.distance, sampled.weight)
102
- }
103
- }
99
+ const [run] = await session.runs()
100
+ console.log(run.id, run.status)
101
+ console.log(await session.runEvents(run.id))
104
102
  ```
105
103
 
106
- ## Examples
107
-
108
- - `examples/test-agentic-parse-llm-blocks.js`
109
- - `examples/test-agentic-search-locators.js`
110
- - `examples/test-agentic-search-sampled-lines.js`
111
- - `examples/test-agentic-search-sdk.js`
104
+ Use `session.currentRun()` while a stream is active to inspect the current run.
105
+ Use `session.cancelRun(run.id)` to cancel only that run; stale IDs will not
106
+ cancel a newer operation.
package/index.d.ts CHANGED
@@ -108,26 +108,28 @@ export interface ToolResult {
108
108
  /** Convenience JSON view of `metadata.document_runtime` when present. */
109
109
  documentRuntimeJson?: string
110
110
  }
111
+ /** Execution limits for `Session.program`. */
111
112
  export interface ProgramScriptLimits {
112
- /** Wall-clock timeout for the embedded QuickJS script. */
113
113
  timeoutMs?: number
114
- /** Maximum number of ctx tool calls the script may perform. */
115
114
  maxToolCalls?: number
116
- /** Maximum bytes returned in the program result output. */
117
115
  maxOutputBytes?: number
118
116
  }
117
+ /** Options for `Session.program`. */
119
118
  export interface ProgramScriptOptions {
120
- /** Inline JavaScript source. Define `async function run(ctx, inputs)` or export it as default. */
121
119
  source?: string
122
- /** Workspace-relative `.js` or `.mjs` script path. */
123
120
  path?: string
124
- /** JSON-serializable inputs passed to `run(ctx, inputs)`. */
125
121
  inputs?: any
126
- /** Optional tool allow-list. Defaults to every registered tool except `program`. */
127
122
  allowedTools?: Array<string>
128
- /** Execution limits for the script. */
129
123
  limits?: ProgramScriptLimits
130
124
  }
125
+ /** Options for `Session.delegateTask`. */
126
+ export interface DelegateTaskOptions {
127
+ agent: string
128
+ description: string
129
+ prompt: string
130
+ background?: boolean
131
+ maxSteps?: number
132
+ }
131
133
  /** Parameters for the web_search tool. */
132
134
  export interface JsWebSearchParams {
133
135
  /** The search query. */
@@ -173,20 +175,6 @@ export interface JsSessionStore {
173
175
  export interface JsSecurityProvider {
174
176
  kind: string
175
177
  }
176
- /**
177
- * A plugin descriptor passed in `SessionOptions.plugins`.
178
- *
179
- * Use `new SkillPlugin(...)` to create plugin instances — do not construct
180
- * this object directly.
181
- */
182
- export interface JsPlugin {
183
- /** Plugin kind: currently only `"skill_plugin"`. */
184
- kind: string
185
- /** Plugin name (used by SkillPlugin). */
186
- pluginName?: string
187
- /** Skill YAML/markdown content strings (used by SkillPlugin). */
188
- skills?: Array<string>
189
- }
190
178
  /**
191
179
  * Union type for AHP transport configuration.
192
180
  * Accepts any of: StdioTransport, HttpTransport, WebSocketTransport, UnixSocketTransport.
@@ -214,7 +202,7 @@ export interface PermissionPolicy {
214
202
  export interface SessionOptions {
215
203
  /** Override the default model. Format: "provider/model" (e.g., "openai/gpt-4o"). */
216
204
  model?: string
217
- /** Enable built-in skills (7 skills: code-search, code-review, explain-code, find-bugs, builtin-tools, delegate-task, find-skills). */
205
+ /** Enable built-in skills (4 skills: code-search, code-review, explain-code, find-bugs). */
218
206
  builtinSkills?: boolean
219
207
  /** Extra directories to scan for skill files (.md with YAML frontmatter). */
220
208
  skillDirs?: Array<string>
@@ -228,7 +216,14 @@ export interface SessionOptions {
228
216
  queueConfig?: SessionQueueConfig
229
217
  /** Explicit permission policy for tool execution. */
230
218
  permissionPolicy?: PermissionPolicy
231
- /** Enable planning mode (default: false). */
219
+ /**
220
+ * Explicit planning mode: "auto", "enabled", or "disabled".
221
+ *
222
+ * Prefer this over `planning` when the caller needs an unambiguous SDK contract.
223
+ * If both are set, `planningMode` wins.
224
+ */
225
+ planningMode?: string
226
+ /** Legacy planning shortcut. Omit for auto planning, true to force planning, false to disable. */
232
227
  planning?: boolean
233
228
  /** Enable goal tracking (default: false). */
234
229
  goalTracking?: boolean
@@ -275,12 +270,6 @@ export interface SessionOptions {
275
270
  * ```
276
271
  */
277
272
  securityProvider?: JsSecurityProvider
278
- /**
279
- * Plugins to mount onto this session.
280
- *
281
- * Pass instances such as `new SkillPlugin(...)` to inject custom skills.
282
- */
283
- plugins?: Array<JsPlugin>
284
273
  /**
285
274
  * Custom role/identity prepended before the core agentic prompt.
286
275
  * Example: "You are a senior Python developer specializing in FastAPI."
@@ -545,55 +534,6 @@ export interface SearchConfig {
545
534
  engines: Record<string, SearchEngineConfig>
546
535
  headless?: HeadlessConfig
547
536
  }
548
- /** SubAgent configuration for the advanced orchestrator control plane. */
549
- export interface SubAgentConfig {
550
- /** Agent type (general, explore, plan, etc.) */
551
- agentType: string
552
- /** Task description */
553
- description: string
554
- /** Execution prompt */
555
- prompt: string
556
- /** Maximum execution steps */
557
- maxSteps?: number
558
- /** Execution timeout (milliseconds) */
559
- timeoutMs?: number
560
- /** Parent SubAgent ID (for nesting) */
561
- parentId?: string
562
- /** Workspace directory for the SubAgent (defaults to ".") */
563
- workspace?: string
564
- /** Extra directories to scan for agent definition files */
565
- agentDirs?: Array<string>
566
- /** Extra directories to scan for skill definition files */
567
- skillDirs?: Array<string>
568
- }
569
- /** SubAgent activity type */
570
- export interface SubAgentActivity {
571
- /** Activity type: idle, calling_tool, requesting_llm, waiting_for_control */
572
- activityType: string
573
- /** Activity data (JSON string) */
574
- data?: string
575
- }
576
- /** SubAgent information with metadata and current activity */
577
- export interface SubAgentInfo {
578
- id: string
579
- agentType: string
580
- description: string
581
- state: string
582
- parentId?: string
583
- createdAt: number
584
- updatedAt: number
585
- currentActivity?: SubAgentActivity
586
- }
587
- /** SubAgent activity entry (id + activity) */
588
- export interface SubAgentActivityEntry {
589
- id: string
590
- activity: SubAgentActivity
591
- }
592
- /** SubAgent state entry (id + state) */
593
- export interface SubAgentStateEntry {
594
- id: string
595
- state: string
596
- }
597
537
  /** Streaming event iterator. Use `for await (const event of stream)` or call `.next()` manually. */
598
538
  export declare class EventStream {
599
539
  /**
@@ -658,35 +598,6 @@ export declare class DefaultSecurityProvider {
658
598
  kind: string
659
599
  constructor()
660
600
  }
661
- /**
662
- * Skill-only plugin — injects custom skills into the session's skill registry
663
- * without registering any tools.
664
- *
665
- * Use this to add custom LLM guidance (instructions, tool restrictions,
666
- * prompting strategies) directly from Node.js. For tools, use MCP servers.
667
- *
668
- * ```js
669
- * import { SkillPlugin } from '@a3s-lab/code';
670
- *
671
- * const plugin = new SkillPlugin('my-plugin', [`
672
- * ---
673
- * name: my-skill
674
- * description: Use bash cautiously
675
- * allowed-tools: "bash(*)"
676
- * kind: instruction
677
- * ---
678
- * Always explain what command you're about to run before executing it.
679
- * `]);
680
- *
681
- * agent.session('.', { plugins: [plugin] });
682
- * ```
683
- */
684
- export declare class SkillPlugin {
685
- kind: string
686
- pluginName?: string
687
- skills?: Array<string>
688
- constructor(name: string, skills: Array<string>)
689
- }
690
601
  /**
691
602
  * Stdio transport for AHP (Agent Harness Protocol).
692
603
  *
@@ -877,8 +788,22 @@ export declare class Session {
877
788
  streamWithAttachments(prompt: string, attachments: Array<AttachmentObject>, history?: Array<MessageObject> | undefined | null): Promise<EventStream>
878
789
  /** Return the session's conversation history. */
879
790
  history(): Array<MessageObject>
791
+ /** Return run snapshots recorded by this session. */
792
+ runs(): Promise<any>
793
+ /** Return a run snapshot by ID, or null when it is unknown. */
794
+ runSnapshot(runId: string): Promise<any>
795
+ /** Return recorded runtime events for a run. */
796
+ runEvents(runId: string): Promise<any>
797
+ /** Return the currently running operation, or null when idle. */
798
+ currentRun(): Promise<any>
799
+ /** Cancel a specific run only if it is still the active run. */
800
+ cancelRun(runId: string): Promise<boolean>
880
801
  /** Execute a tool by name, bypassing the LLM. */
881
802
  tool(name: string, args: any): Promise<ToolResult>
803
+ /** Delegate a bounded task to a child agent through the built-in `task` tool. */
804
+ delegateTask(options: DelegateTaskOptions): Promise<ToolResult>
805
+ /** Execute several delegated child-agent tasks concurrently through `parallel_task`. */
806
+ parallelTask(tasks: DelegateTaskOptions[]): Promise<ToolResult>
882
807
  /** Run a bounded JavaScript script through the embedded QuickJS `program` tool. */
883
808
  program(options: ProgramScriptOptions): Promise<ToolResult>
884
809
  /** Read a file from the workspace. */
@@ -983,6 +908,8 @@ export declare class Session {
983
908
  * @returns Array of tool name strings
984
909
  */
985
910
  toolNames(): Array<string>
911
+ /** Return full model-visible tool definitions currently registered on this session. */
912
+ toolDefinitions(): any
986
913
  /**
987
914
  * Register a hook for lifecycle event interception.
988
915
  *
@@ -1143,61 +1070,3 @@ export declare class Session {
1143
1070
  */
1144
1071
  close(): void
1145
1072
  }
1146
- /** SubAgent handle for control and monitoring. */
1147
- export declare class SubAgentHandle {
1148
- /** Get SubAgent ID */
1149
- get id(): string
1150
- /** Get current state (non-blocking) */
1151
- state(): string
1152
- /** Get current activity */
1153
- activity(): SubAgentActivity
1154
- /** Pause execution */
1155
- pause(): void
1156
- /** Resume execution */
1157
- resume(): void
1158
- /** Cancel execution */
1159
- cancel(): void
1160
- /** Wait for completion and get result */
1161
- wait(): string
1162
- /** Subscribe to sub-agent events. */
1163
- events(): SubAgentEventStream
1164
- }
1165
- /** SubAgent event stream for monitoring sub-agent events. */
1166
- export declare class SubAgentEventStream {
1167
- /** Receive the next sub-agent event, or `null` on timeout / end-of-stream. */
1168
- recv(timeoutMs?: number | undefined | null): Promise<any | null>
1169
- }
1170
- /**
1171
- * Advanced orchestrator for explicit SubAgent lifecycle control.
1172
- *
1173
- * Routine multi-agent work should use `task` / `parallelTask` delegation; this
1174
- * API is for monitoring and controlling long-running SubAgents directly.
1175
- */
1176
- export declare class Orchestrator {
1177
- /**
1178
- * Create a new orchestrator.
1179
- *
1180
- * @param agent - `Agent` instance used to execute spawned SubAgents.
1181
- */
1182
- static create(agent: Agent): Orchestrator
1183
- /** Spawn a new SubAgent */
1184
- spawnSubagent(config: SubAgentConfig): SubAgentHandle
1185
- /** Get active SubAgent count */
1186
- activeCount(): number
1187
- /** Get all SubAgent information list */
1188
- listSubagents(): Array<SubAgentInfo>
1189
- /** Get specific SubAgent information */
1190
- getSubagentInfo(id: string): SubAgentInfo | null
1191
- /** Get all active SubAgent activities */
1192
- getActiveActivities(): Array<SubAgentActivityEntry>
1193
- /** Get all SubAgent states */
1194
- getAllStates(): Array<SubAgentStateEntry>
1195
- /** Pause a SubAgent */
1196
- pauseSubagent(id: string): void
1197
- /** Resume a SubAgent */
1198
- resumeSubagent(id: string): void
1199
- /** Cancel a SubAgent */
1200
- cancelSubagent(id: string): void
1201
- /** Wait for all SubAgents to complete */
1202
- waitAll(): void
1203
- }
package/index.js CHANGED
@@ -310,7 +310,7 @@ if (!nativeBinding) {
310
310
  throw new Error(`Failed to load native binding`)
311
311
  }
312
312
 
313
- const { formatVerificationSummary, EventStream, FileMemoryStore, FileSessionStore, MemorySessionStore, DefaultSecurityProvider, SkillPlugin, StdioTransport, HttpTransport, WebSocketTransport, UnixSocketTransport, Agent, Session, builtinSkills, BrowserBackend, SubAgentHandle, SubAgentEventStream, Orchestrator } = nativeBinding
313
+ const { formatVerificationSummary, EventStream, FileMemoryStore, FileSessionStore, MemorySessionStore, DefaultSecurityProvider, StdioTransport, HttpTransport, WebSocketTransport, UnixSocketTransport, Agent, Session, builtinSkills, BrowserBackend } = nativeBinding
314
314
 
315
315
  module.exports.formatVerificationSummary = formatVerificationSummary
316
316
  module.exports.EventStream = EventStream
@@ -318,7 +318,6 @@ module.exports.FileMemoryStore = FileMemoryStore
318
318
  module.exports.FileSessionStore = FileSessionStore
319
319
  module.exports.MemorySessionStore = MemorySessionStore
320
320
  module.exports.DefaultSecurityProvider = DefaultSecurityProvider
321
- module.exports.SkillPlugin = SkillPlugin
322
321
  module.exports.StdioTransport = StdioTransport
323
322
  module.exports.HttpTransport = HttpTransport
324
323
  module.exports.WebSocketTransport = WebSocketTransport
@@ -327,6 +326,3 @@ module.exports.Agent = Agent
327
326
  module.exports.Session = Session
328
327
  module.exports.builtinSkills = builtinSkills
329
328
  module.exports.BrowserBackend = BrowserBackend
330
- module.exports.SubAgentHandle = SubAgentHandle
331
- module.exports.SubAgentEventStream = SubAgentEventStream
332
- module.exports.Orchestrator = Orchestrator
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a3s-lab/code",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "A3S Code - Native Node.js bindings for the coding-agent runtime",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,17 +37,14 @@
37
37
  "build:debug": "napi build --platform --js index.js --dts index.d.ts",
38
38
  "prepublishOnly": "napi prepublish -t npm",
39
39
  "test": "node test.mjs",
40
- "test:helpers": "node test-helpers.mjs",
41
- "test:agentic-search-locators": "node examples/search/test-agentic-search-locators.js",
42
- "test:agentic-search-sampled-lines": "node examples/search/test-agentic-search-sampled-lines.js",
43
- "test:agentic-parse-llm-blocks": "node examples/search/test-agentic-parse-llm-blocks.js"
40
+ "test:helpers": "node test-helpers.mjs"
44
41
  },
45
42
  "optionalDependencies": {
46
- "@a3s-lab/code-darwin-arm64": "2.0.1",
47
- "@a3s-lab/code-linux-x64-gnu": "2.0.1",
48
- "@a3s-lab/code-linux-x64-musl": "2.0.1",
49
- "@a3s-lab/code-linux-arm64-gnu": "2.0.1",
50
- "@a3s-lab/code-linux-arm64-musl": "2.0.1",
51
- "@a3s-lab/code-win32-x64-msvc": "2.0.1"
43
+ "@a3s-lab/code-darwin-arm64": "2.1.0",
44
+ "@a3s-lab/code-linux-x64-gnu": "2.1.0",
45
+ "@a3s-lab/code-linux-x64-musl": "2.1.0",
46
+ "@a3s-lab/code-linux-arm64-gnu": "2.1.0",
47
+ "@a3s-lab/code-linux-arm64-musl": "2.1.0",
48
+ "@a3s-lab/code-win32-x64-msvc": "2.1.0"
52
49
  }
53
50
  }