@super-one/cli 0.50.4-alpha → 0.50.6-alpha

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 (3) hide show
  1. package/MANIFEST.json +2 -2
  2. package/lib/cli.mjs +681 -381
  3. package/package.json +1 -1
package/lib/cli.mjs CHANGED
@@ -256,7 +256,7 @@ var init_host_action_superone_descriptors = __esm({
256
256
  },
257
257
  "worktree": {
258
258
  "type": "object",
259
- "description": 'Request a host-managed worktree for same-repo isolation while cwd stays omitted or at the project root. Set enabled, baseBranch, and mode; use a unique branchName with branch. See read_manual({ domain: "product", topic: "collaboration" }) for implementer and reviewer recipes.',
259
+ "description": 'Request a host-managed worktree for same-repo isolation while cwd stays omitted or at the project root. Use for parallel implementers (mode branch + unique branchName), not for default read-only review of the current shared checkout. Use mode detach only when reviewing a feature branch another implementer already has checked out. See read_manual({ domain: "product", topic: "collaboration" }).',
260
260
  "properties": {
261
261
  "enabled": {
262
262
  "type": "boolean"
@@ -12027,8 +12027,11 @@ var init_session_runtime = __esm({
12027
12027
  const s2 = this.live.get(sessionId);
12028
12028
  return s2 ? this.clone(s2) : null;
12029
12029
  }
12030
- list(projectId) {
12031
- return [...this.live.values()].filter((s2) => !projectId || s2.projectId === projectId).map((s2) => this.clone(s2));
12030
+ list(projectId, options) {
12031
+ const rows = [...this.live.values()].filter((s2) => !projectId || s2.projectId === projectId).sort((a, b2) => (b2.updatedAt ?? 0) - (a.updatedAt ?? 0) || (b2.createdAt ?? 0) - (a.createdAt ?? 0));
12032
+ const offset = Math.max(0, options?.offset ?? 0);
12033
+ const limited = options?.limit != null && options.limit >= 0 ? rows.slice(offset, offset + options.limit) : offset > 0 ? rows.slice(offset) : rows;
12034
+ return limited.map((s2) => this.clone(s2));
12032
12035
  }
12033
12036
  snapshotSequence() {
12034
12037
  return this.events.headSequence();
@@ -18529,9 +18532,23 @@ var init_turn_attachments = __esm({
18529
18532
  }
18530
18533
  });
18531
18534
 
18535
+ // ../../packages/shared/src/agent-transcript-path.ts
18536
+ function isAgentTranscriptAbsolutePath(filePath) {
18537
+ if (!filePath || filePath.includes("\0")) return false;
18538
+ const norm = filePath.replace(/\\/g, "/");
18539
+ if (!norm.startsWith("/") && !/^[A-Za-z]:\//.test(norm)) return false;
18540
+ return norm.includes("/.grok/sessions/") || norm.includes("/.claude/projects/") || /\/\.grok\/sessions\/?$/.test(norm) || /\/\.claude\/projects\/?$/.test(norm);
18541
+ }
18542
+ var init_agent_transcript_path = __esm({
18543
+ "../../packages/shared/src/agent-transcript-path.ts"() {
18544
+ "use strict";
18545
+ }
18546
+ });
18547
+
18532
18548
  // ../../packages/runtime/src/fs/path-security.ts
18533
18549
  import { realpathSync as realpathSync2, existsSync as existsSync11, lstatSync, statSync } from "node:fs";
18534
- import { isAbsolute, join as join9, normalize, resolve, sep } from "node:path";
18550
+ import { homedir as homedir3 } from "node:os";
18551
+ import { dirname as dirname5, isAbsolute, join as join9, normalize, resolve, sep } from "node:path";
18535
18552
  function resolveProjectPath(projectRoot2, relativePath) {
18536
18553
  if (relativePath.includes("\0")) {
18537
18554
  return { ok: false, reason: "null byte in path" };
@@ -18600,6 +18617,41 @@ function isToolOutputRelativePath(relativePath) {
18600
18617
  if (n === "." || n === "" || n === ".." || n.startsWith("../")) return false;
18601
18618
  return n === "temp" || n.startsWith(TOOL_OUTPUT_REL_PREFIX);
18602
18619
  }
18620
+ function getAgentTranscriptRoots(opts) {
18621
+ const homeDir = opts?.homeDir ?? homedir3();
18622
+ return [
18623
+ join9(homeDir, ".grok", "sessions"),
18624
+ join9(homeDir, ".claude", "projects")
18625
+ ];
18626
+ }
18627
+ function assertAgentTranscriptAbsolutePath(filePath, opts) {
18628
+ if (!isAgentTranscriptAbsolutePath(filePath)) return false;
18629
+ if (!isAbsolute(filePath) && !filePath.replace(/\\/g, "/").startsWith("/")) return false;
18630
+ const candidate = normalizeSep(resolve(filePath));
18631
+ const roots = getAgentTranscriptRoots(opts).map((root) => {
18632
+ const resolved = normalizeSep(resolve(root));
18633
+ const real = existsSync11(resolved) ? normalizeSep(resolveRealPath(resolved)) : resolved;
18634
+ return { resolved, real };
18635
+ });
18636
+ const underAnyRoot = (abs) => {
18637
+ const n = normalizeSep(abs);
18638
+ return roots.some(
18639
+ (r) => n === r.resolved || n.startsWith(r.resolved + sep) || n === r.real || n.startsWith(r.real + sep)
18640
+ );
18641
+ };
18642
+ if (!underAnyRoot(candidate)) return false;
18643
+ if (existsSync11(candidate)) {
18644
+ return underAnyRoot(resolveRealPath(candidate));
18645
+ }
18646
+ let existing = candidate;
18647
+ while (!existsSync11(existing)) {
18648
+ const parent = dirname5(existing);
18649
+ if (parent === existing) return true;
18650
+ if (!underAnyRoot(parent)) return true;
18651
+ existing = parent;
18652
+ }
18653
+ return underAnyRoot(resolveRealPath(existing));
18654
+ }
18603
18655
  function pathKind(absolutePath) {
18604
18656
  try {
18605
18657
  const st = lstatSync(absolutePath);
@@ -18644,6 +18696,8 @@ var TOOL_OUTPUT_REL_PREFIX;
18644
18696
  var init_path_security = __esm({
18645
18697
  "../../packages/runtime/src/fs/path-security.ts"() {
18646
18698
  "use strict";
18699
+ init_agent_transcript_path();
18700
+ init_agent_transcript_path();
18647
18701
  TOOL_OUTPUT_REL_PREFIX = "temp/";
18648
18702
  }
18649
18703
  });
@@ -18734,7 +18788,7 @@ import {
18734
18788
  statSync as statSync3,
18735
18789
  writeFileSync as writeFileSync4
18736
18790
  } from "node:fs";
18737
- import { basename, dirname as dirname5, join as join11, resolve as resolve2, sep as sep2 } from "node:path";
18791
+ import { basename, dirname as dirname6, join as join11, resolve as resolve2, sep as sep2 } from "node:path";
18738
18792
  import { homedir as osHomedir3 } from "node:os";
18739
18793
  function homeOf2(opts) {
18740
18794
  return opts?.homeDir ?? osHomedir3();
@@ -19068,7 +19122,7 @@ function installManagedSkill(provider, cwd, input, opts) {
19068
19122
  code: "invalid_argument"
19069
19123
  });
19070
19124
  }
19071
- mkdirSync6(dirname5(abs), { recursive: true });
19125
+ mkdirSync6(dirname6(abs), { recursive: true });
19072
19126
  writeFileSync4(abs, content, "utf8");
19073
19127
  }
19074
19128
  } catch (err) {
@@ -19100,7 +19154,7 @@ var init_skills_manage = __esm({
19100
19154
 
19101
19155
  // ../../packages/runtime/src/fs/mcp-config-claude.ts
19102
19156
  import { existsSync as existsSync14, mkdirSync as mkdirSync7, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "node:fs";
19103
- import { dirname as dirname6, join as join12 } from "node:path";
19157
+ import { dirname as dirname7, join as join12 } from "node:path";
19104
19158
  import { homedir as osHomedir4 } from "node:os";
19105
19159
  function homeOf3(opts) {
19106
19160
  return opts?.homeDir ?? osHomedir4();
@@ -19123,7 +19177,7 @@ function readJsonFile(filePath) {
19123
19177
  }
19124
19178
  }
19125
19179
  function writeJsonFile(filePath, data) {
19126
- mkdirSync7(dirname6(filePath), { recursive: true });
19180
+ mkdirSync7(dirname7(filePath), { recursive: true });
19127
19181
  writeFileSync5(filePath, JSON.stringify(data, null, 2) + "\n", "utf8");
19128
19182
  }
19129
19183
  function extractServers(config2, scope) {
@@ -20154,7 +20208,7 @@ var init_dist = __esm({
20154
20208
 
20155
20209
  // ../../packages/runtime/src/fs/mcp-config-codex.ts
20156
20210
  import { existsSync as existsSync15, mkdirSync as mkdirSync8, readFileSync as readFileSync10, writeFileSync as writeFileSync6 } from "node:fs";
20157
- import { dirname as dirname7, join as join13 } from "node:path";
20211
+ import { dirname as dirname8, join as join13 } from "node:path";
20158
20212
  import { homedir as osHomedir5 } from "node:os";
20159
20213
  function homeOf4(opts) {
20160
20214
  return opts?.homeDir ?? osHomedir5();
@@ -20176,7 +20230,7 @@ function readConfigFile2(filePath) {
20176
20230
  }
20177
20231
  }
20178
20232
  function writeConfigFile(filePath, data) {
20179
- mkdirSync8(dirname7(filePath), { recursive: true });
20233
+ mkdirSync8(dirname8(filePath), { recursive: true });
20180
20234
  writeFileSync6(filePath, stringify(data), "utf8");
20181
20235
  }
20182
20236
  function parseConfigFile(filePath, scope) {
@@ -20434,7 +20488,7 @@ import {
20434
20488
  statSync as statSync4,
20435
20489
  writeFileSync as writeFileSync7
20436
20490
  } from "node:fs";
20437
- import { dirname as dirname8, join as join14, resolve as resolve3 } from "node:path";
20491
+ import { dirname as dirname9, join as join14, resolve as resolve3 } from "node:path";
20438
20492
  import { homedir as osHomedir6 } from "node:os";
20439
20493
  function homeOf5(opts) {
20440
20494
  return opts?.homeDir ?? osHomedir6();
@@ -20491,7 +20545,7 @@ function getMarketplaceScopeMap(cwd, opts) {
20491
20545
  return map2;
20492
20546
  }
20493
20547
  function writeSettingsJson(filePath, data) {
20494
- mkdirSync9(dirname8(filePath), { recursive: true });
20548
+ mkdirSync9(dirname9(filePath), { recursive: true });
20495
20549
  writeFileSync7(filePath, JSON.stringify(data, null, 2) + "\n");
20496
20550
  }
20497
20551
  function removeMarketplaceFromSettings(filePath, name) {
@@ -21030,7 +21084,7 @@ var init_plugins_manage = __esm({
21030
21084
 
21031
21085
  // ../../packages/runtime/src/fs/hooks-config.ts
21032
21086
  import { existsSync as existsSync17, mkdirSync as mkdirSync10, readFileSync as readFileSync12, writeFileSync as writeFileSync8 } from "node:fs";
21033
- import { dirname as dirname9, join as join15 } from "node:path";
21087
+ import { dirname as dirname10, join as join15 } from "node:path";
21034
21088
  import { homedir as osHomedir7 } from "node:os";
21035
21089
  function homeOf6(opts) {
21036
21090
  return opts?.homeDir ?? osHomedir7();
@@ -21058,7 +21112,7 @@ function readJsonFile2(filePath) {
21058
21112
  }
21059
21113
  }
21060
21114
  function writeJsonFile2(filePath, data) {
21061
- mkdirSync10(dirname9(filePath), { recursive: true });
21115
+ mkdirSync10(dirname10(filePath), { recursive: true });
21062
21116
  writeFileSync8(filePath, JSON.stringify(data, null, 2));
21063
21117
  }
21064
21118
  function getHooksMap(data) {
@@ -40141,6 +40195,265 @@ var init_slash_filter = __esm({
40141
40195
  }
40142
40196
  });
40143
40197
 
40198
+ // ../../packages/shared/src/tool-ui.ts
40199
+ function normalizeToolIdKey(id) {
40200
+ return id.trim().toLowerCase().replace(/[\s-]+/g, "_");
40201
+ }
40202
+ function uiToolNameFromId(id) {
40203
+ if (!id || typeof id !== "string") return null;
40204
+ if (/[\s`/:]/.test(id) && !TOOL_ID_TO_UI_NAME[normalizeToolIdKey(id)]) return null;
40205
+ const key = normalizeToolIdKey(id);
40206
+ return TOOL_ID_TO_UI_NAME[key] ?? null;
40207
+ }
40208
+ function bytesOrStringToText(value) {
40209
+ if (typeof value === "string") return value;
40210
+ if (Array.isArray(value) && value.length > 0 && value.every((n) => typeof n === "number")) {
40211
+ try {
40212
+ return new TextDecoder("utf-8", { fatal: false }).decode(Uint8Array.from(value));
40213
+ } catch {
40214
+ return "";
40215
+ }
40216
+ }
40217
+ return "";
40218
+ }
40219
+ function formatSearchToolPayload(obj) {
40220
+ let data = obj;
40221
+ if (typeof obj.content === "string" && obj.content.trim()) {
40222
+ try {
40223
+ data = JSON.parse(obj.content);
40224
+ } catch {
40225
+ if (!obj.results) return obj.content;
40226
+ }
40227
+ }
40228
+ if (!data || typeof data !== "object") return null;
40229
+ const root = data;
40230
+ const results = root.results;
40231
+ if (!Array.isArray(results)) {
40232
+ if (typeof root.content === "string") return root.content;
40233
+ return null;
40234
+ }
40235
+ const lines = [];
40236
+ const count = typeof obj.result_count === "number" ? obj.result_count : results.length;
40237
+ lines.push(`Found ${count} tool${count === 1 ? "" : "s"}`);
40238
+ for (const entry of results) {
40239
+ if (!entry || typeof entry !== "object") continue;
40240
+ const group = entry;
40241
+ const server = typeof group.server === "string" ? group.server : "MCP";
40242
+ lines.push("");
40243
+ lines.push(`[${server}]`);
40244
+ const tools = group.tools;
40245
+ if (!Array.isArray(tools)) continue;
40246
+ for (const tool of tools) {
40247
+ if (!tool || typeof tool !== "object") continue;
40248
+ const t = tool;
40249
+ const name = typeof t.tool_name === "string" ? t.tool_name : typeof t.name === "string" ? t.name : "tool";
40250
+ const desc = typeof t.description === "string" ? t.description : "";
40251
+ const score = typeof t.score === "number" ? ` \xB7 ${t.score.toFixed(1)}` : "";
40252
+ lines.push(desc ? ` ${name}${score} \u2014 ${desc}` : ` ${name}${score}`);
40253
+ }
40254
+ }
40255
+ if (typeof root.note === "string" && root.note.trim()) {
40256
+ lines.push("");
40257
+ lines.push(root.note);
40258
+ }
40259
+ return lines.join("\n").trim() || null;
40260
+ }
40261
+ function isAgentOutputEnvelope(obj) {
40262
+ const t = obj.type;
40263
+ return t === "MCP" || t === "ListDir" || t === "list_dir" || t === "LS" || t === "Todo" || t === "SearchTool" || t === "GrepSearch" || t === "grep" || obj.TodosUpdated != null || obj.Content != null && typeof obj.Content === "object" || Array.isArray(obj.results) || obj.action != null && typeof obj.action === "object";
40264
+ }
40265
+ function formatAgentToolOutput(raw) {
40266
+ if (raw == null) return "";
40267
+ if (typeof raw === "string") {
40268
+ const trimmed = raw.trim();
40269
+ if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
40270
+ try {
40271
+ const parsed = JSON.parse(trimmed);
40272
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed) && isAgentOutputEnvelope(parsed)) {
40273
+ return formatAgentToolOutput(parsed);
40274
+ }
40275
+ return raw;
40276
+ } catch {
40277
+ return raw;
40278
+ }
40279
+ }
40280
+ return raw;
40281
+ }
40282
+ if (typeof raw !== "object") return String(raw);
40283
+ const obj = raw;
40284
+ if (obj.type === "MCP" && obj.output != null) {
40285
+ if (typeof obj.output === "string") return obj.output;
40286
+ if (typeof obj.output === "object") {
40287
+ const values = Object.values(obj.output);
40288
+ if (values.length === 1 && typeof values[0] === "string") return values[0];
40289
+ }
40290
+ }
40291
+ const listContent = obj.Content ?? obj.content;
40292
+ if ((obj.type === "ListDir" || obj.type === "list_dir" || obj.type === "LS") && listContent && typeof listContent === "object") {
40293
+ const body = listContent;
40294
+ if (typeof body.content === "string" && body.content.trim()) return body.content;
40295
+ if (typeof body.text === "string" && body.text.trim()) return body.text;
40296
+ }
40297
+ if ((obj.type === "ListDir" || obj.type === "list_dir") && typeof obj.Content === "string") {
40298
+ return obj.Content;
40299
+ }
40300
+ if (typeof obj.content === "string" && obj.content.includes("\n") && (obj.type === "ListDir" || obj.absolute_root_path != null)) {
40301
+ return obj.content;
40302
+ }
40303
+ if (obj.type === "Todo" || obj.TodosUpdated != null) {
40304
+ const todos = obj.TodosUpdated;
40305
+ if (todos && typeof todos === "object") {
40306
+ const t = todos;
40307
+ if (typeof t.summary_for_prompt === "string" && t.summary_for_prompt.trim()) return t.summary_for_prompt;
40308
+ if (typeof t.summary === "string" && t.summary.trim()) return t.summary;
40309
+ }
40310
+ }
40311
+ if (obj.type === "SearchTool" || Array.isArray(obj.results) || obj.result_count != null && (obj.content != null || obj.results != null)) {
40312
+ const formatted = formatSearchToolPayload(obj);
40313
+ if (formatted) return formatted;
40314
+ }
40315
+ if (obj.type === "GrepSearch" || obj.type === "grep" || Array.isArray(obj.stdout)) {
40316
+ const text = bytesOrStringToText(obj.stdout ?? obj.content ?? obj.output);
40317
+ if (text) return text;
40318
+ }
40319
+ const action = obj.action;
40320
+ if (action && typeof action === "object") {
40321
+ const a = action;
40322
+ if (a.type === "search") {
40323
+ const lines = [];
40324
+ if (typeof a.query === "string") lines.push(`Query: ${a.query}`);
40325
+ const sources = a.sources;
40326
+ if (Array.isArray(sources)) {
40327
+ for (const s2 of sources) {
40328
+ if (s2 && typeof s2 === "object") {
40329
+ const src = s2;
40330
+ if (typeof src.url === "string") lines.push(src.url);
40331
+ else if (typeof src.title === "string") lines.push(src.title);
40332
+ }
40333
+ }
40334
+ }
40335
+ if (typeof a.result === "string") lines.push(a.result);
40336
+ if (typeof a.snippet === "string") lines.push(a.snippet);
40337
+ if (lines.length > 0) return lines.join("\n");
40338
+ }
40339
+ }
40340
+ if (listContent && typeof listContent === "object") {
40341
+ const body = listContent;
40342
+ for (const key of ["content", "text", "output", "result"]) {
40343
+ if (typeof body[key] === "string" && body[key].trim()) {
40344
+ if (obj.type === "ListDir" || obj.type === "list_dir" || obj.type === "LS" || body.absolute_root_path != null || /^[\s-]*\//.test(body[key])) {
40345
+ return body[key];
40346
+ }
40347
+ }
40348
+ }
40349
+ }
40350
+ if (typeof obj.run_id === "string" || typeof obj.runId === "string") {
40351
+ try {
40352
+ return JSON.stringify(raw);
40353
+ } catch {
40354
+ return String(raw);
40355
+ }
40356
+ }
40357
+ for (const key of ["result", "output", "text", "stdout", "message", "summary"]) {
40358
+ const v2 = obj[key];
40359
+ if (typeof v2 === "string" && v2.trim()) return v2;
40360
+ }
40361
+ if (listContent && typeof listContent === "object") {
40362
+ const body = listContent;
40363
+ for (const key of ["content", "text", "output", "result"]) {
40364
+ if (typeof body[key] === "string" && body[key].trim()) return body[key];
40365
+ }
40366
+ }
40367
+ try {
40368
+ return JSON.stringify(raw, null, 2);
40369
+ } catch {
40370
+ return String(raw);
40371
+ }
40372
+ }
40373
+ var TOOL_ID_TO_UI_NAME;
40374
+ var init_tool_ui = __esm({
40375
+ "../../packages/shared/src/tool-ui.ts"() {
40376
+ "use strict";
40377
+ TOOL_ID_TO_UI_NAME = {
40378
+ read: "Read",
40379
+ read_file: "Read",
40380
+ readfile: "Read",
40381
+ edit: "Edit",
40382
+ search_replace: "Edit",
40383
+ str_replace: "Edit",
40384
+ apply_patch: "Edit",
40385
+ write: "Write",
40386
+ write_file: "Write",
40387
+ writefile: "Write",
40388
+ create_file: "Write",
40389
+ bash: "Bash",
40390
+ shell: "Bash",
40391
+ run_terminal_command: "Bash",
40392
+ run_terminal_cmd: "Bash",
40393
+ run_command: "Bash",
40394
+ execute: "Bash",
40395
+ command: "Bash",
40396
+ grep: "Grep",
40397
+ search: "Grep",
40398
+ ripgrep: "Grep",
40399
+ glob: "Glob",
40400
+ find_files: "Glob",
40401
+ list_dir: "LS",
40402
+ listdir: "LS",
40403
+ ls: "LS",
40404
+ web_fetch: "WebFetch",
40405
+ webfetch: "WebFetch",
40406
+ fetch: "WebFetch",
40407
+ open_page: "WebFetch",
40408
+ open_page_with_find: "WebFetch",
40409
+ web_search: "WebSearch",
40410
+ websearch: "WebSearch",
40411
+ todo_write: "TodoWrite",
40412
+ todowrite: "TodoWrite",
40413
+ todo: "TodoWrite",
40414
+ search_tool: "SearchTools",
40415
+ searchtool: "SearchTools",
40416
+ tool_search: "SearchTools",
40417
+ toolsearch: "SearchTools",
40418
+ use_tool: "UseTool",
40419
+ usetool: "UseTool",
40420
+ call_tool: "UseTool",
40421
+ spawn_subagent: "Agent",
40422
+ spawn_agent: "Agent",
40423
+ agent: "Agent",
40424
+ task: "Task",
40425
+ workflow: "Workflow",
40426
+ run_workflow: "Workflow",
40427
+ memory_search: "MemorySearch",
40428
+ memorysearch: "MemorySearch",
40429
+ search_memory: "MemorySearch",
40430
+ ask_user_question: "AskUserQuestion",
40431
+ askuserquestion: "AskUserQuestion",
40432
+ get_task_output: "TaskOutput",
40433
+ get_command_or_subagent_output: "TaskOutput",
40434
+ get_terminal_command_output: "TaskOutput",
40435
+ wait_tasks: "TaskOutput",
40436
+ wait_commands_or_subagents: "TaskOutput",
40437
+ kill_task: "KillTask",
40438
+ kill_command_or_subagent: "KillTask",
40439
+ kill_terminal_command: "KillTask",
40440
+ enter_plan_mode: "EnterPlanMode",
40441
+ exit_plan_mode: "ExitPlanMode",
40442
+ skill: "Skill",
40443
+ image_gen: "ImageGen",
40444
+ image_edit: "ImageEdit",
40445
+ image_to_video: "ImageToVideo",
40446
+ reference_to_video: "ReferenceToVideo",
40447
+ video_gen: "VideoGen",
40448
+ monitor: "Monitor",
40449
+ update_goal: "UpdateGoal",
40450
+ scheduler_create: "SchedulerCreate",
40451
+ scheduler_delete: "SchedulerDelete",
40452
+ scheduler_list: "SchedulerList"
40453
+ };
40454
+ }
40455
+ });
40456
+
40144
40457
  // ../../packages/acp/src/tool-normalization.ts
40145
40458
  function textFromContent(content) {
40146
40459
  if (!content) return "";
@@ -40209,14 +40522,8 @@ function extractFilePath(tool, raw, diffs) {
40209
40522
  "to"
40210
40523
  ]);
40211
40524
  }
40212
- function normalizeToolId(id) {
40213
- return id.trim().toLowerCase().replace(/[\s-]+/g, "_");
40214
- }
40215
40525
  function nameFromToolId(id) {
40216
- if (!id || typeof id !== "string") return null;
40217
- if (/[\s`/:]/.test(id) && !TOOL_ID_TO_NAME[normalizeToolId(id)]) return null;
40218
- const key = normalizeToolId(id);
40219
- return TOOL_ID_TO_NAME[key] ?? null;
40526
+ return uiToolNameFromId(id);
40220
40527
  }
40221
40528
  function nameFromVariant(raw) {
40222
40529
  const variant = pickString(raw, ["variant", "tool", "name", "toolName", "tool_name"]);
@@ -40492,12 +40799,17 @@ function normalizeInput(toolName, kind, raw, filePath, diffs, terminalCommand) {
40492
40799
  if (raw.limit != null) out.limit = raw.limit;
40493
40800
  return Object.keys(out).length > 0 ? out : { ...raw };
40494
40801
  }
40802
+ case "Agent":
40495
40803
  case "Task": {
40496
40804
  const out = {};
40497
40805
  const desc = pickString(raw, ["description", "prompt", "name", "task", "objective"]);
40498
40806
  if (desc) out.description = desc;
40499
40807
  const sub = pickString(raw, ["subagent_type", "agent_type", "agent", "type"]);
40500
40808
  if (sub) out.subagent_type = sub;
40809
+ const prompt = pickString(raw, ["prompt"]);
40810
+ if (prompt) out.prompt = prompt;
40811
+ const model = pickString(raw, ["model"]);
40812
+ if (model) out.model = model;
40501
40813
  if (raw.run_in_background === true || raw.background === true) out.run_in_background = true;
40502
40814
  return Object.keys(out).length > 0 ? out : { ...raw };
40503
40815
  }
@@ -40593,87 +40905,11 @@ function toolUseBlock(tool, opts) {
40593
40905
  toolFilePath: normalized.toolFilePath
40594
40906
  };
40595
40907
  }
40596
- var TOOL_ID_TO_NAME, GREP_NON_PATTERN_TITLES;
40908
+ var GREP_NON_PATTERN_TITLES;
40597
40909
  var init_tool_normalization = __esm({
40598
40910
  "../../packages/acp/src/tool-normalization.ts"() {
40599
40911
  "use strict";
40600
- TOOL_ID_TO_NAME = {
40601
- read: "Read",
40602
- read_file: "Read",
40603
- readfile: "Read",
40604
- edit: "Edit",
40605
- search_replace: "Edit",
40606
- str_replace: "Edit",
40607
- apply_patch: "Edit",
40608
- write: "Write",
40609
- write_file: "Write",
40610
- writefile: "Write",
40611
- create_file: "Write",
40612
- bash: "Bash",
40613
- shell: "Bash",
40614
- run_terminal_command: "Bash",
40615
- run_terminal_cmd: "Bash",
40616
- run_command: "Bash",
40617
- execute: "Bash",
40618
- command: "Bash",
40619
- grep: "Grep",
40620
- search: "Grep",
40621
- ripgrep: "Grep",
40622
- glob: "Glob",
40623
- find_files: "Glob",
40624
- list_dir: "LS",
40625
- listdir: "LS",
40626
- ls: "LS",
40627
- web_fetch: "WebFetch",
40628
- webfetch: "WebFetch",
40629
- fetch: "WebFetch",
40630
- open_page: "WebFetch",
40631
- open_page_with_find: "WebFetch",
40632
- web_search: "WebSearch",
40633
- websearch: "WebSearch",
40634
- todo_write: "TodoWrite",
40635
- todowrite: "TodoWrite",
40636
- todo: "TodoWrite",
40637
- search_tool: "SearchTools",
40638
- searchtool: "SearchTools",
40639
- tool_search: "SearchTools",
40640
- toolsearch: "SearchTools",
40641
- use_tool: "UseTool",
40642
- usetool: "UseTool",
40643
- call_tool: "UseTool",
40644
- spawn_subagent: "Task",
40645
- spawn_agent: "Task",
40646
- task: "Task",
40647
- agent: "Task",
40648
- workflow: "Workflow",
40649
- run_workflow: "Workflow",
40650
- memory_search: "MemorySearch",
40651
- memorysearch: "MemorySearch",
40652
- search_memory: "MemorySearch",
40653
- ask_user_question: "AskUserQuestion",
40654
- askuserquestion: "AskUserQuestion",
40655
- get_task_output: "TaskOutput",
40656
- get_command_or_subagent_output: "TaskOutput",
40657
- get_terminal_command_output: "TaskOutput",
40658
- wait_tasks: "TaskOutput",
40659
- wait_commands_or_subagents: "TaskOutput",
40660
- kill_task: "KillTask",
40661
- kill_command_or_subagent: "KillTask",
40662
- kill_terminal_command: "KillTask",
40663
- enter_plan_mode: "EnterPlanMode",
40664
- exit_plan_mode: "ExitPlanMode",
40665
- skill: "Skill",
40666
- image_gen: "ImageGen",
40667
- image_edit: "ImageEdit",
40668
- image_to_video: "ImageToVideo",
40669
- reference_to_video: "ReferenceToVideo",
40670
- video_gen: "VideoGen",
40671
- monitor: "Monitor",
40672
- update_goal: "UpdateGoal",
40673
- scheduler_create: "SchedulerCreate",
40674
- scheduler_delete: "SchedulerDelete",
40675
- scheduler_list: "SchedulerList"
40676
- };
40912
+ init_tool_ui();
40677
40913
  GREP_NON_PATTERN_TITLES = /* @__PURE__ */ new Set([
40678
40914
  "grep",
40679
40915
  "Grep",
@@ -40687,170 +40923,8 @@ var init_tool_normalization = __esm({
40687
40923
  });
40688
40924
 
40689
40925
  // ../../packages/acp/src/tool-result-map.ts
40690
- function bytesOrStringToText(value) {
40691
- if (typeof value === "string") return value;
40692
- if (Array.isArray(value) && value.every((n) => typeof n === "number")) {
40693
- try {
40694
- return Buffer.from(value).toString("utf8");
40695
- } catch {
40696
- return "";
40697
- }
40698
- }
40699
- return "";
40700
- }
40701
- function formatSearchToolPayload(obj) {
40702
- let data = obj;
40703
- if (typeof obj.content === "string" && obj.content.trim()) {
40704
- try {
40705
- data = JSON.parse(obj.content);
40706
- } catch {
40707
- if (!obj.results) return obj.content;
40708
- }
40709
- }
40710
- if (!data || typeof data !== "object") return null;
40711
- const root = data;
40712
- const results = root.results;
40713
- if (!Array.isArray(results)) {
40714
- if (typeof root.content === "string") return root.content;
40715
- return null;
40716
- }
40717
- const lines = [];
40718
- const count = typeof obj.result_count === "number" ? obj.result_count : results.length;
40719
- lines.push(`Found ${count} tool${count === 1 ? "" : "s"}`);
40720
- for (const entry of results) {
40721
- if (!entry || typeof entry !== "object") continue;
40722
- const group = entry;
40723
- const server = typeof group.server === "string" ? group.server : "MCP";
40724
- lines.push("");
40725
- lines.push(`[${server}]`);
40726
- const tools = group.tools;
40727
- if (!Array.isArray(tools)) continue;
40728
- for (const tool of tools) {
40729
- if (!tool || typeof tool !== "object") continue;
40730
- const t = tool;
40731
- const name = typeof t.tool_name === "string" ? t.tool_name : typeof t.name === "string" ? t.name : "tool";
40732
- const desc = typeof t.description === "string" ? t.description : "";
40733
- const score = typeof t.score === "number" ? ` \xB7 ${t.score.toFixed(1)}` : "";
40734
- lines.push(desc ? ` ${name}${score} \u2014 ${desc}` : ` ${name}${score}`);
40735
- }
40736
- }
40737
- if (typeof root.note === "string" && root.note.trim()) {
40738
- lines.push("");
40739
- lines.push(root.note);
40740
- }
40741
- return lines.join("\n").trim() || null;
40742
- }
40743
- function isAgentOutputEnvelope(obj) {
40744
- const t = obj.type;
40745
- return t === "MCP" || t === "ListDir" || t === "list_dir" || t === "LS" || t === "Todo" || t === "SearchTool" || t === "GrepSearch" || t === "grep" || obj.TodosUpdated != null || obj.Content != null && typeof obj.Content === "object" || Array.isArray(obj.results) || obj.action != null && typeof obj.action === "object";
40746
- }
40747
40926
  function formatAcpRawOutput(raw) {
40748
- if (raw == null) return "";
40749
- if (typeof raw === "string") {
40750
- const trimmed = raw.trim();
40751
- if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
40752
- try {
40753
- const parsed = JSON.parse(trimmed);
40754
- if (parsed && typeof parsed === "object" && !Array.isArray(parsed) && isAgentOutputEnvelope(parsed)) {
40755
- return formatAcpRawOutput(parsed);
40756
- }
40757
- return raw;
40758
- } catch {
40759
- return raw;
40760
- }
40761
- }
40762
- return raw;
40763
- }
40764
- if (typeof raw !== "object") return String(raw);
40765
- const obj = raw;
40766
- if (obj.type === "MCP" && obj.output != null) {
40767
- if (typeof obj.output === "string") return obj.output;
40768
- if (typeof obj.output === "object") {
40769
- const values = Object.values(obj.output);
40770
- if (values.length === 1 && typeof values[0] === "string") return values[0];
40771
- }
40772
- }
40773
- const listContent = obj.Content ?? obj.content;
40774
- if ((obj.type === "ListDir" || obj.type === "list_dir" || obj.type === "LS") && listContent && typeof listContent === "object") {
40775
- const body = listContent;
40776
- if (typeof body.content === "string" && body.content.trim()) return body.content;
40777
- if (typeof body.text === "string" && body.text.trim()) return body.text;
40778
- }
40779
- if ((obj.type === "ListDir" || obj.type === "list_dir") && typeof obj.Content === "string") {
40780
- return obj.Content;
40781
- }
40782
- if (typeof obj.content === "string" && obj.content.includes("\n") && (obj.type === "ListDir" || obj.absolute_root_path != null)) {
40783
- return obj.content;
40784
- }
40785
- if (obj.type === "Todo" || obj.TodosUpdated != null) {
40786
- const todos = obj.TodosUpdated;
40787
- if (todos && typeof todos === "object") {
40788
- const t = todos;
40789
- if (typeof t.summary_for_prompt === "string" && t.summary_for_prompt.trim()) return t.summary_for_prompt;
40790
- if (typeof t.summary === "string" && t.summary.trim()) return t.summary;
40791
- }
40792
- }
40793
- if (obj.type === "SearchTool" || Array.isArray(obj.results) || obj.result_count != null && (obj.content != null || obj.results != null)) {
40794
- const formatted = formatSearchToolPayload(obj);
40795
- if (formatted) return formatted;
40796
- }
40797
- if (obj.type === "GrepSearch" || obj.type === "grep" || Array.isArray(obj.stdout)) {
40798
- const text = bytesOrStringToText(obj.stdout ?? obj.content ?? obj.output);
40799
- if (text) return text;
40800
- }
40801
- const action = obj.action;
40802
- if (action && typeof action === "object") {
40803
- const a = action;
40804
- if (a.type === "search") {
40805
- const lines = [];
40806
- if (typeof a.query === "string") lines.push(`Query: ${a.query}`);
40807
- const sources = a.sources;
40808
- if (Array.isArray(sources)) {
40809
- for (const s2 of sources) {
40810
- if (s2 && typeof s2 === "object") {
40811
- const src = s2;
40812
- if (typeof src.url === "string") lines.push(src.url);
40813
- else if (typeof src.title === "string") lines.push(src.title);
40814
- }
40815
- }
40816
- }
40817
- if (typeof a.result === "string") lines.push(a.result);
40818
- if (typeof a.snippet === "string") lines.push(a.snippet);
40819
- if (lines.length > 0) return lines.join("\n");
40820
- }
40821
- }
40822
- if (listContent && typeof listContent === "object") {
40823
- const body = listContent;
40824
- for (const key of ["content", "text", "output", "result"]) {
40825
- if (typeof body[key] === "string" && body[key].trim()) {
40826
- if (obj.type === "ListDir" || obj.type === "list_dir" || obj.type === "LS" || body.absolute_root_path != null || /^[\s-]*\//.test(body[key])) {
40827
- return body[key];
40828
- }
40829
- }
40830
- }
40831
- }
40832
- if (typeof obj.run_id === "string" || typeof obj.runId === "string") {
40833
- try {
40834
- return JSON.stringify(raw);
40835
- } catch {
40836
- return String(raw);
40837
- }
40838
- }
40839
- for (const key of ["result", "output", "text", "stdout", "message", "summary"]) {
40840
- const v2 = obj[key];
40841
- if (typeof v2 === "string" && v2.trim()) return v2;
40842
- }
40843
- if (listContent && typeof listContent === "object") {
40844
- const body = listContent;
40845
- for (const key of ["content", "text", "output", "result"]) {
40846
- if (typeof body[key] === "string" && body[key].trim()) return body[key];
40847
- }
40848
- }
40849
- try {
40850
- return JSON.stringify(raw, null, 2);
40851
- } catch {
40852
- return String(raw);
40853
- }
40927
+ return formatAgentToolOutput(raw);
40854
40928
  }
40855
40929
  function mediaGenGallerySummary(raw) {
40856
40930
  if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
@@ -40965,18 +41039,25 @@ var init_tool_result_map = __esm({
40965
41039
  "../../packages/acp/src/tool-result-map.ts"() {
40966
41040
  "use strict";
40967
41041
  init_capability_prompt_tags();
41042
+ init_tool_ui();
40968
41043
  init_tool_normalization();
40969
41044
  }
40970
41045
  });
40971
41046
 
40972
41047
  // ../../packages/acp/src/xai-state.ts
40973
- function createXaiCorrelationState() {
41048
+ import { homedir as homedir4 } from "node:os";
41049
+ import { join as join16 } from "node:path";
41050
+ function createXaiCorrelationState(opts) {
40974
41051
  return {
41052
+ ...opts?.cwd ? { cwd: opts.cwd } : {},
40975
41053
  workflowToolByRunId: /* @__PURE__ */ new Map(),
40976
41054
  workflowRevision: /* @__PURE__ */ new Map(),
40977
41055
  workflowStarted: /* @__PURE__ */ new Set(),
40978
41056
  workflowOwnedSubagents: /* @__PURE__ */ new Set(),
41057
+ smokeWorkflowToolIds: /* @__PURE__ */ new Set(),
41058
+ pendingToolNamesById: /* @__PURE__ */ new Map(),
40979
41059
  subagentToolById: /* @__PURE__ */ new Map(),
41060
+ subagentOutputById: /* @__PURE__ */ new Map(),
40980
41061
  subagentStarted: /* @__PURE__ */ new Set(),
40981
41062
  bgTaskById: /* @__PURE__ */ new Map(),
40982
41063
  goalStarted: /* @__PURE__ */ new Set(),
@@ -40985,6 +41066,38 @@ function createXaiCorrelationState() {
40985
41066
  lastMessageId: null
40986
41067
  };
40987
41068
  }
41069
+ function resolveGrokChildChatHistoryPath(cwd, childSessionId) {
41070
+ if (!cwd || !childSessionId) return void 0;
41071
+ return join16(homedir4(), ".grok", "sessions", encodeURIComponent(cwd), childSessionId, "chat_history.jsonl");
41072
+ }
41073
+ function noteSubagentOutputFile(state, subagentId, childSessionId) {
41074
+ const existing = state.subagentOutputById.get(subagentId);
41075
+ if (existing) return existing;
41076
+ const path = resolveGrokChildChatHistoryPath(state.cwd, childSessionId || subagentId);
41077
+ if (path) state.subagentOutputById.set(subagentId, path);
41078
+ return path;
41079
+ }
41080
+ function isSubagentLaunchToolName(name) {
41081
+ if (!name) return false;
41082
+ const n = name.toLowerCase();
41083
+ return n === "agent" || n === "task" || n === "spawn_subagent" || n === "spawn_agent";
41084
+ }
41085
+ function bindSubagentToolId(state, subagentId, toolUseId, description, migrateOut) {
41086
+ if (state.workflowOwnedSubagents.has(subagentId)) return;
41087
+ const existing = state.subagentToolById.get(subagentId);
41088
+ if (existing && existing !== toolUseId) return;
41089
+ const isNew = !existing;
41090
+ if (isNew) state.subagentToolById.set(subagentId, toolUseId);
41091
+ if (isNew && state.subagentStarted.has(subagentId)) {
41092
+ migrateOut.push({
41093
+ type: "task_progress",
41094
+ taskId: subagentId,
41095
+ toolUseId,
41096
+ description: description ?? subagentId,
41097
+ usage: { totalTokens: 0, toolUses: 0, durationMs: 0 }
41098
+ });
41099
+ }
41100
+ }
40988
41101
  function asRecord7(v2) {
40989
41102
  if (!v2 || typeof v2 !== "object" || Array.isArray(v2)) return null;
40990
41103
  return v2;
@@ -41031,7 +41144,22 @@ function parseXaiSessionNotificationEnvelope(raw) {
41031
41144
  function parseXaiExtParams(raw) {
41032
41145
  return asRecord7(raw) ?? {};
41033
41146
  }
41147
+ function parsePlainTextTaskAck(text) {
41148
+ const subagentId = text.match(/subagent_id:\s*(\S+)/i)?.[1] ?? text.match(/task_ids?\s*=\s*\[\s*"([^"]+)"/i)?.[1];
41149
+ const taskId = text.match(/(?:^|\n)\s*task_id:\s*(\S+)/i)?.[1] ?? subagentId;
41150
+ const outputFile = text.match(/output_file:\s*(\S+)/i)?.[1];
41151
+ const description = text.match(/(?:^|\n)\s*description:\s*(.+)$/im)?.[1]?.trim();
41152
+ const subagentType = text.match(/(?:^|\n)\s*(?:type|subagent_type):\s*(\S+)/i)?.[1];
41153
+ return {
41154
+ ...subagentId ? { subagentId } : {},
41155
+ ...taskId ? { taskId } : {},
41156
+ ...outputFile ? { outputFile } : {},
41157
+ ...description ? { description } : {},
41158
+ ...subagentType ? { subagentType } : {}
41159
+ };
41160
+ }
41034
41161
  function noteToolCorrelationFromAgentEvents(events, state) {
41162
+ const migrate = [];
41035
41163
  for (const event of events) {
41036
41164
  if (event.type === "message_usage") {
41037
41165
  state.lastMessageId = event.messageId;
@@ -41040,32 +41168,79 @@ function noteToolCorrelationFromAgentEvents(events, state) {
41040
41168
  if (event.type !== "content_delta") continue;
41041
41169
  const d = event.delta;
41042
41170
  if (d.type === "tool_use") {
41171
+ if (d.toolUseId && d.toolName) {
41172
+ state.pendingToolNamesById.set(d.toolUseId, d.toolName);
41173
+ }
41174
+ const toolName = (d.toolName ?? "").toLowerCase();
41175
+ if ((toolName === "workflow" || toolName === "run_workflow") && d.toolUseId && isValidateOnlyToolInput(d.input)) {
41176
+ state.smokeWorkflowToolIds.add(d.toolUseId);
41177
+ }
41043
41178
  continue;
41044
41179
  }
41045
41180
  if (d.type !== "tool_result" || !d.summary) continue;
41046
41181
  const toolUseId = d.toolUseId;
41182
+ const launchName = state.pendingToolNamesById.get(toolUseId);
41183
+ const isSpawnLaunch = isSubagentLaunchToolName(launchName);
41047
41184
  const parsed = tryParseJsonObject(d.summary);
41048
- if (!parsed) continue;
41049
- const runId = strField(parsed, "run_id", "runId");
41050
- if (runId) {
41051
- state.workflowToolByRunId.set(runId, toolUseId);
41052
- }
41053
- const subagentId = strField(parsed, "subagent_id", "subagentId") ?? strField(parsed, "agent_id", "agentId") ?? strField(parsed, "task_id", "taskId");
41054
- if (subagentId && (strField(parsed, "subagent_id", "subagentId") || strField(parsed, "subagent_type", "subagentType"))) {
41055
- state.subagentToolById.set(subagentId, toolUseId);
41056
- } else if (subagentId && strField(parsed, "agent_id", "agentId") && !runId) {
41057
- state.subagentToolById.set(subagentId, toolUseId);
41058
- }
41059
- const taskId = strField(parsed, "task_id", "taskId");
41060
- if (taskId && !runId) {
41061
- const existing = state.bgTaskById.get(taskId);
41062
- state.bgTaskById.set(taskId, {
41063
- toolUseId: toolUseId ?? existing?.toolUseId,
41064
- description: existing?.description ?? strField(parsed, "description", "name") ?? taskId,
41065
- outputFile: strField(parsed, "output_file", "outputFile") ?? existing?.outputFile
41066
- });
41185
+ if (parsed) {
41186
+ const runId = strField(parsed, "run_id", "runId");
41187
+ if (runId && toolUseId && !state.smokeWorkflowToolIds.has(toolUseId)) {
41188
+ state.workflowToolByRunId.set(runId, toolUseId);
41189
+ }
41190
+ const explicitSubagentId = strField(parsed, "subagent_id", "subagentId");
41191
+ const agentId = strField(parsed, "agent_id", "agentId");
41192
+ const hasSubagentShape = !!(explicitSubagentId || strField(parsed, "subagent_type", "subagentType") || agentId && !runId);
41193
+ const subagentId = explicitSubagentId ?? agentId ?? strField(parsed, "task_id", "taskId");
41194
+ if (subagentId && (explicitSubagentId || strField(parsed, "subagent_type", "subagentType"))) {
41195
+ if (isSpawnLaunch || !launchName) {
41196
+ bindSubagentToolId(state, subagentId, toolUseId, strField(parsed, "description", "name"), migrate);
41197
+ }
41198
+ } else if (subagentId && agentId && !runId) {
41199
+ if (isSpawnLaunch || !launchName) {
41200
+ bindSubagentToolId(state, subagentId, toolUseId, strField(parsed, "description", "name"), migrate);
41201
+ }
41202
+ }
41203
+ const taskId = strField(parsed, "task_id", "taskId");
41204
+ if (taskId && !runId && !hasSubagentShape) {
41205
+ const existing = state.bgTaskById.get(taskId);
41206
+ if (!existing?.toolUseId || existing.toolUseId === toolUseId) {
41207
+ state.bgTaskById.set(taskId, {
41208
+ toolUseId: toolUseId ?? existing?.toolUseId,
41209
+ description: existing?.description ?? strField(parsed, "description", "name") ?? taskId,
41210
+ outputFile: strField(parsed, "output_file", "outputFile") ?? existing?.outputFile
41211
+ });
41212
+ }
41213
+ }
41214
+ continue;
41215
+ }
41216
+ const plain = parsePlainTextTaskAck(d.summary);
41217
+ const allowPlain = isSpawnLaunch || /started in background/i.test(d.summary);
41218
+ if (allowPlain && plain.subagentId) {
41219
+ bindSubagentToolId(state, plain.subagentId, toolUseId, plain.description, migrate);
41220
+ }
41221
+ const explicitTaskId = d.summary.match(/(?:^|\n)\s*task_id:\s*(\S+)/i)?.[1];
41222
+ const bgTaskId = plain.outputFile ? explicitTaskId ?? plain.taskId : explicitTaskId && explicitTaskId !== plain.subagentId ? explicitTaskId : explicitTaskId && !plain.subagentId ? explicitTaskId : void 0;
41223
+ if (allowPlain && bgTaskId) {
41224
+ const existing = state.bgTaskById.get(bgTaskId);
41225
+ if (!existing?.toolUseId || existing.toolUseId === toolUseId) {
41226
+ state.bgTaskById.set(bgTaskId, {
41227
+ toolUseId: toolUseId ?? existing?.toolUseId,
41228
+ description: plain.description ?? existing?.description ?? bgTaskId,
41229
+ outputFile: plain.outputFile ?? existing?.outputFile
41230
+ });
41231
+ }
41067
41232
  }
41068
41233
  }
41234
+ return migrate;
41235
+ }
41236
+ function isValidateOnlyToolInput(input) {
41237
+ if (!input) return false;
41238
+ try {
41239
+ const o = tryParseJsonObject(input);
41240
+ if (o) return o.validate_only === true || o.validateOnly === true;
41241
+ } catch {
41242
+ }
41243
+ return /"validate_only"\s*:\s*true/.test(input) || /"validateOnly"\s*:\s*true/.test(input);
41069
41244
  }
41070
41245
  function tryParseJsonObject(text) {
41071
41246
  const trimmed = text.trim();
@@ -41164,6 +41339,12 @@ function mapXaiSessionUpdate(update, state, ctx = {}) {
41164
41339
  return mapAutoRecoveryStarted(update);
41165
41340
  case "auto_recovery_exhausted":
41166
41341
  return mapAutoRecoveryExhausted(update);
41342
+ case "last_turn_summary":
41343
+ return mapLastTurnSummary(update, ctx);
41344
+ case "session_recap":
41345
+ return mapSessionRecap(update);
41346
+ case "session_recap_unavailable":
41347
+ return [];
41167
41348
  case "unknown":
41168
41349
  return [];
41169
41350
  default:
@@ -41363,18 +41544,23 @@ function mapSubagentSpawned(u, state) {
41363
41544
  state.subagentToolById.delete(id);
41364
41545
  }
41365
41546
  const toolUseId = workflowRunId ? void 0 : state.subagentToolById.get(id);
41547
+ const childSessionId = strField(u, "child_session_id", "childSessionId") ?? id;
41548
+ const outputFile = workflowRunId ? void 0 : noteSubagentOutputFile(state, id, childSessionId);
41366
41549
  return [{
41367
41550
  type: "task_started",
41368
41551
  taskId: id,
41369
41552
  ...toolUseId ? { toolUseId } : {},
41370
41553
  description,
41371
- ...subagentType ? { taskType: subagentType } : {}
41554
+ ...subagentType ? { taskType: subagentType } : {},
41555
+ ...outputFile ? { outputFile } : {}
41372
41556
  }];
41373
41557
  }
41374
41558
  function mapSubagentProgress(u, state) {
41375
41559
  const id = strField(u, "subagent_id", "subagentId");
41376
41560
  if (!id) return [];
41377
41561
  if (state.workflowOwnedSubagents.has(id)) return [];
41562
+ const childSessionId = strField(u, "child_session_id", "childSessionId") ?? id;
41563
+ const outputFile = noteSubagentOutputFile(state, id, childSessionId);
41378
41564
  const events = [];
41379
41565
  if (!state.subagentStarted.has(id)) {
41380
41566
  state.subagentStarted.add(id);
@@ -41382,22 +41568,26 @@ function mapSubagentProgress(u, state) {
41382
41568
  type: "task_started",
41383
41569
  taskId: id,
41384
41570
  ...state.subagentToolById.get(id) ? { toolUseId: state.subagentToolById.get(id) } : {},
41385
- description: id
41571
+ description: id,
41572
+ ...outputFile ? { outputFile } : {}
41386
41573
  });
41387
41574
  }
41388
41575
  const durationMs = numField(u, "duration_ms", "durationMs") ?? 0;
41389
41576
  const toolCalls = numField(u, "tool_call_count", "toolCallCount") ?? 0;
41390
41577
  const tokens = numField(u, "tokens_used", "tokensUsed") ?? 0;
41391
- const toolsUsed = arrField(u, "tools_used", "toolsUsed");
41392
- const activityText = toolsUsed?.filter((t) => typeof t === "string").slice(-5).join(", ");
41578
+ const toolsUsed = (arrField(u, "tools_used", "toolsUsed") ?? []).filter((t) => typeof t === "string" && t.length > 0);
41579
+ const activityText = toolsUsed.length ? toolsUsed.join(", ") : void 0;
41393
41580
  const toolUseId = state.subagentToolById.get(id);
41394
41581
  events.push({
41395
41582
  type: "task_progress",
41396
41583
  taskId: id,
41397
41584
  ...toolUseId ? { toolUseId } : {},
41585
+ // Keep a stable non-tool description so reducer does not invent history from
41586
+ // description transitions when no transcript path is available.
41398
41587
  description: id,
41399
41588
  usage: { totalTokens: tokens, toolUses: toolCalls, durationMs },
41400
- ...activityText ? { activityText } : {}
41589
+ ...activityText ? { activityText } : {},
41590
+ ...outputFile ? { outputFile } : {}
41401
41591
  });
41402
41592
  return events;
41403
41593
  }
@@ -41413,6 +41603,8 @@ function mapSubagentFinished(u, state) {
41413
41603
  const durationMs = numField(u, "duration_ms", "durationMs") ?? 0;
41414
41604
  const toolCalls = numField(u, "tool_calls", "toolCalls") ?? 0;
41415
41605
  const tokens = numField(u, "tokens_used", "tokensUsed") ?? 0;
41606
+ const childSessionId = strField(u, "child_session_id", "childSessionId") ?? id;
41607
+ const outputFile = noteSubagentOutputFile(state, id, childSessionId) ?? "";
41416
41608
  const events = [];
41417
41609
  if (!state.subagentStarted.has(id)) {
41418
41610
  state.subagentStarted.add(id);
@@ -41420,7 +41612,8 @@ function mapSubagentFinished(u, state) {
41420
41612
  type: "task_started",
41421
41613
  taskId: id,
41422
41614
  ...toolUseId ? { toolUseId } : {},
41423
- description: id
41615
+ description: id,
41616
+ ...outputFile ? { outputFile } : {}
41424
41617
  });
41425
41618
  }
41426
41619
  events.push({
@@ -41428,7 +41621,7 @@ function mapSubagentFinished(u, state) {
41428
41621
  taskId: id,
41429
41622
  ...toolUseId ? { toolUseId } : {},
41430
41623
  taskStatus,
41431
- outputFile: "",
41624
+ outputFile,
41432
41625
  summary: error51 ?? status,
41433
41626
  usage: { totalTokens: tokens, toolUses: toolCalls, durationMs },
41434
41627
  ...output ? { resultText: output } : error51 ? { resultText: error51 } : {}
@@ -41761,6 +41954,27 @@ function mapAutoCompactFailed(u) {
41761
41954
  compactError: error51
41762
41955
  }];
41763
41956
  }
41957
+ function mapLastTurnSummary(u, ctx) {
41958
+ const summary = strField(u, "summary")?.trim();
41959
+ if (!summary) return [];
41960
+ const promptId = strField(u, "prompt_id", "promptId");
41961
+ return [{
41962
+ type: "turn_summary",
41963
+ summary,
41964
+ ...promptId ? { promptId } : {},
41965
+ ...ctx.messageId ? { messageId: ctx.messageId } : {}
41966
+ }];
41967
+ }
41968
+ function mapSessionRecap(u) {
41969
+ const summary = strField(u, "summary")?.trim();
41970
+ if (!summary) return [];
41971
+ const auto = boolField(u, "auto");
41972
+ return [{
41973
+ type: "session_recap",
41974
+ summary,
41975
+ ...auto != null ? { auto } : {}
41976
+ }];
41977
+ }
41764
41978
  function mapModelChanged(u) {
41765
41979
  const modelId = strField(u, "model_id", "modelId");
41766
41980
  if (!modelId) return [];
@@ -42147,7 +42361,9 @@ function createAcpAgentEventMapper(options) {
42147
42361
  const nativeToLocal = /* @__PURE__ */ new Map();
42148
42362
  const localMessageIds = /* @__PURE__ */ new Set([options.messageId]);
42149
42363
  const openTools = /* @__PURE__ */ new Set();
42150
- const xaiCorrelation = createXaiCorrelationState();
42364
+ const xaiCorrelation = createXaiCorrelationState(
42365
+ options.cwd ? { cwd: options.cwd } : void 0
42366
+ );
42151
42367
  let currentMessageId = options.messageId;
42152
42368
  let started = false;
42153
42369
  let terminal = false;
@@ -42223,7 +42439,7 @@ function createAcpAgentEventMapper(options) {
42223
42439
  });
42224
42440
  }
42225
42441
  trackOpenAcpTools(openTools, events);
42226
- noteToolCorrelationFromAgentEvents(events, xaiCorrelation);
42442
+ const migrate = noteToolCorrelationFromAgentEvents(events, xaiCorrelation);
42227
42443
  let textDelta = "";
42228
42444
  for (const event of events) {
42229
42445
  if (event.type === "content_delta" && event.delta.type === "text" && !event.delta.parentToolUseId) {
@@ -42231,6 +42447,7 @@ function createAcpAgentEventMapper(options) {
42231
42447
  }
42232
42448
  options.emit(event);
42233
42449
  }
42450
+ for (const event of migrate) options.emit(event);
42234
42451
  return { textDelta: textDelta || null };
42235
42452
  },
42236
42453
  applyXaiNotification(method, params) {
@@ -42241,8 +42458,9 @@ function createAcpAgentEventMapper(options) {
42241
42458
  { messageId: currentMessageId }
42242
42459
  );
42243
42460
  trackOpenAcpTools(openTools, events);
42244
- noteToolCorrelationFromAgentEvents(events, xaiCorrelation);
42461
+ const migrate = noteToolCorrelationFromAgentEvents(events, xaiCorrelation);
42245
42462
  for (const event of events) options.emit(event);
42463
+ for (const event of migrate) options.emit(event);
42246
42464
  },
42247
42465
  complete(stopReason = "end_turn") {
42248
42466
  if (terminal) return;
@@ -42465,7 +42683,8 @@ function createAcpAgentTurnRunner(opts = {}) {
42465
42683
  const blockId = `acp-${sessionId}`;
42466
42684
  agentEventMapper = input.onAgentEvent ? createAcpAgentEventMapper({
42467
42685
  messageId: input.messageId ?? blockId,
42468
- emit: input.onAgentEvent
42686
+ emit: input.onAgentEvent,
42687
+ cwd
42469
42688
  }) : null;
42470
42689
  agentEventMapper?.start(sessionId);
42471
42690
  if (agentEventMapper) {
@@ -48995,23 +49214,23 @@ var init_parse4 = __esm({
48995
49214
  // ../../packages/opencode/src/server.ts
48996
49215
  import { spawn as spawn3 } from "node:child_process";
48997
49216
  import { existsSync as existsSync20 } from "node:fs";
48998
- import { homedir as homedir3 } from "node:os";
48999
- import { delimiter, join as join16 } from "node:path";
49217
+ import { homedir as homedir5 } from "node:os";
49218
+ import { delimiter, join as join17 } from "node:path";
49000
49219
  function appendOutput(current, chunk) {
49001
49220
  const next = current + chunk.toString();
49002
49221
  return next.length <= maxServerOutput ? next : next.slice(-maxServerOutput);
49003
49222
  }
49004
49223
  function defaultOpenCodeBinaryPath() {
49005
49224
  const filename = process.platform === "win32" ? "opencode.exe" : "opencode";
49006
- const installed = join16(homedir3(), ".opencode", "bin", filename);
49225
+ const installed = join17(homedir5(), ".opencode", "bin", filename);
49007
49226
  return existsSync20(installed) ? installed : filename;
49008
49227
  }
49009
49228
  function openCodePath(pathEnv) {
49010
- const home = homedir3();
49229
+ const home = homedir5();
49011
49230
  const paths = [
49012
- join16(home, ".opencode", "bin"),
49013
- join16(home, ".local", "bin"),
49014
- join16(home, ".bun", "bin"),
49231
+ join17(home, ".opencode", "bin"),
49232
+ join17(home, ".local", "bin"),
49233
+ join17(home, ".bun", "bin"),
49015
49234
  "/opt/homebrew/bin",
49016
49235
  "/usr/local/bin",
49017
49236
  ...(pathEnv ?? "").split(delimiter)
@@ -49830,7 +50049,7 @@ __export(managed_harness_official_exports, {
49830
50049
  });
49831
50050
  import { existsSync as existsSync24, mkdirSync as mkdirSync12, readFileSync as readFileSync14, readdirSync as readdirSync8, statSync as statSync6 } from "node:fs";
49832
50051
  import { arch as osArch2, platform as osPlatform2 } from "node:os";
49833
- import { join as join18, resolve as resolve5 } from "node:path";
50052
+ import { join as join19, resolve as resolve5 } from "node:path";
49834
50053
  import { spawn as spawn4 } from "node:child_process";
49835
50054
  function managedNpmPrefix(nodeHome, harnessId) {
49836
50055
  return resolve5(nodeHome, "managed-npm", harnessId);
@@ -49876,29 +50095,29 @@ function officialPackageSpecs(harnessId) {
49876
50095
  function resolveOfficialInstallBinary(harnessId, prefix) {
49877
50096
  if (harnessId === "codex") {
49878
50097
  const candidates = [
49879
- join18(prefix, "bin", "codex"),
49880
- join18(prefix, "bin", "codex.cmd"),
49881
- join18(prefix, "lib", "node_modules", "@openai", "codex", "bin", "codex.js")
50098
+ join19(prefix, "bin", "codex"),
50099
+ join19(prefix, "bin", "codex.cmd"),
50100
+ join19(prefix, "lib", "node_modules", "@openai", "codex", "bin", "codex.js")
49882
50101
  ];
49883
50102
  for (const c of candidates) {
49884
50103
  if (existsSync24(c) && (c.endsWith(".js") || isExecutableFile(c))) return c;
49885
50104
  }
49886
50105
  return null;
49887
50106
  }
49888
- const nm = join18(prefix, "lib", "node_modules");
49889
- const scoped = join18(nm, "@anthropic-ai");
50107
+ const nm = join19(prefix, "lib", "node_modules");
50108
+ const scoped = join19(nm, "@anthropic-ai");
49890
50109
  try {
49891
50110
  if (existsSync24(scoped)) {
49892
50111
  const names = readdirSync8(scoped).filter((n) => n.startsWith("claude-agent-sdk-"));
49893
50112
  for (const n of names) {
49894
50113
  const ext = process.platform === "win32" ? ".exe" : "";
49895
- const bin = join18(scoped, n, `claude${ext}`);
50114
+ const bin = join19(scoped, n, `claude${ext}`);
49896
50115
  if (existsSync24(bin)) return bin;
49897
50116
  }
49898
50117
  }
49899
50118
  } catch {
49900
50119
  }
49901
- const direct = join18(
50120
+ const direct = join19(
49902
50121
  nm,
49903
50122
  ...claudePlatformPackageName().split("/"),
49904
50123
  process.platform === "win32" ? "claude.exe" : "claude"
@@ -49953,7 +50172,7 @@ async function installManagedFromOfficialNpm(opts) {
49953
50172
  }
49954
50173
  function readInstalledVersion(prefix, harnessId) {
49955
50174
  try {
49956
- const pkgPath = harnessId === "claude" ? join18(prefix, "lib", "node_modules", "@anthropic-ai", "claude-agent-sdk", "package.json") : join18(prefix, "lib", "node_modules", "@openai", "codex", "package.json");
50175
+ const pkgPath = harnessId === "claude" ? join19(prefix, "lib", "node_modules", "@anthropic-ai", "claude-agent-sdk", "package.json") : join19(prefix, "lib", "node_modules", "@openai", "codex", "package.json");
49957
50176
  if (!existsSync24(pkgPath)) return null;
49958
50177
  const raw = JSON.parse(readFileSync14(pkgPath, "utf8"));
49959
50178
  return raw.version?.trim() || null;
@@ -57145,7 +57364,7 @@ var require_dist = __commonJS({
57145
57364
  });
57146
57365
 
57147
57366
  // src/cli.ts
57148
- import { homedir as homedir7 } from "node:os";
57367
+ import { homedir as homedir9 } from "node:os";
57149
57368
  import { resolve as resolve12 } from "node:path";
57150
57369
 
57151
57370
  // src/config.ts
@@ -57187,8 +57406,8 @@ import { fileURLToPath } from "node:url";
57187
57406
  function resolveCliReleaseVersion() {
57188
57407
  const fromEnv = process.env.SUPERONE_CLI_VERSION?.trim();
57189
57408
  if (fromEnv) return fromEnv;
57190
- if ("0.50.4-alpha".trim()) {
57191
- return "0.50.4-alpha".trim();
57409
+ if ("0.50.6-alpha".trim()) {
57410
+ return "0.50.6-alpha".trim();
57192
57411
  }
57193
57412
  const fromDist = readDistManifestVersion();
57194
57413
  if (fromDist) return fromDist;
@@ -58804,7 +59023,7 @@ import {
58804
59023
  writeFileSync as writeFileSync9
58805
59024
  } from "node:fs";
58806
59025
  import { createHash as createHash4, randomBytes as randomBytes3 } from "node:crypto";
58807
- import { dirname as dirname10, join as join17, relative, resolve as resolve4, sep as sep3 } from "node:path";
59026
+ import { dirname as dirname11, join as join18, relative, resolve as resolve4, sep as sep3 } from "node:path";
58808
59027
  import { arch as osArch, platform as osPlatform } from "node:os";
58809
59028
  var MANAGED_PAYLOAD_BASENAME = "payload.bin";
58810
59029
  var MANAGED_META_BASENAME = "artifact.json";
@@ -58923,7 +59142,7 @@ function loadHarnessReleaseManifest(nodeHome) {
58923
59142
  }
58924
59143
  return parseHarnessReleaseManifest(JSON.parse(readFileSync13(fromEnv, "utf8")));
58925
59144
  }
58926
- const local = join17(nodeHome, "release-manifest.json");
59145
+ const local = join18(nodeHome, "release-manifest.json");
58927
59146
  if (existsSync23(local)) {
58928
59147
  return parseHarnessReleaseManifest(JSON.parse(readFileSync13(local, "utf8")));
58929
59148
  }
@@ -59011,8 +59230,8 @@ async function installManagedArtifactFromFile(opts) {
59011
59230
  opts.harnessId,
59012
59231
  pin.artifactVersion
59013
59232
  );
59014
- const finalFile = join17(destDir, MANAGED_PAYLOAD_BASENAME);
59015
- const metaPath = join17(destDir, MANAGED_META_BASENAME);
59233
+ const finalFile = join18(destDir, MANAGED_PAYLOAD_BASENAME);
59234
+ const metaPath = join18(destDir, MANAGED_META_BASENAME);
59016
59235
  assertStrictChild(finalFile, destDir, "payload path");
59017
59236
  assertStrictChild(metaPath, destDir, "meta path");
59018
59237
  const metaBody = JSON.stringify(
@@ -59051,15 +59270,15 @@ async function installManagedArtifactFromFile(opts) {
59051
59270
  );
59052
59271
  }
59053
59272
  } else {
59054
- const harnessRoot2 = dirname10(destDir);
59273
+ const harnessRoot2 = dirname11(destDir);
59055
59274
  mkdirSync11(harnessRoot2, { recursive: true });
59056
59275
  assertPathInside(destDir, harnessRoot2, "version dir");
59057
59276
  const stagingDir = mkdtempSync(
59058
- join17(harnessRoot2, `.staging-${opts.harnessId}-${randomBytes3(8).toString("hex")}-`)
59277
+ join18(harnessRoot2, `.staging-${opts.harnessId}-${randomBytes3(8).toString("hex")}-`)
59059
59278
  );
59060
59279
  assertPathInside(stagingDir, harnessRoot2, "staging dir");
59061
- const stagingFile = join17(stagingDir, MANAGED_PAYLOAD_BASENAME);
59062
- const stagingMeta = join17(stagingDir, MANAGED_META_BASENAME);
59280
+ const stagingFile = join18(stagingDir, MANAGED_PAYLOAD_BASENAME);
59281
+ const stagingMeta = join18(stagingDir, MANAGED_META_BASENAME);
59063
59282
  try {
59064
59283
  copyFileSync(opts.artifactPath, stagingFile);
59065
59284
  const stagedDigest = await sha256File(stagingFile);
@@ -59095,7 +59314,7 @@ async function installManagedArtifactFromFile(opts) {
59095
59314
  if (finalDigest !== art.digestSha256) {
59096
59315
  throw new Error(`final payload digest mismatch for ${opts.harnessId}`);
59097
59316
  }
59098
- const harnessRoot = join17(
59317
+ const harnessRoot = join18(
59099
59318
  releasesRoot(opts.nodeHome),
59100
59319
  opts.manifest.cliVersion,
59101
59320
  "harnesses",
@@ -59103,8 +59322,8 @@ async function installManagedArtifactFromFile(opts) {
59103
59322
  );
59104
59323
  assertPathInside(harnessRoot, releasesRoot(opts.nodeHome), "harness root");
59105
59324
  mkdirSync11(harnessRoot, { recursive: true });
59106
- const currentPath = join17(harnessRoot, MANAGED_CURRENT_BASENAME);
59107
- const currentTmp = join17(
59325
+ const currentPath = join18(harnessRoot, MANAGED_CURRENT_BASENAME);
59326
+ const currentTmp = join18(
59108
59327
  harnessRoot,
59109
59328
  `.${MANAGED_CURRENT_BASENAME}.${process.pid}.${randomBytes3(6).toString("hex")}.tmp`
59110
59329
  );
@@ -59143,8 +59362,8 @@ async function installManagedArtifactFromFile(opts) {
59143
59362
  async function replacePayloadAtomically(opts) {
59144
59363
  mkdirSync11(opts.destDir, { recursive: true });
59145
59364
  const nonce = randomBytes3(8).toString("hex");
59146
- const payloadTmp = join17(opts.destDir, `.${MANAGED_PAYLOAD_BASENAME}.${nonce}.tmp`);
59147
- const metaTmp = join17(opts.destDir, `.${MANAGED_META_BASENAME}.${nonce}.tmp`);
59365
+ const payloadTmp = join18(opts.destDir, `.${MANAGED_PAYLOAD_BASENAME}.${nonce}.tmp`);
59366
+ const metaTmp = join18(opts.destDir, `.${MANAGED_META_BASENAME}.${nonce}.tmp`);
59148
59367
  assertStrictChild(payloadTmp, opts.destDir, "payload temp");
59149
59368
  assertStrictChild(metaTmp, opts.destDir, "meta temp");
59150
59369
  try {
@@ -59452,7 +59671,7 @@ function looksLikeSecretArg(value) {
59452
59671
  // ../../packages/shared/src/git-clone.ts
59453
59672
  import { execFile as execFile2 } from "node:child_process";
59454
59673
  import { existsSync as existsSync26, mkdirSync as mkdirSync13 } from "node:fs";
59455
- import { isAbsolute as isAbsolute3, join as join19, resolve as resolve7 } from "node:path";
59674
+ import { isAbsolute as isAbsolute3, join as join20, resolve as resolve7 } from "node:path";
59456
59675
 
59457
59676
  // ../../packages/shared/src/git-remote.ts
59458
59677
  function repoNameFromGitUrl(url2) {
@@ -59517,7 +59736,7 @@ function resolveCloneDestination(input) {
59517
59736
  if (name.includes("/") || name.includes("\\") || name === "." || name === "..") {
59518
59737
  throw invalid(`invalid folder name: ${name}`);
59519
59738
  }
59520
- return { path: join19(resolve7(parent), name), name };
59739
+ return { path: join20(resolve7(parent), name), name };
59521
59740
  }
59522
59741
  async function cloneRepository(input) {
59523
59742
  const destination = resolveCloneDestination(input);
@@ -59567,7 +59786,7 @@ async function cloneRepository(input) {
59567
59786
  init_resolve_service();
59568
59787
  import { existsSync as existsSync27, mkdirSync as mkdirSync14, readdirSync as readdirSync9, statSync as statSync8 } from "node:fs";
59569
59788
  import { join as pathJoin, resolve as pathResolve } from "node:path";
59570
- import { arch, cpus, freemem, homedir as homedir4, hostname as hostname4, platform, totalmem, uptime } from "node:os";
59789
+ import { arch, cpus, freemem, homedir as homedir6, hostname as hostname4, platform, totalmem, uptime } from "node:os";
59571
59790
 
59572
59791
  // src/rpc/resource-handlers.ts
59573
59792
  init_environment();
@@ -62172,9 +62391,9 @@ function handleProjectGet(payload, ctx) {
62172
62391
  function expandHostPath(path) {
62173
62392
  const trimmed = path.trim();
62174
62393
  if (!trimmed) return trimmed;
62175
- if (trimmed === "~") return homedir4();
62394
+ if (trimmed === "~") return homedir6();
62176
62395
  if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) {
62177
- return pathResolve(pathJoin(homedir4(), trimmed.slice(2)));
62396
+ return pathResolve(pathJoin(homedir6(), trimmed.slice(2)));
62178
62397
  }
62179
62398
  return pathResolve(trimmed);
62180
62399
  }
@@ -62457,10 +62676,12 @@ function handleWorkspaceTailWatchStart(payload, ctx) {
62457
62676
  const p2 = asRecord14(payload);
62458
62677
  try {
62459
62678
  const offset = typeof p2.offset === "number" ? p2.offset : void 0;
62679
+ const absolutePath = typeof p2.absolutePath === "string" ? p2.absolutePath : void 0;
62460
62680
  return {
62461
62681
  result: ctx.workspaceTailWatch.start(String(p2.projectId ?? ""), String(p2.relativePath ?? ""), {
62462
62682
  offset,
62463
- ownerClientId: ctx.client.clientSessionId
62683
+ ownerClientId: ctx.client.clientSessionId,
62684
+ ...absolutePath ? { absolutePath } : {}
62464
62685
  })
62465
62686
  };
62466
62687
  } catch (err) {
@@ -62948,8 +63169,33 @@ function handleSessionList(payload, ctx) {
62948
63169
  const denied = requireScopes6(ctx.client, OPERATION_SCOPES.readSession);
62949
63170
  if (denied) return denied;
62950
63171
  const p2 = asRecord14(payload);
63172
+ const projectId = typeof p2.projectId === "string" ? p2.projectId : void 0;
63173
+ if (typeof p2.limit !== "number" || !Number.isFinite(p2.limit)) {
63174
+ return { error: { code: "invalid_argument", message: "session.list requires finite limit" } };
63175
+ }
63176
+ if (typeof p2.offset !== "number" || !Number.isFinite(p2.offset)) {
63177
+ return { error: { code: "invalid_argument", message: "session.list requires finite offset" } };
63178
+ }
63179
+ const limit = Math.min(Math.max(Math.floor(p2.limit), 0), 500);
63180
+ const offset = Math.max(Math.floor(p2.offset), 0);
63181
+ const rows = ctx.sessions.list(projectId, { limit, offset });
62951
63182
  return {
62952
- result: ctx.sessions.list(typeof p2.projectId === "string" ? p2.projectId : void 0)
63183
+ result: rows.map((s2) => ({
63184
+ sessionId: s2.sessionId,
63185
+ projectId: s2.projectId,
63186
+ harnessId: s2.harnessId,
63187
+ providerId: s2.providerId,
63188
+ title: s2.title,
63189
+ status: s2.status,
63190
+ messageCount: Array.isArray(s2.transcript) ? s2.transcript.length : 0,
63191
+ cwd: s2.cwd,
63192
+ createdAt: s2.createdAt,
63193
+ updatedAt: s2.updatedAt,
63194
+ isPinned: s2.isPinned,
63195
+ isHidden: s2.isHidden,
63196
+ isAutomation: s2.isAutomation === true,
63197
+ automationId: s2.automationId ?? null
63198
+ }))
62953
63199
  };
62954
63200
  }
62955
63201
  function handleSessionAcquireControl(payload, ctx) {
@@ -64197,7 +64443,7 @@ import {
64197
64443
  unlinkSync,
64198
64444
  writeFileSync as writeFileSync10
64199
64445
  } from "node:fs";
64200
- import { dirname as dirname11, join as join20, relative as relative2 } from "node:path";
64446
+ import { dirname as dirname12, join as join21, relative as relative2 } from "node:path";
64201
64447
  import { createHash as createHash6 } from "node:crypto";
64202
64448
  function normalizeRel(path) {
64203
64449
  return path.replace(/\\/g, "/").replace(/\/+$/, "") || ".";
@@ -64253,7 +64499,7 @@ var WorkspaceFsService = class {
64253
64499
  this.projects.touch(projectId);
64254
64500
  const ents = readdirSync10(resolved.absolutePath, { withFileTypes: true });
64255
64501
  return ents.map((ent) => {
64256
- const abs = join20(resolved.absolutePath, ent.name);
64502
+ const abs = join21(resolved.absolutePath, ent.name);
64257
64503
  let size;
64258
64504
  let mtimeMs;
64259
64505
  try {
@@ -64330,7 +64576,7 @@ var WorkspaceFsService = class {
64330
64576
  throw Object.assign(new Error("content hash mismatch"), { code: "conflict" });
64331
64577
  }
64332
64578
  }
64333
- mkdirSync15(dirname11(resolved.absolutePath), { recursive: true });
64579
+ mkdirSync15(dirname12(resolved.absolutePath), { recursive: true });
64334
64580
  const data = typeof content === "string" ? Buffer.from(content, "utf8") : Buffer.from(content);
64335
64581
  if (data.length > MAX_READ_BYTES) {
64336
64582
  throw Object.assign(new Error("write payload too large"), { code: "invalid_argument" });
@@ -64406,7 +64652,7 @@ var WorkspaceFsService = class {
64406
64652
  for (const ent of ents) {
64407
64653
  if (hits.length >= MAX_SEARCH_HITS) return;
64408
64654
  if (ent.name === ".git" || ent.name === "node_modules") continue;
64409
- const abs = join20(dir, ent.name);
64655
+ const abs = join21(dir, ent.name);
64410
64656
  const rel = relative2(root, abs).split("\\").join("/");
64411
64657
  const check2 = resolveProjectPath(root, rel);
64412
64658
  if (!check2.ok) continue;
@@ -64539,7 +64785,7 @@ var WorkspaceFsService = class {
64539
64785
  code: "conflict"
64540
64786
  });
64541
64787
  }
64542
- mkdirSync15(dirname11(to.absolutePath), { recursive: true });
64788
+ mkdirSync15(dirname12(to.absolutePath), { recursive: true });
64543
64789
  renameSync3(from.absolutePath, to.absolutePath);
64544
64790
  this.projects.touch(projectId);
64545
64791
  return { from: fromN, to: toN };
@@ -64565,7 +64811,7 @@ function hashFileBounded(absolutePath, size) {
64565
64811
 
64566
64812
  // src/workspace/git-service.ts
64567
64813
  import { existsSync as existsSync31, mkdirSync as mkdirSync16, realpathSync as realpathSync5, rmSync as rmSync4, writeFileSync as writeFileSync11 } from "node:fs";
64568
- import { join as join22, resolve as resolve10 } from "node:path";
64814
+ import { join as join23, resolve as resolve10 } from "node:path";
64569
64815
  import { tmpdir as tmpdir2 } from "node:os";
64570
64816
  import { randomUUID as randomUUID8 } from "node:crypto";
64571
64817
 
@@ -64760,19 +65006,19 @@ function gitRunSync(folderPath, args, env) {
64760
65006
  }
64761
65007
 
64762
65008
  // ../../packages/runtime/src/git/worktree-plan.ts
64763
- import { basename as basename3, dirname as dirname12, join as join21, resolve as resolve9, sep as sep4 } from "node:path";
64764
- import { homedir as homedir5 } from "node:os";
65009
+ import { basename as basename3, dirname as dirname13, join as join22, resolve as resolve9, sep as sep4 } from "node:path";
65010
+ import { homedir as homedir7 } from "node:os";
64765
65011
  function resolveMainDirFromCommonDir(folderPath, gitCommonDir) {
64766
65012
  const repoRoot = resolve9(folderPath, gitCommonDir.trim());
64767
- return repoRoot.endsWith(`${sep4}.git`) || repoRoot.endsWith("/.git") ? dirname12(repoRoot) : repoRoot;
65013
+ return repoRoot.endsWith(`${sep4}.git`) || repoRoot.endsWith("/.git") ? dirname13(repoRoot) : repoRoot;
64768
65014
  }
64769
65015
  function planNewWorktreePaths(input) {
64770
- const home = input.homeDir ?? homedir5();
65016
+ const home = input.homeDir ?? homedir7();
64771
65017
  const repoName = basename3(input.mainDir);
64772
65018
  const epoch = Math.floor((input.nowMs ?? Date.now()) / 1e3).toString(36);
64773
65019
  const short = input.shortHash.slice(0, 7);
64774
- const wtDir = join21(home, ".worktrees", repoName);
64775
- const wtPath = join21(wtDir, `${epoch}-${short}`);
65020
+ const wtDir = join22(home, ".worktrees", repoName);
65021
+ const wtPath = join22(wtDir, `${epoch}-${short}`);
64776
65022
  return { wtDir, wtPath };
64777
65023
  }
64778
65024
  function worktreeAddArgs(mode, wtPath, baseRef, branchName) {
@@ -64864,7 +65110,7 @@ var WorkspaceGitService = class {
64864
65110
  * --ignored walks the whole tree of ignored paths and dominates remote latency.
64865
65111
  */
64866
65112
  statusForCwd(cwd) {
64867
- if (!existsSync31(join22(cwd, ".git")) && !isGitWorktree(cwd)) {
65113
+ if (!existsSync31(join23(cwd, ".git")) && !isGitWorktree(cwd)) {
64868
65114
  return { isRepo: false, branch: null, dirty: false, ahead: 0, behind: 0, porcelain: "" };
64869
65115
  }
64870
65116
  try {
@@ -65119,7 +65365,7 @@ var WorkspaceGitService = class {
65119
65365
  const mainStatus = git(diff.mainDir, ["status", "--porcelain"]).trim();
65120
65366
  if (mainStatus) return { ok: false, reason: "main-dirty" };
65121
65367
  const patch = git(diff.worktreePath, ["diff", "--binary", diff.base, diff.tree]);
65122
- const patchFile = join22(tmpdir2(), `s1-handoff-${randomUUID8()}.patch`);
65368
+ const patchFile = join23(tmpdir2(), `s1-handoff-${randomUUID8()}.patch`);
65123
65369
  writeFileSync11(patchFile, `${patch}
65124
65370
  `);
65125
65371
  if (git(diff.mainDir, ["status", "--porcelain"]).trim()) {
@@ -65181,7 +65427,7 @@ var WorkspaceGitService = class {
65181
65427
  };
65182
65428
  }
65183
65429
  writeWorkingTree(worktreePath) {
65184
- const tmpIndex = join22(tmpdir2(), `s1-handoff-${randomUUID8()}.index`);
65430
+ const tmpIndex = join23(tmpdir2(), `s1-handoff-${randomUUID8()}.index`);
65185
65431
  const env = { GIT_INDEX_FILE: tmpIndex };
65186
65432
  try {
65187
65433
  git(worktreePath, ["read-tree", "HEAD"], env);
@@ -66389,7 +66635,7 @@ var CollaborationService = class {
66389
66635
 
66390
66636
  // src/provider/secret-crypto.ts
66391
66637
  import { existsSync as existsSync33, mkdirSync as mkdirSync17, readFileSync as readFileSync16, writeFileSync as writeFileSync12, chmodSync as chmodSync2 } from "node:fs";
66392
- import { dirname as dirname13 } from "node:path";
66638
+ import { dirname as dirname14 } from "node:path";
66393
66639
  import { createCipheriv, createDecipheriv, randomBytes as randomBytes5 } from "node:crypto";
66394
66640
  var ENC_PREFIX = "enc:v1:";
66395
66641
  var KEY_BYTES = 32;
@@ -66401,7 +66647,7 @@ function ensureKeyFile(keyPath) {
66401
66647
  const raw = readFileSync16(keyPath);
66402
66648
  if (raw.length === KEY_BYTES) return raw;
66403
66649
  }
66404
- mkdirSync17(dirname13(keyPath), { recursive: true, mode: 448 });
66650
+ mkdirSync17(dirname14(keyPath), { recursive: true, mode: 448 });
66405
66651
  const key = randomBytes5(KEY_BYTES);
66406
66652
  writeFileSync12(keyPath, key, { mode: 384 });
66407
66653
  try {
@@ -66545,7 +66791,7 @@ var WorkspaceWatchService = class {
66545
66791
 
66546
66792
  // src/workspace/tail-watch-service.ts
66547
66793
  init_fs();
66548
- import { existsSync as existsSync34, fstatSync as fstatSync2, openSync as openSync2, closeSync as closeSync2, statSync as statSync12 } from "node:fs";
66794
+ import { existsSync as existsSync34, fstatSync as fstatSync2, openSync as openSync2, closeSync as closeSync2, statSync as statSync12, readSync as readSync2, realpathSync as realpathSync6 } from "node:fs";
66549
66795
  var MAX_POLL_BYTES = 10 * 1024 * 1024;
66550
66796
  var WorkspaceTailWatchService = class {
66551
66797
  constructor(projects, fs) {
@@ -66556,16 +66802,41 @@ var WorkspaceTailWatchService = class {
66556
66802
  start(projectId, relativePath, opts) {
66557
66803
  const project = this.projects.get(projectId);
66558
66804
  if (!project) throw Object.assign(new Error("project not found"), { code: "not_found" });
66559
- const rel = normalizeProjectRelativePath(relativePath || "");
66560
- if (!isToolOutputRelativePath(rel)) {
66561
- throw Object.assign(
66562
- new Error("tail watch is limited to project-relative paths under temp/"),
66563
- { code: "invalid_argument" }
66564
- );
66565
- }
66566
- const resolved = resolveProjectPath(project.path, rel);
66567
- if (!resolved.ok) {
66568
- throw Object.assign(new Error(resolved.reason), { code: "invalid_argument" });
66805
+ const absolutePath = typeof opts?.absolutePath === "string" && opts.absolutePath ? opts.absolutePath : void 0;
66806
+ let rel = "";
66807
+ let resolvedAbs = "";
66808
+ if (absolutePath) {
66809
+ if (!assertAgentTranscriptAbsolutePath(absolutePath)) {
66810
+ throw Object.assign(
66811
+ new Error("absolute tail watch is limited to agent transcript roots (~/.grok/sessions, ~/.claude/projects)"),
66812
+ { code: "invalid_argument" }
66813
+ );
66814
+ }
66815
+ try {
66816
+ resolvedAbs = existsSync34(absolutePath) ? realpathSync6(absolutePath) : absolutePath;
66817
+ } catch {
66818
+ resolvedAbs = absolutePath;
66819
+ }
66820
+ if (!assertAgentTranscriptAbsolutePath(resolvedAbs)) {
66821
+ throw Object.assign(
66822
+ new Error("absolute tail watch resolved outside agent transcript roots"),
66823
+ { code: "invalid_argument" }
66824
+ );
66825
+ }
66826
+ rel = absolutePath;
66827
+ } else {
66828
+ rel = normalizeProjectRelativePath(relativePath || "");
66829
+ if (!isToolOutputRelativePath(rel)) {
66830
+ throw Object.assign(
66831
+ new Error("tail watch is limited to project-relative paths under temp/"),
66832
+ { code: "invalid_argument" }
66833
+ );
66834
+ }
66835
+ const resolved = resolveProjectPath(project.path, rel);
66836
+ if (!resolved.ok) {
66837
+ throw Object.assign(new Error(resolved.reason), { code: "invalid_argument" });
66838
+ }
66839
+ resolvedAbs = resolved.absolutePath;
66569
66840
  }
66570
66841
  let offset = opts?.offset ?? 0;
66571
66842
  if (!Number.isSafeInteger(offset) || offset < 0) {
@@ -66573,9 +66844,9 @@ var WorkspaceTailWatchService = class {
66573
66844
  code: "invalid_argument"
66574
66845
  });
66575
66846
  }
66576
- if (existsSync34(resolved.absolutePath)) {
66847
+ if (existsSync34(resolvedAbs)) {
66577
66848
  try {
66578
- const st = statSync12(resolved.absolutePath);
66849
+ const st = statSync12(resolvedAbs);
66579
66850
  if (!st.isFile()) {
66580
66851
  throw Object.assign(new Error("not a file"), { code: "invalid_argument" });
66581
66852
  }
@@ -66588,12 +66859,19 @@ var WorkspaceTailWatchService = class {
66588
66859
  const watchId = crypto.randomUUID();
66589
66860
  this.entries.set(watchId, {
66590
66861
  projectId,
66591
- relativePath: rel,
66862
+ relativePath: absolutePath ? "" : rel,
66863
+ // Store resolved path so poll opens the verified target, not a swapped symlink.
66864
+ ...absolutePath ? { absolutePath: resolvedAbs } : {},
66592
66865
  offset,
66593
66866
  owner: opts?.ownerClientId ?? ""
66594
66867
  });
66595
66868
  this.projects.touch(projectId);
66596
- return { watchId, offset, relativePath: rel };
66869
+ return {
66870
+ watchId,
66871
+ offset,
66872
+ relativePath: absolutePath ? "" : rel,
66873
+ ...absolutePath ? { absolutePath: resolvedAbs } : {}
66874
+ };
66597
66875
  }
66598
66876
  poll(watchId, ownerClientId) {
66599
66877
  const entry = this.entries.get(watchId);
@@ -66604,11 +66882,20 @@ var WorkspaceTailWatchService = class {
66604
66882
  if (!project) {
66605
66883
  throw Object.assign(new Error("project not found"), { code: "not_found" });
66606
66884
  }
66607
- const resolved = resolveProjectPath(project.path, entry.relativePath);
66608
- if (!resolved.ok) {
66609
- throw Object.assign(new Error(resolved.reason), { code: "invalid_argument" });
66885
+ let absolutePath = entry.absolutePath;
66886
+ if (!absolutePath) {
66887
+ const resolved = resolveProjectPath(project.path, entry.relativePath);
66888
+ if (!resolved.ok) {
66889
+ throw Object.assign(new Error(resolved.reason), { code: "invalid_argument" });
66890
+ }
66891
+ absolutePath = resolved.absolutePath;
66892
+ } else if (!assertAgentTranscriptAbsolutePath(absolutePath)) {
66893
+ throw Object.assign(
66894
+ new Error("absolute tail watch resolved outside agent transcript roots"),
66895
+ { code: "invalid_argument" }
66896
+ );
66610
66897
  }
66611
- if (!existsSync34(resolved.absolutePath)) {
66898
+ if (!existsSync34(absolutePath)) {
66612
66899
  return {
66613
66900
  content: "",
66614
66901
  encoding: "base64",
@@ -66619,7 +66906,7 @@ var WorkspaceTailWatchService = class {
66619
66906
  }
66620
66907
  let size = 0;
66621
66908
  try {
66622
- const fd = openSync2(resolved.absolutePath, "r");
66909
+ const fd = openSync2(absolutePath, "r");
66623
66910
  try {
66624
66911
  size = fstatSync2(fd).size;
66625
66912
  } finally {
@@ -66641,14 +66928,27 @@ var WorkspaceTailWatchService = class {
66641
66928
  return { content: "", encoding: "base64", offset: entry.offset, size };
66642
66929
  }
66643
66930
  const toRead = Math.min(MAX_POLL_BYTES, size - entry.offset);
66644
- const slice = this.fs.readFile(entry.projectId, entry.relativePath, {
66645
- offset: entry.offset,
66646
- limit: toRead
66647
- });
66931
+ let contentB64;
66932
+ if (entry.absolutePath) {
66933
+ const buf = Buffer.alloc(toRead);
66934
+ const fd = openSync2(absolutePath, "r");
66935
+ try {
66936
+ const n = readSync2(fd, buf, 0, toRead, entry.offset);
66937
+ contentB64 = buf.subarray(0, n).toString("base64");
66938
+ } finally {
66939
+ closeSync2(fd);
66940
+ }
66941
+ } else {
66942
+ const slice = this.fs.readFile(entry.projectId, entry.relativePath, {
66943
+ offset: entry.offset,
66944
+ limit: toRead
66945
+ });
66946
+ contentB64 = slice.content;
66947
+ }
66648
66948
  entry.offset = entry.offset + toRead;
66649
66949
  this.projects.touch(entry.projectId);
66650
66950
  return {
66651
- content: slice.content,
66951
+ content: contentB64,
66652
66952
  encoding: "base64",
66653
66953
  offset: entry.offset,
66654
66954
  size
@@ -79579,7 +79879,7 @@ function readRuntimeStatus(nodeHome) {
79579
79879
  // src/systemd/install.ts
79580
79880
  import { spawnSync as spawnSync2 } from "node:child_process";
79581
79881
  import { chmodSync as chmodSync3, existsSync as existsSync36, mkdirSync as mkdirSync18, unlinkSync as unlinkSync2, writeFileSync as writeFileSync14 } from "node:fs";
79582
- import { dirname as dirname14 } from "node:path";
79882
+ import { dirname as dirname15 } from "node:path";
79583
79883
 
79584
79884
  // src/systemd/unit.ts
79585
79885
  function renderSystemdUserUnit(opts) {
@@ -79636,7 +79936,7 @@ function checkLinger(user) {
79636
79936
  return { enabled: null, raw };
79637
79937
  }
79638
79938
  function writeSystemdUserUnit(opts, unitPath = systemdUserUnitPath()) {
79639
- mkdirSync18(dirname14(unitPath), { recursive: true });
79939
+ mkdirSync18(dirname15(unitPath), { recursive: true });
79640
79940
  writeFileSync14(unitPath, renderSystemdUserUnit(opts), { encoding: "utf8", mode: 420 });
79641
79941
  try {
79642
79942
  chmodSync3(unitPath, 420);
@@ -79713,9 +80013,9 @@ function systemdUserStatus() {
79713
80013
 
79714
80014
  // src/session/harness-cli.ts
79715
80015
  init_environment();
79716
- import { accessSync as accessSync2, constants as constants2, existsSync as existsSync37, realpathSync as realpathSync6, statSync as statSync13 } from "node:fs";
80016
+ import { accessSync as accessSync2, constants as constants2, existsSync as existsSync37, realpathSync as realpathSync7, statSync as statSync13 } from "node:fs";
79717
80017
  import { isAbsolute as isAbsolute4, resolve as resolve11 } from "node:path";
79718
- import { homedir as homedir6 } from "node:os";
80018
+ import { homedir as homedir8 } from "node:os";
79719
80019
  var DEFERRED_FLAGS = /* @__PURE__ */ new Set([
79720
80020
  "--env-file",
79721
80021
  "--server-password-stdin",
@@ -80231,7 +80531,7 @@ function resolveExternalCommand2(explicit, pathCandidates) {
80231
80531
  }
80232
80532
  const pathEnv = process.env.PATH || "";
80233
80533
  const dirs = pathEnv.split(":").filter(Boolean);
80234
- const home = process.env.HOME || homedir6();
80534
+ const home = process.env.HOME || homedir8();
80235
80535
  const extra = [
80236
80536
  `${home}/.local/bin`,
80237
80537
  `${home}/.npm-global/bin`,
@@ -80262,7 +80562,7 @@ function isUsableExecutable(path) {
80262
80562
  return null;
80263
80563
  }
80264
80564
  try {
80265
- return realpathSync6(path);
80565
+ return realpathSync7(path);
80266
80566
  } catch {
80267
80567
  return path;
80268
80568
  }
@@ -80630,7 +80930,7 @@ async function main() {
80630
80930
  const result = installSystemdUserService({
80631
80931
  execStart: `${process.execPath} ${execStart}`,
80632
80932
  nodeHome,
80633
- home: process.env.HOME || homedir7(),
80933
+ home: process.env.HOME || homedir9(),
80634
80934
  bindHost: host,
80635
80935
  bindPort: port
80636
80936
  });