@lucascouts/claude-agent-tui 0.10.3 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/acp-agent.d.ts +2 -0
- package/dist/acp-agent.js +92 -17
- package/dist/tools.d.ts +40 -4
- package/dist/tools.js +248 -25
- package/package.json +2 -2
package/dist/acp-agent.d.ts
CHANGED
package/dist/acp-agent.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { AgentSideConnection, ndJsonStream, RequestError, } from "@agentclientprotocol/sdk";
|
|
2
2
|
import { deleteSession, getSessionInfo, listSessions, } from "@anthropic-ai/claude-agent-sdk";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
4
5
|
import * as os from "node:os";
|
|
5
6
|
import * as path from "node:path";
|
|
6
7
|
import packageJson from "../package.json" with { type: "json" };
|
|
7
8
|
import { SettingsManager } from "./settings.js";
|
|
8
|
-
import { applyTaskCreate, applyTaskUpdate, parseTaskCreateOutput, planEntries, registerHookCallback, taskStateToPlanEntries, toolInfoFromToolUse, toolUpdateFromDiffToolResponse, toolUpdateFromToolResult, } from "./tools.js";
|
|
9
|
+
import { applyTaskCreate, applyTaskUpdate, parseTaskCreateOutput, parseTaskListOutput, parseTaskUpdateOutput, applyTaskList, planEntries, registerHookCallback, taskStateToPlanEntries, toolInfoFromToolUse, toolUpdateFromDiffToolResponse, toolUpdateFromToolResult, } from "./tools.js";
|
|
9
10
|
import { nodeToWebReadable, nodeToWebWritable, unreachable } from "./utils.js";
|
|
10
11
|
// === SEAM(011): engine boundary — inject a temporary no-op engine so the agent
|
|
11
12
|
// boots without the cut SDK query() path; the real PTY engine arrives in 013–015/023.
|
|
@@ -367,6 +368,59 @@ function computeSessionFingerprint(params) {
|
|
|
367
368
|
const dirs = [...resolveAdditionalDirs(params)].sort();
|
|
368
369
|
return JSON.stringify({ cwd: params.cwd, mcpServers: servers, additionalDirectories: dirs });
|
|
369
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Upstream #986 (v0.67.0) — build the `_meta.claudeCode` bag for one tool_use.
|
|
373
|
+
* Extracted from the four inline literals that used to build it so the Skill
|
|
374
|
+
* fields cannot land on some call sites and not others.
|
|
375
|
+
*/
|
|
376
|
+
function claudeCodeMetaFromToolUse(toolUse, cwd) {
|
|
377
|
+
const skillName = toolUse.name === "Skill"
|
|
378
|
+
? toolUse.input?.skill
|
|
379
|
+
: undefined;
|
|
380
|
+
const skillPath = skillName ? resolveSkillPath(skillName, cwd) : undefined;
|
|
381
|
+
return {
|
|
382
|
+
toolName: toolUse.name,
|
|
383
|
+
...(skillName ? { skill: skillName } : {}),
|
|
384
|
+
...(skillPath ? { skillPath } : {}),
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
/** Roots a skill's directory may sit under, relative to the directory the scope resolves to. */
|
|
388
|
+
const SKILL_CONTAINER_DIRS = [".claude/skills", ".agents/skills"];
|
|
389
|
+
/**
|
|
390
|
+
* Absolute path of a skill's `SKILL.md`, or `undefined` when none of the known layouts holds one.
|
|
391
|
+
*
|
|
392
|
+
* The `Skill` tool reports only the skill's name, so the file has to be located by probing the
|
|
393
|
+
* layouts skills actually use: project- and user-level `.claude/skills` (plus `.agents/skills`),
|
|
394
|
+
* and for a `<prefix>:<name>` spelling either a plugin (`.claude/plugins/<prefix>/skills/<name>`)
|
|
395
|
+
* or a directory-scoped skill (`<prefix>/.claude/skills/<name>`), which share that spelling. Only
|
|
396
|
+
* a path that exists on disk is returned, so a wrong guess costs nothing and clients never render
|
|
397
|
+
* a link to a missing file.
|
|
398
|
+
*/
|
|
399
|
+
function resolveSkillPath(skillName, cwd) {
|
|
400
|
+
if (!cwd) {
|
|
401
|
+
return undefined;
|
|
402
|
+
}
|
|
403
|
+
const colon = skillName.indexOf(":");
|
|
404
|
+
const scope = colon < 0 ? undefined : skillName.slice(0, colon);
|
|
405
|
+
const name = colon < 0 ? skillName : skillName.slice(colon + 1);
|
|
406
|
+
if (!name) {
|
|
407
|
+
return undefined;
|
|
408
|
+
}
|
|
409
|
+
const candidates = [];
|
|
410
|
+
const addCandidates = (base) => {
|
|
411
|
+
for (const container of SKILL_CONTAINER_DIRS) {
|
|
412
|
+
candidates.push(path.join(base, container, name, "SKILL.md"));
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
if (scope) {
|
|
416
|
+
// A `<prefix>:<name>` skill is either directory-scoped or a plugin's; both look identical.
|
|
417
|
+
addCandidates(path.join(cwd, scope));
|
|
418
|
+
candidates.push(path.join(cwd, ".claude/plugins", scope, "skills", name, "SKILL.md"));
|
|
419
|
+
}
|
|
420
|
+
addCandidates(cwd);
|
|
421
|
+
addCandidates(os.homedir());
|
|
422
|
+
return candidates.find((candidate) => existsSync(candidate));
|
|
423
|
+
}
|
|
370
424
|
// === SEAM(012/023): the engine binary is resolved from the user's PATH. After the 023 rewrite,
|
|
371
425
|
// createSession no longer passes the SDK `pathToClaudeCodeExecutable`; the PTY engine (story 013)
|
|
372
426
|
// spawns the subscription `claude` through the login shell (`bash -lc 'claude …'`), so it resolves
|
|
@@ -3101,8 +3155,8 @@ export function toAcpNotifications(content, role, sessionId, toolUseCache, clien
|
|
|
3101
3155
|
const update = {
|
|
3102
3156
|
_meta: {
|
|
3103
3157
|
claudeCode: {
|
|
3158
|
+
...claudeCodeMetaFromToolUse(toolUse, options?.cwd),
|
|
3104
3159
|
toolResponse,
|
|
3105
|
-
toolName: toolUse.name,
|
|
3106
3160
|
},
|
|
3107
3161
|
},
|
|
3108
3162
|
toolCallId: toolUseId,
|
|
@@ -3133,9 +3187,7 @@ export function toAcpNotifications(content, role, sessionId, toolUseCache, clien
|
|
|
3133
3187
|
// rather than emitting a duplicate tool_call.
|
|
3134
3188
|
update = {
|
|
3135
3189
|
_meta: {
|
|
3136
|
-
claudeCode:
|
|
3137
|
-
toolName: chunk.name,
|
|
3138
|
-
},
|
|
3190
|
+
claudeCode: claudeCodeMetaFromToolUse(chunk, options?.cwd),
|
|
3139
3191
|
},
|
|
3140
3192
|
toolCallId: chunk.id,
|
|
3141
3193
|
sessionUpdate: "tool_call_update",
|
|
@@ -3148,9 +3200,7 @@ export function toAcpNotifications(content, role, sessionId, toolUseCache, clien
|
|
|
3148
3200
|
// send as tool_call with terminal_info for Bash tools.
|
|
3149
3201
|
update = {
|
|
3150
3202
|
_meta: {
|
|
3151
|
-
claudeCode:
|
|
3152
|
-
toolName: chunk.name,
|
|
3153
|
-
},
|
|
3203
|
+
claudeCode: claudeCodeMetaFromToolUse(chunk, options?.cwd),
|
|
3154
3204
|
...(chunk.name === "Bash" && supportsTerminalOutput
|
|
3155
3205
|
? { terminal_info: { terminal_id: chunk.id } }
|
|
3156
3206
|
: {}),
|
|
@@ -3184,19 +3234,46 @@ export function toAcpNotifications(content, role, sessionId, toolUseCache, clien
|
|
|
3184
3234
|
toolUse.name === "TaskGet") {
|
|
3185
3235
|
// Headless/SDK sessions emit Task* tools instead of TodoWrite.
|
|
3186
3236
|
// TaskCreate / TaskUpdate mutate the accumulated task list; TaskList
|
|
3187
|
-
//
|
|
3188
|
-
//
|
|
3189
|
-
//
|
|
3237
|
+
// RECONCILES it against the SDK's authoritative snapshot (upstream #974),
|
|
3238
|
+
// which is what repairs a resumed or compacted session whose creating
|
|
3239
|
+
// calls are no longer in replay history. TaskGet stays read-only and
|
|
3240
|
+
// suppressed. The plan update is emitted as a snapshot of the accumulated
|
|
3241
|
+
// state, mirroring the legacy TodoWrite behavior.
|
|
3242
|
+
//
|
|
3243
|
+
// Each parser is offered the structured `toolUseResult` FIRST and the
|
|
3244
|
+
// model-facing `chunk.content` second. That order is not cosmetic: the
|
|
3245
|
+
// measured transcripts put the structured object only in `toolUseResult`
|
|
3246
|
+
// and a short sentence in `content`, so reading `content` alone (as this
|
|
3247
|
+
// arm did before) parsed nothing at all.
|
|
3190
3248
|
const isError = "is_error" in chunk && chunk.is_error;
|
|
3249
|
+
let shouldEmitTaskPlan = false;
|
|
3191
3250
|
if (!isError) {
|
|
3192
3251
|
if (toolUse.name === "TaskCreate") {
|
|
3193
|
-
applyTaskCreate(taskState, toolUse.input, parseTaskCreateOutput(chunk.content));
|
|
3252
|
+
applyTaskCreate(taskState, toolUse.input, parseTaskCreateOutput(toolUseResult) ?? parseTaskCreateOutput(chunk.content));
|
|
3253
|
+
shouldEmitTaskPlan = true;
|
|
3194
3254
|
}
|
|
3195
3255
|
else if (toolUse.name === "TaskUpdate") {
|
|
3196
|
-
|
|
3256
|
+
const input = toolUse.input;
|
|
3257
|
+
const output = parseTaskUpdateOutput(toolUseResult, input?.taskId) ??
|
|
3258
|
+
parseTaskUpdateOutput(chunk.content, input?.taskId);
|
|
3259
|
+
// Older transcripts carry no structured output, so the input-based
|
|
3260
|
+
// path is retained. When an output IS available, only a confirmed
|
|
3261
|
+
// update for the same task is applied — a TaskUpdate can fail
|
|
3262
|
+
// logically (unknown id) without the result being flagged is_error.
|
|
3263
|
+
if (!output || (output.success && output.taskId === input?.taskId)) {
|
|
3264
|
+
applyTaskUpdate(taskState, input);
|
|
3265
|
+
shouldEmitTaskPlan = true;
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
else if (toolUse.name === "TaskList") {
|
|
3269
|
+
const output = parseTaskListOutput(toolUseResult) ?? parseTaskListOutput(chunk.content);
|
|
3270
|
+
if (output) {
|
|
3271
|
+
applyTaskList(taskState, output);
|
|
3272
|
+
shouldEmitTaskPlan = true;
|
|
3273
|
+
}
|
|
3197
3274
|
}
|
|
3198
3275
|
}
|
|
3199
|
-
if (
|
|
3276
|
+
if (shouldEmitTaskPlan) {
|
|
3200
3277
|
update = {
|
|
3201
3278
|
sessionUpdate: "plan",
|
|
3202
3279
|
entries: taskStateToPlanEntries(taskState),
|
|
@@ -3227,9 +3304,7 @@ export function toAcpNotifications(content, role, sessionId, toolUseCache, clien
|
|
|
3227
3304
|
}
|
|
3228
3305
|
update = {
|
|
3229
3306
|
_meta: {
|
|
3230
|
-
claudeCode:
|
|
3231
|
-
toolName: toolUse.name,
|
|
3232
|
-
},
|
|
3307
|
+
claudeCode: claudeCodeMetaFromToolUse(toolUse, options?.cwd),
|
|
3233
3308
|
...(toolMeta?.terminal_exit ? { terminal_exit: toolMeta.terminal_exit } : {}),
|
|
3234
3309
|
},
|
|
3235
3310
|
toolCallId: chunk.tool_use_id,
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PlanEntry, ToolCallContent, ToolCallLocation, ToolKind } from "@agentclientprotocol/sdk";
|
|
2
2
|
import { HookCallback } from "@anthropic-ai/claude-agent-sdk";
|
|
3
|
-
import { TaskCreateInput, TaskCreateOutput, TaskUpdateInput } from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
|
|
3
|
+
import { TaskCreateInput, TaskCreateOutput, TaskListOutput, TaskUpdateInput, TaskUpdateOutput } from "@anthropic-ai/claude-agent-sdk/sdk-tools.js";
|
|
4
4
|
import { ToolResultBlockParam, WebSearchToolResultBlockParam } from "@anthropic-ai/sdk/resources";
|
|
5
5
|
import { BetaBashCodeExecutionToolResultBlockParam, BetaCodeExecutionToolResultBlockParam, BetaRequestMCPToolResultBlockParam, BetaTextEditorCodeExecutionToolResultBlockParam, BetaToolResultBlockParam, BetaToolSearchToolResultBlockParam, BetaWebFetchToolResultBlockParam, BetaWebSearchToolResultBlockParam } from "@anthropic-ai/sdk/resources/beta.mjs";
|
|
6
6
|
import { Logger } from "./acp-agent.js";
|
|
@@ -85,13 +85,49 @@ export type TaskEntry = {
|
|
|
85
85
|
};
|
|
86
86
|
export type TaskState = Map<string, TaskEntry>;
|
|
87
87
|
/**
|
|
88
|
-
* Best-effort parse of a TaskCreate
|
|
89
|
-
*
|
|
90
|
-
*
|
|
88
|
+
* Best-effort parse of a TaskCreate result. Upstream #974 (v0.67.0).
|
|
89
|
+
*
|
|
90
|
+
* MEASURED at port time, and the reason the textual fallback is not optional here: across 186
|
|
91
|
+
* Task* tool_use/tool_result pairs in the local transcripts, the model-facing `content` is ALWAYS
|
|
92
|
+
* the short sentence ("Task #1 created successfully: <subject>") and never JSON — the structured
|
|
93
|
+
* object lives in the message-level `toolUseResult`. The pre-#974 parser tried `JSON.parse` on
|
|
94
|
+
* `content` alone, so it returned `undefined` for every real TaskCreate and `applyTaskCreate`
|
|
95
|
+
* silently did nothing. On a resumed session, where the TaskCreated hook never fires, that left
|
|
96
|
+
* the plan empty.
|
|
91
97
|
*/
|
|
92
98
|
export declare function parseTaskCreateOutput(content: unknown): TaskCreateOutput | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Best-effort parse of a TaskList result — the SDK's AUTHORITATIVE snapshot of the task list.
|
|
101
|
+
* Upstream #974 (v0.67.0).
|
|
102
|
+
*
|
|
103
|
+
* Both shapes are ported, and both are measured: the structured `{ tasks: [...] }` is what the
|
|
104
|
+
* single real TaskList in the local corpus carries in `toolUseResult`, and its `content` is the
|
|
105
|
+
* `#<id> [<status>] <subject>` listing the textual arm below parses. One sample is too few to drop
|
|
106
|
+
* either arm, so neither is dropped.
|
|
107
|
+
*/
|
|
108
|
+
export declare function parseTaskListOutput(content: unknown): TaskListOutput | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Best-effort parse of a TaskUpdate result. Upstream #974 (v0.67.0).
|
|
111
|
+
*
|
|
112
|
+
* The point is the `success` flag: a TaskUpdate can fail LOGICALLY (unknown task id) while the
|
|
113
|
+
* tool_result itself is not flagged `is_error`. Applying the requested mutation in that case
|
|
114
|
+
* writes a task the CLI does not have. `expectedTaskId` lets the textual arm attribute a
|
|
115
|
+
* "Task #<id> not found" line when the structured output is absent.
|
|
116
|
+
*/
|
|
117
|
+
export declare function parseTaskUpdateOutput(content: unknown, expectedTaskId?: string): TaskUpdateOutput | undefined;
|
|
93
118
|
export declare function applyTaskCreate(state: TaskState, input: TaskCreateInput | undefined, output: TaskCreateOutput | undefined): void;
|
|
94
119
|
export declare function applyTaskUpdate(state: TaskState, input: TaskUpdateInput | undefined): void;
|
|
120
|
+
/**
|
|
121
|
+
* Reconcile the accumulated task list against the SDK's authoritative TaskList snapshot.
|
|
122
|
+
* Upstream #974 (v0.67.0).
|
|
123
|
+
*
|
|
124
|
+
* This is what repairs a RESUMED or COMPACTED session: the TaskCreate calls that built the list
|
|
125
|
+
* may be gone from replay history, so the accumulated state under-reports. The snapshot replaces
|
|
126
|
+
* the list wholesale — entries it omits were deleted and must disappear — while `activeForm` and
|
|
127
|
+
* `description` are carried over from the previous entry, because the TaskList output does not
|
|
128
|
+
* carry them and dropping them would silently degrade the plan text.
|
|
129
|
+
*/
|
|
130
|
+
export declare function applyTaskList(state: TaskState, output: TaskListOutput): void;
|
|
95
131
|
export declare function taskStateToPlanEntries(state: TaskState): PlanEntry[];
|
|
96
132
|
export declare function markdownEscape(text: string): string;
|
|
97
133
|
/**
|
package/dist/tools.js
CHANGED
|
@@ -310,6 +310,21 @@ export function toolInfoFromToolUse(toolUse, supportsTerminalOutput = false, cwd
|
|
|
310
310
|
: [],
|
|
311
311
|
};
|
|
312
312
|
}
|
|
313
|
+
// Upstream #986 (v0.67.0) — the `Skill` tool announces a skill being loaded.
|
|
314
|
+
// Without this case it falls through to `Other` and renders as a generic block
|
|
315
|
+
// titled "Skill" with the raw result text behind an expander. The skill NAME is
|
|
316
|
+
// the tool's only meaningful input, and it arrives as a real JSONL
|
|
317
|
+
// `tool_use.input.skill` (measured: 73 of 3 515 local transcripts), so this is
|
|
318
|
+
// readable from the disk-tail engine with no new source.
|
|
319
|
+
case "Skill": {
|
|
320
|
+
const input = toolUse.input;
|
|
321
|
+
const skillName = input?.skill;
|
|
322
|
+
return {
|
|
323
|
+
title: skillName ? `Load skill: ${skillName}` : "Load skill",
|
|
324
|
+
kind: "other",
|
|
325
|
+
content: [],
|
|
326
|
+
};
|
|
327
|
+
}
|
|
313
328
|
case "Other": {
|
|
314
329
|
const input = toolUse.input;
|
|
315
330
|
let output;
|
|
@@ -622,6 +637,11 @@ toolUseResult) {
|
|
|
622
637
|
}
|
|
623
638
|
return {};
|
|
624
639
|
}
|
|
640
|
+
// The result text is a bare "Launching skill: <name>" restatement of the title
|
|
641
|
+
// the tool_use already produced — suppress it, as Edit/Write suppress theirs.
|
|
642
|
+
case "Skill": {
|
|
643
|
+
return {};
|
|
644
|
+
}
|
|
625
645
|
case "Edit": // Edit is handled in hooks
|
|
626
646
|
case "Write": {
|
|
627
647
|
return {};
|
|
@@ -784,47 +804,226 @@ function toAcpContentBlock(content, isError) {
|
|
|
784
804
|
}
|
|
785
805
|
export function planEntries(input) {
|
|
786
806
|
return (input?.todos ?? []).map((todo) => ({
|
|
787
|
-
|
|
807
|
+
// Upstream #974 (v0.67.0): an in-progress item reads better in its active voice
|
|
808
|
+
// ("Fixing the bug") than in its imperative subject ("Fix the bug") — that is what
|
|
809
|
+
// `activeForm` is for. Any other status keeps the subject. Story 020's drift note
|
|
810
|
+
// recorded this field as DROPPED; it is now carried, and that note is updated.
|
|
811
|
+
content: todo.status === "in_progress" && todo.activeForm ? todo.activeForm : todo.content,
|
|
788
812
|
status: todo.status,
|
|
789
813
|
priority: "medium",
|
|
790
814
|
}));
|
|
791
815
|
}
|
|
792
816
|
/**
|
|
793
|
-
*
|
|
794
|
-
*
|
|
795
|
-
*
|
|
817
|
+
* Every text payload a tool_result can carry, in the order it should be tried: a bare string, or
|
|
818
|
+
* the `text` of each TextBlockParam-like block. Shared by the three Task* parsers so they cannot
|
|
819
|
+
* disagree about where a tool's output lives.
|
|
796
820
|
*/
|
|
797
|
-
|
|
798
|
-
|
|
821
|
+
function toolOutputTexts(content) {
|
|
822
|
+
if (typeof content === "string")
|
|
823
|
+
return [content];
|
|
824
|
+
if (!Array.isArray(content))
|
|
825
|
+
return [];
|
|
826
|
+
return content.flatMap((block) => block &&
|
|
827
|
+
typeof block === "object" &&
|
|
828
|
+
"type" in block &&
|
|
829
|
+
block.type === "text" &&
|
|
830
|
+
typeof block.text === "string"
|
|
831
|
+
? [block.text]
|
|
832
|
+
: []);
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* The already-structured object (the JSONL `toolUseResult`), or the first text payload that parses
|
|
836
|
+
* as JSON and satisfies `isValid`. Returns `undefined` when neither holds — never a partial object,
|
|
837
|
+
* so every caller can treat a result as fully shaped.
|
|
838
|
+
*/
|
|
839
|
+
function parseJsonToolOutput(content, isValid) {
|
|
840
|
+
if (content && typeof content === "object" && !Array.isArray(content) && isValid(content)) {
|
|
841
|
+
return content;
|
|
842
|
+
}
|
|
843
|
+
for (const text of toolOutputTexts(content)) {
|
|
799
844
|
try {
|
|
800
845
|
const parsed = JSON.parse(text);
|
|
801
|
-
if (parsed
|
|
802
|
-
typeof parsed === "object" &&
|
|
803
|
-
parsed.task &&
|
|
804
|
-
typeof parsed.task.id === "string") {
|
|
846
|
+
if (isValid(parsed))
|
|
805
847
|
return parsed;
|
|
806
|
-
}
|
|
807
848
|
}
|
|
808
849
|
catch {
|
|
809
|
-
//
|
|
850
|
+
// Not JSON — fall through to the caller's textual fallback.
|
|
810
851
|
}
|
|
852
|
+
}
|
|
853
|
+
return undefined;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Best-effort parse of a TaskCreate result. Upstream #974 (v0.67.0).
|
|
857
|
+
*
|
|
858
|
+
* MEASURED at port time, and the reason the textual fallback is not optional here: across 186
|
|
859
|
+
* Task* tool_use/tool_result pairs in the local transcripts, the model-facing `content` is ALWAYS
|
|
860
|
+
* the short sentence ("Task #1 created successfully: <subject>") and never JSON — the structured
|
|
861
|
+
* object lives in the message-level `toolUseResult`. The pre-#974 parser tried `JSON.parse` on
|
|
862
|
+
* `content` alone, so it returned `undefined` for every real TaskCreate and `applyTaskCreate`
|
|
863
|
+
* silently did nothing. On a resumed session, where the TaskCreated hook never fires, that left
|
|
864
|
+
* the plan empty.
|
|
865
|
+
*/
|
|
866
|
+
export function parseTaskCreateOutput(content) {
|
|
867
|
+
const structured = parseJsonToolOutput(content, (parsed) => Boolean(parsed) &&
|
|
868
|
+
typeof parsed === "object" &&
|
|
869
|
+
"task" in parsed &&
|
|
870
|
+
typeof parsed.task?.id === "string");
|
|
871
|
+
if (structured)
|
|
872
|
+
return structured;
|
|
873
|
+
for (const text of toolOutputTexts(content)) {
|
|
874
|
+
const match = /^Task #(\S+) created successfully: (.+)$/.exec(text.trim());
|
|
875
|
+
if (match)
|
|
876
|
+
return { task: { id: match[1], subject: match[2] } };
|
|
877
|
+
}
|
|
878
|
+
return undefined;
|
|
879
|
+
}
|
|
880
|
+
const TASK_STATUSES = new Set(["pending", "in_progress", "completed"]);
|
|
881
|
+
/**
|
|
882
|
+
* One line of a textual TaskList listing — `#<id> [<status>] <subject>`, optionally followed by
|
|
883
|
+
* ` (<owner>)` and ` [blocked by #a, #b]` — or `undefined` when the line is not one.
|
|
884
|
+
*
|
|
885
|
+
* A LINEAR SCANNER, deliberately, and not the regex upstream uses. That regex nests a quantifier
|
|
886
|
+
* inside a quantified group (`(?:#[^,\]]+(?:, )?)+`) and CodeQL flagged it twice on this repo:
|
|
887
|
+
* `js/redos` (exponential) and `js/polynomial-redos`. It reproduces — on `#! [pending] a [blocked
|
|
888
|
+
* by #` followed by N repetitions of `+#`, the match time QUADRUPLES for every 2 characters added
|
|
889
|
+
* (n=20 → 4.9 ms, n=22 → 20 ms, n=24 → 79 ms), so a ~100-character line hangs the process for
|
|
890
|
+
* hours. The input is the model-facing text of a tool_result read from the transcript, so it is
|
|
891
|
+
* not trusted the way a literal in this file would be.
|
|
892
|
+
*
|
|
893
|
+
* This follows the precedent story 051 set for the command-marker stripper: replace the regex with
|
|
894
|
+
* a scanner that makes exactly one pass and never backtracks. Same grammar, same results — the
|
|
895
|
+
* equivalence is pinned by tests — in O(n).
|
|
896
|
+
*
|
|
897
|
+
* The two optional suffixes are anchored at the END of the line, so they are peeled right-to-left
|
|
898
|
+
* with `lastIndexOf`. That reproduces the lazy `(.+?)` subject of the original: the regex, unable
|
|
899
|
+
* to put parentheses inside `[^()]*`, ends up matching the LAST parenthesised group as the owner,
|
|
900
|
+
* which is exactly what `lastIndexOf` finds.
|
|
901
|
+
*/
|
|
902
|
+
function parseTaskListLine(line) {
|
|
903
|
+
if (!line.startsWith("#"))
|
|
811
904
|
return undefined;
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
905
|
+
const idEnd = line.indexOf(" ");
|
|
906
|
+
// `#` alone is not an id, and `\S+` cannot be empty.
|
|
907
|
+
if (idEnd < 2)
|
|
908
|
+
return undefined;
|
|
909
|
+
const id = line.slice(1, idEnd);
|
|
910
|
+
const afterId = line.slice(idEnd + 1);
|
|
911
|
+
if (!afterId.startsWith("["))
|
|
912
|
+
return undefined;
|
|
913
|
+
const statusEnd = afterId.indexOf("]");
|
|
914
|
+
if (statusEnd < 0)
|
|
915
|
+
return undefined;
|
|
916
|
+
const status = afterId.slice(1, statusEnd);
|
|
917
|
+
if (!TASK_STATUSES.has(status))
|
|
918
|
+
return undefined;
|
|
919
|
+
let tail = afterId.slice(statusEnd + 1);
|
|
920
|
+
if (!tail.startsWith(" "))
|
|
921
|
+
return undefined;
|
|
922
|
+
tail = tail.slice(1);
|
|
923
|
+
let blockedBy = [];
|
|
924
|
+
const BLOCKED_BY = " [blocked by ";
|
|
925
|
+
if (tail.endsWith("]")) {
|
|
926
|
+
const at = tail.lastIndexOf(BLOCKED_BY);
|
|
927
|
+
// `at > 0` also enforces the original's non-empty subject: at 0 there is nothing before it.
|
|
928
|
+
if (at > 0) {
|
|
929
|
+
const entries = tail.slice(at + BLOCKED_BY.length, -1).split(", ");
|
|
930
|
+
// Every entry is `#<id>` with an id that carries no comma and no bracket — the character
|
|
931
|
+
// class the original spelled as `[^,\]]+`.
|
|
932
|
+
if (entries.length > 0 &&
|
|
933
|
+
entries.every((entry) => entry.startsWith("#") &&
|
|
934
|
+
entry.length > 1 &&
|
|
935
|
+
!entry.includes(",") &&
|
|
936
|
+
!entry.includes("]"))) {
|
|
937
|
+
blockedBy = entries.map((entry) => entry.slice(1));
|
|
938
|
+
tail = tail.slice(0, at);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
815
941
|
}
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
942
|
+
let owner;
|
|
943
|
+
if (tail.endsWith(")")) {
|
|
944
|
+
const at = tail.lastIndexOf(" (");
|
|
945
|
+
if (at > 0) {
|
|
946
|
+
const inner = tail.slice(at + 2, -1);
|
|
947
|
+
// `[^()]*` — the owner group cannot itself contain parentheses.
|
|
948
|
+
if (!inner.includes("(") && !inner.includes(")")) {
|
|
949
|
+
owner = inner;
|
|
950
|
+
tail = tail.slice(0, at);
|
|
825
951
|
}
|
|
826
952
|
}
|
|
827
953
|
}
|
|
954
|
+
// `(.+?)` needs at least one character of subject.
|
|
955
|
+
if (tail.length === 0)
|
|
956
|
+
return undefined;
|
|
957
|
+
return {
|
|
958
|
+
id,
|
|
959
|
+
subject: tail,
|
|
960
|
+
status: status,
|
|
961
|
+
...(owner ? { owner } : {}),
|
|
962
|
+
blockedBy,
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Best-effort parse of a TaskList result — the SDK's AUTHORITATIVE snapshot of the task list.
|
|
967
|
+
* Upstream #974 (v0.67.0).
|
|
968
|
+
*
|
|
969
|
+
* Both shapes are ported, and both are measured: the structured `{ tasks: [...] }` is what the
|
|
970
|
+
* single real TaskList in the local corpus carries in `toolUseResult`, and its `content` is the
|
|
971
|
+
* `#<id> [<status>] <subject>` listing the textual arm below parses. One sample is too few to drop
|
|
972
|
+
* either arm, so neither is dropped.
|
|
973
|
+
*/
|
|
974
|
+
export function parseTaskListOutput(content) {
|
|
975
|
+
const structured = parseJsonToolOutput(content, (parsed) => Boolean(parsed) &&
|
|
976
|
+
typeof parsed === "object" &&
|
|
977
|
+
Array.isArray(parsed.tasks) &&
|
|
978
|
+
parsed.tasks.every((task) => Boolean(task) &&
|
|
979
|
+
typeof task.id === "string" &&
|
|
980
|
+
typeof task.subject === "string" &&
|
|
981
|
+
TASK_STATUSES.has(task.status)));
|
|
982
|
+
if (structured)
|
|
983
|
+
return structured;
|
|
984
|
+
for (const text of toolOutputTexts(content)) {
|
|
985
|
+
if (text.trim() === "No tasks found")
|
|
986
|
+
return { tasks: [] };
|
|
987
|
+
const tasks = [];
|
|
988
|
+
let clean = true;
|
|
989
|
+
for (const line of text.trim().split("\n")) {
|
|
990
|
+
const task = parseTaskListLine(line);
|
|
991
|
+
// A single unparseable line means this text is not a task listing at all — take none of it
|
|
992
|
+
// rather than a truncated plan that reads as complete.
|
|
993
|
+
if (!task) {
|
|
994
|
+
clean = false;
|
|
995
|
+
break;
|
|
996
|
+
}
|
|
997
|
+
tasks.push(task);
|
|
998
|
+
}
|
|
999
|
+
if (clean && tasks.length > 0)
|
|
1000
|
+
return { tasks };
|
|
1001
|
+
}
|
|
1002
|
+
return undefined;
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Best-effort parse of a TaskUpdate result. Upstream #974 (v0.67.0).
|
|
1006
|
+
*
|
|
1007
|
+
* The point is the `success` flag: a TaskUpdate can fail LOGICALLY (unknown task id) while the
|
|
1008
|
+
* tool_result itself is not flagged `is_error`. Applying the requested mutation in that case
|
|
1009
|
+
* writes a task the CLI does not have. `expectedTaskId` lets the textual arm attribute a
|
|
1010
|
+
* "Task #<id> not found" line when the structured output is absent.
|
|
1011
|
+
*/
|
|
1012
|
+
export function parseTaskUpdateOutput(content, expectedTaskId) {
|
|
1013
|
+
const structured = parseJsonToolOutput(content, (parsed) => Boolean(parsed) &&
|
|
1014
|
+
typeof parsed === "object" &&
|
|
1015
|
+
typeof parsed.success === "boolean" &&
|
|
1016
|
+
typeof parsed.taskId === "string" &&
|
|
1017
|
+
Array.isArray(parsed.updatedFields));
|
|
1018
|
+
if (structured)
|
|
1019
|
+
return structured;
|
|
1020
|
+
for (const text of toolOutputTexts(content)) {
|
|
1021
|
+
const notFound = /^Task #(\S+) not found$/.exec(text.trim());
|
|
1022
|
+
const taskId = notFound?.[1] ?? expectedTaskId;
|
|
1023
|
+
if (taskId && (notFound || text.trim() === "Failed to delete task")) {
|
|
1024
|
+
return { success: false, taskId, updatedFields: [], error: text.trim() };
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
828
1027
|
return undefined;
|
|
829
1028
|
}
|
|
830
1029
|
export function applyTaskCreate(state, input, output) {
|
|
@@ -858,9 +1057,33 @@ export function applyTaskUpdate(state, input) {
|
|
|
858
1057
|
description: input.description ?? existing?.description,
|
|
859
1058
|
});
|
|
860
1059
|
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Reconcile the accumulated task list against the SDK's authoritative TaskList snapshot.
|
|
1062
|
+
* Upstream #974 (v0.67.0).
|
|
1063
|
+
*
|
|
1064
|
+
* This is what repairs a RESUMED or COMPACTED session: the TaskCreate calls that built the list
|
|
1065
|
+
* may be gone from replay history, so the accumulated state under-reports. The snapshot replaces
|
|
1066
|
+
* the list wholesale — entries it omits were deleted and must disappear — while `activeForm` and
|
|
1067
|
+
* `description` are carried over from the previous entry, because the TaskList output does not
|
|
1068
|
+
* carry them and dropping them would silently degrade the plan text.
|
|
1069
|
+
*/
|
|
1070
|
+
export function applyTaskList(state, output) {
|
|
1071
|
+
const previous = new Map(state);
|
|
1072
|
+
state.clear();
|
|
1073
|
+
for (const task of output.tasks) {
|
|
1074
|
+
const existing = previous.get(task.id);
|
|
1075
|
+
state.set(task.id, {
|
|
1076
|
+
subject: task.subject,
|
|
1077
|
+
status: task.status,
|
|
1078
|
+
activeForm: existing?.activeForm,
|
|
1079
|
+
description: existing?.description,
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
861
1083
|
export function taskStateToPlanEntries(state) {
|
|
862
1084
|
return Array.from(state.values()).map((task) => ({
|
|
863
|
-
|
|
1085
|
+
// Same rule as `planEntries` above — the two plan sources must not drift.
|
|
1086
|
+
content: task.status === "in_progress" && task.activeForm ? task.activeForm : task.subject,
|
|
864
1087
|
status: task.status,
|
|
865
1088
|
priority: "medium",
|
|
866
1089
|
}));
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.11.1",
|
|
7
7
|
"description": "Run the official Claude Code TUI in Zed's agent panel on your Claude Pro/Max subscription — an ACP-over-PTY bridge created for Anthropic's billing split (paused June 15; see README).",
|
|
8
8
|
"main": "dist/lib.js",
|
|
9
9
|
"types": "dist/lib.d.ts",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@agentclientprotocol/sdk": "1.3.0",
|
|
67
|
-
"@anthropic-ai/claude-agent-sdk": "0.3.
|
|
67
|
+
"@anthropic-ai/claude-agent-sdk": "0.3.232",
|
|
68
68
|
"node-pty": "1.1.0",
|
|
69
69
|
"zod": "^3.25.0 || ^4.0.0"
|
|
70
70
|
},
|