@autopilot-agent/cli 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/README.md +30 -153
  2. package/dist/activity-animation.d.ts +6 -0
  3. package/dist/activity-animation.js +15 -18
  4. package/dist/composition-root.d.ts +31 -1
  5. package/dist/composition-root.js +124 -3
  6. package/dist/context-report.d.ts +9 -4
  7. package/dist/context-report.js +16 -5
  8. package/dist/controller.d.ts +34 -4
  9. package/dist/controller.js +494 -90
  10. package/dist/design-tokens.d.ts +4 -0
  11. package/dist/design-tokens.js +4 -0
  12. package/dist/error-diagnostics.d.ts +2 -0
  13. package/dist/error-diagnostics.js +3 -1
  14. package/dist/event-projector.d.ts +16 -2
  15. package/dist/event-projector.js +78 -7
  16. package/dist/index.d.ts +1 -1
  17. package/dist/main.js +142 -7
  18. package/dist/parser.js +511 -4
  19. package/dist/renderer.js +19 -3
  20. package/dist/session-summary.d.ts +7 -0
  21. package/dist/session-summary.js +25 -0
  22. package/dist/session-title.d.ts +5 -0
  23. package/dist/session-title.js +10 -0
  24. package/dist/termination-format.js +1 -0
  25. package/dist/thread-commands.d.ts +37 -0
  26. package/dist/thread-commands.js +233 -0
  27. package/dist/thread-host.d.ts +31 -0
  28. package/dist/thread-host.js +76 -0
  29. package/dist/timeline-lines.js +36 -28
  30. package/dist/tui/app.d.ts +22 -0
  31. package/dist/tui/app.js +119 -44
  32. package/dist/tui/approval.d.ts +5 -1
  33. package/dist/tui/approval.js +20 -7
  34. package/dist/tui/constants.d.ts +1 -1
  35. package/dist/tui/constants.js +1 -1
  36. package/dist/tui/format.d.ts +1 -1
  37. package/dist/tui/format.js +23 -11
  38. package/dist/tui/hooks/use-prompt-input.d.ts +52 -0
  39. package/dist/tui/hooks/use-prompt-input.js +148 -20
  40. package/dist/tui/hooks/use-status-view.d.ts +2 -2
  41. package/dist/tui/hooks/use-status-view.js +38 -11
  42. package/dist/tui/inline-output.d.ts +17 -0
  43. package/dist/tui/inline-output.js +31 -0
  44. package/dist/tui/input/clipboard-image.d.ts +17 -0
  45. package/dist/tui/input/clipboard-image.js +117 -0
  46. package/dist/tui/input-area.d.ts +8 -0
  47. package/dist/tui/input-area.js +18 -3
  48. package/dist/tui/lifecycle.js +2 -5
  49. package/dist/tui/markdown/diff.d.ts +1 -1
  50. package/dist/tui/markdown/diff.js +28 -1
  51. package/dist/tui/performance-diagnostics.js +2 -0
  52. package/dist/tui/prompt-input.d.ts +1 -0
  53. package/dist/tui/prompt-input.js +5 -3
  54. package/dist/tui/render-mode.d.ts +4 -4
  55. package/dist/tui/render-mode.js +5 -11
  56. package/dist/tui/run.js +37 -49
  57. package/dist/tui/session-manager.d.ts +115 -0
  58. package/dist/tui/session-manager.js +383 -0
  59. package/dist/tui/session-workspace.d.ts +9 -0
  60. package/dist/tui/session-workspace.js +383 -0
  61. package/dist/tui/status-line.d.ts +3 -0
  62. package/dist/tui/status-line.js +12 -6
  63. package/dist/tui/store.js +111 -53
  64. package/dist/tui/timeline/live.js +9 -8
  65. package/dist/tui/timeline/presentation-timeline.d.ts +2 -1
  66. package/dist/tui/timeline/presentation-timeline.js +34 -15
  67. package/dist/tui/timeline/progress.js +3 -2
  68. package/dist/tui/timeline/static-timeline.js +17 -8
  69. package/dist/tui/timeline/turn-items.d.ts +12 -0
  70. package/dist/tui/timeline/turn-items.js +28 -0
  71. package/dist/tui/timeline/turn.js +8 -7
  72. package/dist/tui/transcript.d.ts +2 -2
  73. package/dist/tui/transcript.js +21 -3
  74. package/dist/tui/trust-dialog.d.ts +3 -0
  75. package/dist/tui/trust-dialog.js +23 -2
  76. package/dist/tui/types.d.ts +23 -1
  77. package/dist/tui/types.js +4 -1
  78. package/dist/tui/viewport/sources.d.ts +2 -2
  79. package/dist/tui/viewport/sources.js +75 -75
  80. package/dist/tui/viewport/viewport.js +5 -1
  81. package/dist/types.d.ts +165 -2
  82. package/package.json +4 -4
package/dist/parser.js CHANGED
@@ -15,7 +15,7 @@ export const CLI_SLASH_COMMANDS = [
15
15
  { name: "/model", usage: "/model", description: "查看或设置下一个 Turn 的模型" },
16
16
  { name: "/effort", usage: "/effort", description: "查看或设置下一个 Turn 的推理强度" },
17
17
  { name: "/skill", usage: "/skill [name]", description: "打开 Skill picker 或选择 Skill" },
18
- { name: "/permissions", usage: "/permissions [mode]", description: "查看或设置 Session 权限模式" },
18
+ { name: "/permissions", usage: "/permissions [mode | grants | revoke <constraint>]", description: "查看/设置权限模式,或查看与撤销持久授权" },
19
19
  { name: "/approve", usage: "/approve <decision>", description: "提交当前工具审批决定" },
20
20
  { name: "/undo", usage: "/undo [confirm]", description: "预览并确认撤销当前会话最近一轮文件修改" },
21
21
  ];
@@ -41,6 +41,21 @@ export function renderHelp() {
41
41
  " autopilot config show|get|set ... --scope user|project|local",
42
42
  " autopilot mcp list | approve <server> [--yes] | revoke <server>",
43
43
  " autopilot job list | show <id> | output <id> | kill <id>",
44
+ " autopilot thread group of --thread <id> (读取groupId/revision)",
45
+ " autopilot thread group enable --thread <id> --request-id <id>",
46
+ " autopilot thread group disable --group <id> --request-id <id>",
47
+ " autopilot thread create --group <id> --thread <parentId> --request-id <id> [--title <t>] [--role <label>] [--model <provider/modelId>] [--effort <level>]",
48
+ " autopilot thread associate --group <id> --thread <id> --request-id <id>",
49
+ " autopilot thread bind-host --group <id> --thread <id> --expected-revision <n> --execution-host <cli-work-v1|web-work-v1>",
50
+ " autopilot thread list --group <id> [--cursor <c>] [--limit <n>]",
51
+ " autopilot thread read --group <id> --thread <id> [--cursor <c>] [--limit <n>]",
52
+ " autopilot thread send --group <id> --thread <id> --mode <notify|run|steer> --request-id <id> (--message-file <path> | --message-stdin) [--reply-to <id>] [--expected-turn-id <id>] [--handoff-title <t> --handoff-file <path>]",
53
+ " autopilot thread wait --group <id> --thread <id> [--thread <id> ...] [--cursor <threadId>=<cursor> ...] [--task <threadId>=<messageId> ...] [--timeout-ms <n>]",
54
+ " autopilot thread state read --group <id>",
55
+ " autopilot thread state set --group <id> --request-id <id> --expected-revision <n> --key <k> (--value <json> | --value-file <path>)",
56
+ " autopilot thread state remove --group <id> --request-id <id> --expected-revision <n> --key <k>",
57
+ " autopilot thread interrupt --group <id> --thread <id> --expected-turn-id <id> --request-id <id>",
58
+ " autopilot thread watch --group <id> [--cursor <c>] [--limit <n>]",
44
59
  " autopilot undo --session <id> --yes",
45
60
  " autopilot doctor [--connectivity]",
46
61
  " autopilot sandbox status | setup --yes",
@@ -54,7 +69,7 @@ export function renderHelp() {
54
69
  " -h, --help show this help",
55
70
  "",
56
71
  "Permissions: ask requires confirmation; auto_approve only auto-runs safe writes and workspace commands after Trust; full_access still enforces path, schema, and destructive-command guards.",
57
- "Limits: AGENT_MAX_STEPS is optional (unset means no total step cap); AGENT_MAX_TOOL_RETRIES defaults to 5; Turn overrides win and values are capped at 100 and 10.",
72
+ "Limits: settings.json maxTurns, AGENT_MAX_STEPS and AGENT_MAX_DURATION_MS are optional (unset means no step/time cap); maxTurns maps to per-run steps without a fixed platform cap; AGENT_MAX_TOOL_RETRIES defaults to 5 and is capped at 10.",
58
73
  "Exit codes: 0 success/normal exit, 1 runtime error, 2 usage error, 130 SIGINT, 143 SIGTERM.",
59
74
  "Interactive uses Ink on a TTY and Plain fallback otherwise; --output jsonl never emits ANSI or prompts.",
60
75
  ].join("\n");
@@ -141,6 +156,9 @@ export function parseArgv(argv) {
141
156
  if (token.startsWith("-"))
142
157
  return { kind: "error", message: `未知选项 ${token}` };
143
158
  if (!commandName) {
159
+ // 协作命令族有独立选项集;交给专用 parser,避免把 --thread/--group 泄漏给其他命令。
160
+ if (token === "thread")
161
+ return parseThreadArgv(argv.slice(index + 1), host);
144
162
  commandName = token;
145
163
  continue;
146
164
  }
@@ -273,6 +291,484 @@ export function parseArgv(argv) {
273
291
  function createInvocation(command, host) {
274
292
  return { command, host };
275
293
  }
294
+ /** 协作命令支持的带值选项;未列出的选项一律拒绝,避免拼写错误被静默忽略。 */
295
+ const THREAD_VALUE_OPTIONS = new Set([
296
+ "--group", "--thread", "--request-id", "--title", "--role", "--model", "--effort",
297
+ "--cursor", "--limit", "--mode", "--message-file", "--reply-to", "--expected-turn-id",
298
+ "--handoff-title", "--handoff-file", "--task", "--timeout-ms", "--expected-revision", "--key",
299
+ "--value", "--value-file", "--execution-host",
300
+ ]);
301
+ /** 协作命令支持的开关选项。 */
302
+ const THREAD_FLAG_OPTIONS = new Set(["--message-stdin"]);
303
+ /** 可与协作命令混排的宿主选项;值语义与全局 parser 一致。 */
304
+ const THREAD_HOST_OPTIONS = new Set(["--state-root", "--trust-root", "--workspace-root"]);
305
+ /** 构造统一的用法错误。 */
306
+ function threadUsageError(message) {
307
+ return { kind: "error", message };
308
+ }
309
+ /** 拆分协作命令的选项与位置参数;只做词法切分,不解释语义。 */
310
+ function readThreadArgs(tokens) {
311
+ const options = new Map();
312
+ const flags = new Set();
313
+ const positionals = [];
314
+ const host = {};
315
+ for (let index = 0; index < tokens.length; index += 1) {
316
+ const token = tokens[index];
317
+ if (THREAD_FLAG_OPTIONS.has(token)) {
318
+ flags.add(token);
319
+ continue;
320
+ }
321
+ if (THREAD_HOST_OPTIONS.has(token)) {
322
+ const value = tokens[index + 1];
323
+ if (value === undefined)
324
+ return { error: `选项 ${token} 需要一个值` };
325
+ if (token === "--state-root")
326
+ host.stateRoot = value;
327
+ else if (token === "--trust-root")
328
+ host.trustRoot = value;
329
+ else
330
+ host.workspaceRoot = value;
331
+ index += 1;
332
+ continue;
333
+ }
334
+ if (!THREAD_VALUE_OPTIONS.has(token)) {
335
+ if (token.startsWith("-"))
336
+ return { error: `未知选项 ${token}` };
337
+ positionals.push(token);
338
+ continue;
339
+ }
340
+ const value = tokens[index + 1];
341
+ if (value === undefined)
342
+ return { error: `选项 ${token} 需要一个值` };
343
+ const values = options.get(token) ?? [];
344
+ values.push(value);
345
+ options.set(token, values);
346
+ index += 1;
347
+ }
348
+ return { options, flags, positionals, host };
349
+ }
350
+ /** 读取唯一必填选项;缺失、重复或空值统一返回用法错误。 */
351
+ function requiredThreadOption(bag, name) {
352
+ const values = bag.options.get(name);
353
+ if (!values || values.length !== 1 || !values[0])
354
+ return { error: `thread 命令需要且只接受一个 ${name}` };
355
+ return { value: values[0] };
356
+ }
357
+ /** 读取可选单值选项;重复出现视为用法错误。 */
358
+ function optionalThreadOption(bag, name) {
359
+ const values = bag.options.get(name);
360
+ if (!values)
361
+ return {};
362
+ if (values.length !== 1 || !values[0])
363
+ return { error: `选项 ${name} 只能出现一次且不能为空` };
364
+ return { value: values[0] };
365
+ }
366
+ /** 解析有界整数选项;不接受负数或小数。 */
367
+ function threadInteger(value, name, min, max) {
368
+ if (!/^\d+$/u.test(value))
369
+ return { error: `${name} 需要非负整数` };
370
+ const parsed = Number(value);
371
+ if (!Number.isSafeInteger(parsed) || parsed < min || parsed > max)
372
+ return { error: `${name} 必须在 ${min}-${max} 之间` };
373
+ return { value: parsed };
374
+ }
375
+ /** 组装协作命令;位置参数必须为空,避免把多余文本当成正文或身份。 */
376
+ function threadCommand(subcommand, command, bag, host) {
377
+ if (bag.positionals.length > 0)
378
+ return threadUsageError(`thread ${subcommand} 不接受位置参数:${bag.positionals.join(" ")}`);
379
+ return { kind: "command", invocation: createInvocation({ type: "thread", command }, { ...host, ...bag.host }) };
380
+ }
381
+ /** 解析 `autopilot thread ...` 薄命令族;argv 契约见 CLI-Reference 第 12 节。 */
382
+ function parseThreadArgv(tokens, host) {
383
+ const name = tokens[0];
384
+ if (!name || name.startsWith("-"))
385
+ return threadUsageError("thread 支持 group|create|associate|bind-host|list|read|send|wait|state|interrupt|watch");
386
+ if (name === "group")
387
+ return parseThreadGroup(tokens.slice(1), host);
388
+ if (name === "state")
389
+ return parseThreadState(tokens.slice(1), host);
390
+ if (name !== "bind-host" && name !== "create" && name !== "associate" && name !== "list" && name !== "read" && name !== "send" && name !== "wait" && name !== "interrupt" && name !== "watch") {
391
+ return threadUsageError(`未知 thread 子命令 ${name}`);
392
+ }
393
+ const bag = readThreadArgs(tokens.slice(1));
394
+ if ("error" in bag)
395
+ return threadUsageError(bag.error);
396
+ if (name === "create")
397
+ return parseThreadCreate(bag, host);
398
+ if (name === "associate")
399
+ return parseThreadAssociate(bag, host);
400
+ if (name === "bind-host")
401
+ return parseThreadBindHost(bag, host);
402
+ if (name === "list")
403
+ return parseThreadList(bag, host);
404
+ if (name === "read")
405
+ return parseThreadRead(bag, host);
406
+ if (name === "send")
407
+ return parseThreadSend(bag, host);
408
+ if (name === "wait")
409
+ return parseThreadWait(bag, host);
410
+ if (name === "interrupt")
411
+ return parseThreadInterrupt(bag, host);
412
+ return parseThreadWatch(bag, host);
413
+ }
414
+ /** 解析 `thread group enable|disable`;启用与停用都必须带稳定请求编号。 */
415
+ function parseThreadGroup(tokens, host) {
416
+ const action = tokens[0];
417
+ const bag = readThreadArgs(tokens.slice(1));
418
+ if ("error" in bag)
419
+ return threadUsageError(bag.error);
420
+ if (action === "of") {
421
+ const threadId = requiredThreadOption(bag, "--thread");
422
+ if ("error" in threadId)
423
+ return threadUsageError(threadId.error);
424
+ return threadCommand("group of", { type: "group_of", threadId: threadId.value }, bag, host);
425
+ }
426
+ if (action === "enable") {
427
+ const rootThreadId = requiredThreadOption(bag, "--thread");
428
+ if ("error" in rootThreadId)
429
+ return threadUsageError(rootThreadId.error);
430
+ const requestId = requiredThreadOption(bag, "--request-id");
431
+ if ("error" in requestId)
432
+ return threadUsageError(requestId.error);
433
+ return threadCommand("group enable", { type: "group_enable", requestId: requestId.value, rootThreadId: rootThreadId.value }, bag, host);
434
+ }
435
+ if (action === "disable") {
436
+ const groupId = requiredThreadOption(bag, "--group");
437
+ if ("error" in groupId)
438
+ return threadUsageError(groupId.error);
439
+ const requestId = requiredThreadOption(bag, "--request-id");
440
+ if ("error" in requestId)
441
+ return threadUsageError(requestId.error);
442
+ return threadCommand("group disable", { type: "group_disable", requestId: requestId.value, groupId: groupId.value }, bag, host);
443
+ }
444
+ return threadUsageError("thread group 支持 of|enable|disable");
445
+ }
446
+ /** 解析 `thread state read|set|remove`;写入必须给 expected revision 与请求编号。 */
447
+ function parseThreadState(tokens, host) {
448
+ const action = tokens[0];
449
+ const bag = readThreadArgs(tokens.slice(1));
450
+ if ("error" in bag)
451
+ return threadUsageError(bag.error);
452
+ if (action !== "read" && action !== "set" && action !== "remove")
453
+ return threadUsageError("thread state 支持 read|set|remove");
454
+ const groupId = requiredThreadOption(bag, "--group");
455
+ if ("error" in groupId)
456
+ return threadUsageError(groupId.error);
457
+ if (action === "read")
458
+ return threadCommand("state read", { type: "state_read", groupId: groupId.value }, bag, host);
459
+ const requestId = requiredThreadOption(bag, "--request-id");
460
+ if ("error" in requestId)
461
+ return threadUsageError(requestId.error);
462
+ const revision = requiredThreadOption(bag, "--expected-revision");
463
+ if ("error" in revision)
464
+ return threadUsageError(revision.error);
465
+ const expectedRevision = threadInteger(revision.value, "--expected-revision", 0, Number.MAX_SAFE_INTEGER);
466
+ if ("error" in expectedRevision)
467
+ return threadUsageError(expectedRevision.error);
468
+ const key = requiredThreadOption(bag, "--key");
469
+ if ("error" in key)
470
+ return threadUsageError(key.error);
471
+ const value = optionalThreadOption(bag, "--value");
472
+ if ("error" in value)
473
+ return threadUsageError(value.error);
474
+ const valueFile = optionalThreadOption(bag, "--value-file");
475
+ if ("error" in valueFile)
476
+ return threadUsageError(valueFile.error);
477
+ if (action === "remove") {
478
+ if (value.value !== undefined || valueFile.value !== undefined)
479
+ return threadUsageError("thread state remove 不接受 --value/--value-file");
480
+ return threadCommand("state remove", { type: "state_remove", requestId: requestId.value, groupId: groupId.value, expectedRevision: expectedRevision.value, key: key.value }, bag, host);
481
+ }
482
+ let stateValue;
483
+ if (value.value !== undefined && valueFile.value === undefined)
484
+ stateValue = { kind: "inline", json: value.value };
485
+ else if (valueFile.value !== undefined && value.value === undefined)
486
+ stateValue = { kind: "file", path: valueFile.value };
487
+ else
488
+ return threadUsageError("thread state set 需要 --value 或 --value-file 二选一");
489
+ return threadCommand("state set", {
490
+ type: "state_set",
491
+ requestId: requestId.value,
492
+ groupId: groupId.value,
493
+ expectedRevision: expectedRevision.value,
494
+ key: key.value,
495
+ value: stateValue,
496
+ }, bag, host);
497
+ }
498
+ /** 解析 `thread create`;`--thread` 是父会话,模型与推理强度只能在宿主目录内选择。 */
499
+ function parseThreadCreate(bag, host) {
500
+ const groupId = requiredThreadOption(bag, "--group");
501
+ if ("error" in groupId)
502
+ return threadUsageError(groupId.error);
503
+ const parentThreadId = requiredThreadOption(bag, "--thread");
504
+ if ("error" in parentThreadId)
505
+ return threadUsageError(parentThreadId.error);
506
+ const requestId = requiredThreadOption(bag, "--request-id");
507
+ if ("error" in requestId)
508
+ return threadUsageError(requestId.error);
509
+ const title = optionalThreadOption(bag, "--title");
510
+ if ("error" in title)
511
+ return threadUsageError(title.error);
512
+ const roleLabel = optionalThreadOption(bag, "--role");
513
+ if ("error" in roleLabel)
514
+ return threadUsageError(roleLabel.error);
515
+ const model = optionalThreadOption(bag, "--model");
516
+ if ("error" in model)
517
+ return threadUsageError(model.error);
518
+ const effort = optionalThreadOption(bag, "--effort");
519
+ if ("error" in effort)
520
+ return threadUsageError(effort.error);
521
+ let modelRef;
522
+ if (model.value !== undefined) {
523
+ const separator = model.value.indexOf("/");
524
+ if (separator <= 0 || separator === model.value.length - 1)
525
+ return threadUsageError("--model 需要 provider/modelId");
526
+ modelRef = { provider: model.value.slice(0, separator), modelId: model.value.slice(separator + 1) };
527
+ }
528
+ if (effort.value !== undefined && effort.value !== "none" && effort.value !== "low" && effort.value !== "medium" && effort.value !== "high" && effort.value !== "max") {
529
+ return threadUsageError("--effort 支持 none|low|medium|high|max");
530
+ }
531
+ return threadCommand("create", {
532
+ type: "create",
533
+ requestId: requestId.value,
534
+ groupId: groupId.value,
535
+ parentThreadId: parentThreadId.value,
536
+ ...(title.value !== undefined ? { title: title.value } : {}),
537
+ ...(roleLabel.value !== undefined ? { roleLabel: roleLabel.value } : {}),
538
+ ...(modelRef ? { modelRef } : {}),
539
+ ...(effort.value !== undefined ? { reasoningEffort: effort.value } : {}),
540
+ }, bag, host);
541
+ }
542
+ /** 解析 `thread list`;游标与条数由 Core 再校验一次。 */
543
+ function parseThreadList(bag, host) {
544
+ const groupId = requiredThreadOption(bag, "--group");
545
+ if ("error" in groupId)
546
+ return threadUsageError(groupId.error);
547
+ const cursor = optionalThreadOption(bag, "--cursor");
548
+ if ("error" in cursor)
549
+ return threadUsageError(cursor.error);
550
+ const limit = optionalThreadOption(bag, "--limit");
551
+ if ("error" in limit)
552
+ return threadUsageError(limit.error);
553
+ let limitValue;
554
+ if (limit.value !== undefined) {
555
+ const parsedLimit = threadInteger(limit.value, "--limit", 1, 100);
556
+ if ("error" in parsedLimit)
557
+ return threadUsageError(parsedLimit.error);
558
+ limitValue = parsedLimit.value;
559
+ }
560
+ return threadCommand("list", {
561
+ type: "list",
562
+ groupId: groupId.value,
563
+ ...(cursor.value !== undefined ? { cursor: cursor.value } : {}),
564
+ ...(limitValue !== undefined ? { limit: limitValue } : {}),
565
+ }, bag, host);
566
+ }
567
+ /** 解析 `thread read`;读取不启动、不恢复目标会话。 */
568
+ function parseThreadRead(bag, host) {
569
+ const groupId = requiredThreadOption(bag, "--group");
570
+ if ("error" in groupId)
571
+ return threadUsageError(groupId.error);
572
+ const threadId = requiredThreadOption(bag, "--thread");
573
+ if ("error" in threadId)
574
+ return threadUsageError(threadId.error);
575
+ const cursor = optionalThreadOption(bag, "--cursor");
576
+ if ("error" in cursor)
577
+ return threadUsageError(cursor.error);
578
+ const limit = optionalThreadOption(bag, "--limit");
579
+ if ("error" in limit)
580
+ return threadUsageError(limit.error);
581
+ let limitValue;
582
+ if (limit.value !== undefined) {
583
+ const parsedLimit = threadInteger(limit.value, "--limit", 1, 100);
584
+ if ("error" in parsedLimit)
585
+ return threadUsageError(parsedLimit.error);
586
+ limitValue = parsedLimit.value;
587
+ }
588
+ return threadCommand("read", {
589
+ type: "read",
590
+ groupId: groupId.value,
591
+ threadId: threadId.value,
592
+ ...(cursor.value !== undefined ? { cursor: cursor.value } : {}),
593
+ ...(limitValue !== undefined ? { limit: limitValue } : {}),
594
+ }, bag, host);
595
+ }
596
+ /** 解析 `thread send`;正文只允许文件或显式 stdin,避免 shell 二次解释。 */
597
+ function parseThreadSend(bag, host) {
598
+ const groupId = requiredThreadOption(bag, "--group");
599
+ if ("error" in groupId)
600
+ return threadUsageError(groupId.error);
601
+ const threadId = requiredThreadOption(bag, "--thread");
602
+ if ("error" in threadId)
603
+ return threadUsageError(threadId.error);
604
+ const requestId = requiredThreadOption(bag, "--request-id");
605
+ if ("error" in requestId)
606
+ return threadUsageError(requestId.error);
607
+ const mode = requiredThreadOption(bag, "--mode");
608
+ if ("error" in mode)
609
+ return threadUsageError(mode.error);
610
+ if (mode.value !== "notify" && mode.value !== "run" && mode.value !== "steer")
611
+ return threadUsageError("--mode 支持 notify|run|steer");
612
+ const messageFile = optionalThreadOption(bag, "--message-file");
613
+ if ("error" in messageFile)
614
+ return threadUsageError(messageFile.error);
615
+ const fromStdin = bag.flags.has("--message-stdin");
616
+ if (Boolean(messageFile.value) === fromStdin)
617
+ return threadUsageError("正文需要 --message-file 或 --message-stdin 二选一");
618
+ const replyTo = optionalThreadOption(bag, "--reply-to");
619
+ if ("error" in replyTo)
620
+ return threadUsageError(replyTo.error);
621
+ const expectedTurnId = optionalThreadOption(bag, "--expected-turn-id");
622
+ if ("error" in expectedTurnId)
623
+ return threadUsageError(expectedTurnId.error);
624
+ if (mode.value === "steer" && expectedTurnId.value === undefined)
625
+ return threadUsageError("--mode steer 必须提供 --expected-turn-id");
626
+ if (mode.value !== "steer" && expectedTurnId.value !== undefined)
627
+ return threadUsageError("只有 --mode steer 接受 --expected-turn-id");
628
+ const handoffTitle = optionalThreadOption(bag, "--handoff-title");
629
+ if ("error" in handoffTitle)
630
+ return threadUsageError(handoffTitle.error);
631
+ const handoffFile = optionalThreadOption(bag, "--handoff-file");
632
+ if ("error" in handoffFile)
633
+ return threadUsageError(handoffFile.error);
634
+ if (Boolean(handoffTitle.value) !== Boolean(handoffFile.value))
635
+ return threadUsageError("交接需要同时提供 --handoff-title 与 --handoff-file");
636
+ if (handoffTitle.value !== undefined && mode.value !== "run")
637
+ return threadUsageError("交接只允许 --mode run");
638
+ return threadCommand("send", {
639
+ type: "send",
640
+ requestId: requestId.value,
641
+ groupId: groupId.value,
642
+ threadId: threadId.value,
643
+ mode: mode.value,
644
+ contentSource: messageFile.value ? { kind: "file", path: messageFile.value } : { kind: "stdin" },
645
+ ...(replyTo.value !== undefined ? { replyTo: replyTo.value } : {}),
646
+ ...(expectedTurnId.value !== undefined ? { expectedTurnId: expectedTurnId.value } : {}),
647
+ ...(handoffTitle.value && handoffFile.value ? { handoff: { title: handoffTitle.value, markdownFile: handoffFile.value } } : {}),
648
+ }, bag, host);
649
+ }
650
+ /** 解析 `thread wait`;每个 `--thread` 一个目标,游标用 `--cursor <threadId>=<cursor>` 指定。 */
651
+ function parseThreadWait(bag, host) {
652
+ const groupId = requiredThreadOption(bag, "--group");
653
+ if ("error" in groupId)
654
+ return threadUsageError(groupId.error);
655
+ const threadValues = bag.options.get("--thread") ?? [];
656
+ if (threadValues.length === 0 || threadValues.length > 8)
657
+ return threadUsageError("thread wait 需要 1-8 个 --thread");
658
+ if (new Set(threadValues).size !== threadValues.length)
659
+ return threadUsageError("thread wait 的 --thread 不能重复");
660
+ const cursors = new Map();
661
+ for (const entry of bag.options.get("--cursor") ?? []) {
662
+ const separator = entry.indexOf("=");
663
+ if (separator <= 0 || separator === entry.length - 1)
664
+ return threadUsageError("--cursor 需要 <threadId>=<cursor>");
665
+ const target = entry.slice(0, separator);
666
+ if (!threadValues.includes(target))
667
+ return threadUsageError(`--cursor 的目标 ${target} 不在 --thread 列表中`);
668
+ if (cursors.has(target))
669
+ return threadUsageError(`--cursor 重复指定了 ${target}`);
670
+ cursors.set(target, entry.slice(separator + 1));
671
+ }
672
+ const tasks = new Map();
673
+ for (const entry of bag.options.get("--task") ?? []) {
674
+ const separator = entry.indexOf("=");
675
+ if (separator <= 0 || separator === entry.length - 1)
676
+ return threadUsageError("--task 需要 <threadId>=<messageId>");
677
+ const target = entry.slice(0, separator);
678
+ if (!threadValues.includes(target) || tasks.has(target))
679
+ return threadUsageError("--task 目标必须属于 --thread 且不能重复");
680
+ tasks.set(target, entry.slice(separator + 1));
681
+ }
682
+ const timeout = optionalThreadOption(bag, "--timeout-ms");
683
+ if ("error" in timeout)
684
+ return threadUsageError(timeout.error);
685
+ const timeoutMs = timeout.value === undefined ? { value: 30_000 } : threadInteger(timeout.value, "--timeout-ms", 0, 30_000);
686
+ if ("error" in timeoutMs)
687
+ return threadUsageError(timeoutMs.error);
688
+ return threadCommand("wait", {
689
+ type: "wait",
690
+ groupId: groupId.value,
691
+ targets: threadValues.map(function toTarget(threadId) {
692
+ const cursor = cursors.get(threadId);
693
+ return { threadId, ...(tasks.has(threadId) ? { taskId: tasks.get(threadId) } : {}), ...(cursor !== undefined ? { cursor } : {}) };
694
+ }),
695
+ timeoutMs: timeoutMs.value,
696
+ }, bag, host);
697
+ }
698
+ /** 显式关联已有会话;只有受信人类 owner 可在 Core 中真正授权。 */
699
+ function parseThreadAssociate(bag, host) {
700
+ const groupId = requiredThreadOption(bag, "--group");
701
+ if ("error" in groupId)
702
+ return threadUsageError(groupId.error);
703
+ const threadId = requiredThreadOption(bag, "--thread");
704
+ if ("error" in threadId)
705
+ return threadUsageError(threadId.error);
706
+ const requestId = requiredThreadOption(bag, "--request-id");
707
+ if ("error" in requestId)
708
+ return threadUsageError(requestId.error);
709
+ return threadCommand("associate", { type: "associate", groupId: groupId.value, threadId: threadId.value, requestId: requestId.value }, bag, host);
710
+ }
711
+ /** 人类明确选择旧目标的执行档位,组版本用于拒绝迟到确认。 */
712
+ function parseThreadBindHost(bag, host) {
713
+ const groupId = requiredThreadOption(bag, "--group");
714
+ if ("error" in groupId)
715
+ return threadUsageError(groupId.error);
716
+ const threadId = requiredThreadOption(bag, "--thread");
717
+ if ("error" in threadId)
718
+ return threadUsageError(threadId.error);
719
+ const revision = requiredThreadOption(bag, "--expected-revision");
720
+ if ("error" in revision)
721
+ return threadUsageError(revision.error);
722
+ const executionHost = requiredThreadOption(bag, "--execution-host");
723
+ if ("error" in executionHost)
724
+ return threadUsageError(executionHost.error);
725
+ if (!/^\d+$/u.test(revision.value) || !Number.isSafeInteger(Number(revision.value)))
726
+ return threadUsageError("--expected-revision 需要非负整数");
727
+ if (executionHost.value !== "cli-work-v1" && executionHost.value !== "web-work-v1")
728
+ return threadUsageError("--execution-host 需要 cli-work-v1 或 web-work-v1");
729
+ return threadCommand("bind-host", { type: "bind_host", groupId: groupId.value, threadId: threadId.value, expectedRevision: Number(revision.value), executionHost: executionHost.value }, bag, host);
730
+ }
731
+ /** 解析 `thread interrupt`;必须带发送时观察到的 Turn,避免中断错任务。 */
732
+ function parseThreadInterrupt(bag, host) {
733
+ const groupId = requiredThreadOption(bag, "--group");
734
+ if ("error" in groupId)
735
+ return threadUsageError(groupId.error);
736
+ const threadId = requiredThreadOption(bag, "--thread");
737
+ if ("error" in threadId)
738
+ return threadUsageError(threadId.error);
739
+ const requestId = requiredThreadOption(bag, "--request-id");
740
+ if ("error" in requestId)
741
+ return threadUsageError(requestId.error);
742
+ const expectedTurnId = requiredThreadOption(bag, "--expected-turn-id");
743
+ if ("error" in expectedTurnId)
744
+ return threadUsageError(expectedTurnId.error);
745
+ return threadCommand("interrupt", { type: "interrupt", requestId: requestId.value, groupId: groupId.value, threadId: threadId.value, expectedTurnId: expectedTurnId.value }, bag, host);
746
+ }
747
+ /** 解析 `thread watch`;只观察组事件,Ctrl+C 只结束观察。 */
748
+ function parseThreadWatch(bag, host) {
749
+ const groupId = requiredThreadOption(bag, "--group");
750
+ if ("error" in groupId)
751
+ return threadUsageError(groupId.error);
752
+ const cursor = optionalThreadOption(bag, "--cursor");
753
+ if ("error" in cursor)
754
+ return threadUsageError(cursor.error);
755
+ const limit = optionalThreadOption(bag, "--limit");
756
+ if ("error" in limit)
757
+ return threadUsageError(limit.error);
758
+ let limitValue;
759
+ if (limit.value !== undefined) {
760
+ const parsedLimit = threadInteger(limit.value, "--limit", 1, 100);
761
+ if ("error" in parsedLimit)
762
+ return threadUsageError(parsedLimit.error);
763
+ limitValue = parsedLimit.value;
764
+ }
765
+ return threadCommand("watch", {
766
+ type: "watch",
767
+ groupId: groupId.value,
768
+ ...(cursor.value !== undefined ? { cursor: cursor.value } : {}),
769
+ ...(limitValue !== undefined ? { limit: limitValue } : {}),
770
+ }, bag, host);
771
+ }
276
772
  /** 解析单行 slash command;普通文本不在此函数内改写。 */
277
773
  export function parseSlashAction(input) {
278
774
  const trimmed = input.trim();
@@ -293,6 +789,8 @@ export function parseSlashAction(input) {
293
789
  return parseQueuedPrompt(parts);
294
790
  if (name === "compact")
295
791
  return parts.length === 1 ? { kind: "action", action: { type: "compact" } } : invalidSlashArguments(name);
792
+ if (name === "resume")
793
+ return parts.length === 1 ? { kind: "action", action: { type: "resume" } } : { kind: "error", message: "/resume 不接受额外参数" };
296
794
  if (name === "context") {
297
795
  if (parts.length === 1)
298
796
  return { kind: "action", action: { type: "show_context", all: false } };
@@ -359,12 +857,21 @@ function isApprovalDecision(value) {
359
857
  function invalidSlashArguments(name) {
360
858
  return { kind: "error", message: `/${name} 不接受额外参数` };
361
859
  }
362
- /** 解析权限模式查询与 Session 默认权限更新。 */
860
+ /** 解析权限模式查询、Session 默认权限更新与持久授权查看/撤销(Talk-Plan1013 Stage 4)。 */
363
861
  function parsePermissionsAction(parts) {
364
862
  if (parts.length === 1)
365
863
  return { kind: "action", action: { type: "open_permissions" } };
864
+ if (parts.length === 2 && parts[1] === "grants")
865
+ return { kind: "action", action: { type: "list_permission_grants" } };
866
+ if (parts[1] === "revoke") {
867
+ if (parts.length === 2)
868
+ return { kind: "error", message: "/permissions revoke 需要从 /permissions grants 列表中复制的完整 constraint" };
869
+ // constraint 由 ext-file:/path:/program: 前缀与路径组成,路径可含空格,按原样拼接且不再拆分。
870
+ const constraint = parts.slice(2).join(" ").trim();
871
+ return { kind: "action", action: { type: "revoke_permission_grant", constraint } };
872
+ }
366
873
  if (parts.length !== 2 || !isPermissionMode(parts[1])) {
367
- return { kind: "error", message: "/permissions 需要 ask|auto_approve|full_access" };
874
+ return { kind: "error", message: "/permissions 需要 ask|auto_approve|full_access 或 grants | revoke <constraint>" };
368
875
  }
369
876
  return { kind: "action", action: { type: "set_permission_mode", mode: parts[1] } };
370
877
  }
package/dist/renderer.js CHANGED
@@ -5,6 +5,10 @@
5
5
  * Store、checkpoint 或 Web SSE DTO;因此 text 与 JSONL 的语义来源一致。
6
6
  */
7
7
  import { formatAgentTermination } from "./termination-format.js";
8
+ /** 判断审批约束是否为无沙箱直接执行;与 Web 审批卡同一字符串判定,休眠底座不签发,历史记录仍可能携带。 */
9
+ function isNoSandboxApproval(constraint) {
10
+ return constraint === "no-sandbox-exec:v1";
11
+ }
8
12
  /** 将安全事件渲染为不带 ANSI 的 Plain 文本行。 */
9
13
  function renderTextEvent(event) {
10
14
  switch (event.type) {
@@ -15,8 +19,18 @@ function renderTextEvent(event) {
15
19
  case "answer_reset": return "answer reset";
16
20
  case "tool_started": return `tool ${event.toolName}: ${event.summary}`;
17
21
  case "tool_progress": return `tool ${event.toolName}: ${event.tail}`;
18
- case "tool_result": return `tool ${event.toolName} [${event.status}]: ${event.summary}${event.errorCode ? ` (${event.errorCode})` : ""}${event.diff ? `\n${event.diff}` : ""}`;
19
- case "approval_required": return `approval ${event.approvalId}: ${event.toolName} ${event.reason}`;
22
+ case "tool_result": {
23
+ const isolation = event.display?.executionMode === "unisolated" ? " · 未隔离:宿主直接执行" : "";
24
+ const diagnostics = event.display?.diagnostics?.length ? ` · 诊断:${event.display.diagnostics.join(";")}` : "";
25
+ return `tool ${event.toolName} [${event.status}]: ${event.summary}${event.errorCode ? ` (${event.errorCode})` : ""}${diagnostics}${isolation}${event.diff ? `\n${event.diff}` : ""}`;
26
+ }
27
+ case "approval_required": {
28
+ const cwd = event.display?.cwd ? ` · 工作目录:${event.display.cwd}` : "";
29
+ const noSandbox = isNoSandboxApproval(event.constraint) ? " · 无沙箱直接执行,仅本次有效" : "";
30
+ // Talk-Plan1022 S3:宿主执行审批卡按"将采用"措辞说明无隔离事实,待审批不显示成已执行。
31
+ const hostExecution = event.display?.executionMode === "unisolated" ? " · 将在当前用户权限下运行(未启用沙箱隔离)" : "";
32
+ return `approval ${event.approvalId}: ${event.toolName} ${event.reason}${cwd}${noSandbox}${hostExecution}`;
33
+ }
20
34
  case "input_queued": return `input queued: ${event.inputId} (${event.delivery})`;
21
35
  case "todo_updated": {
22
36
  const total = event.todos.length;
@@ -33,8 +47,10 @@ function renderTextEvent(event) {
33
47
  case "context_compact_circuit_open": return "context compact circuit open";
34
48
  // 用量变化只属于动态状态栏;text 输出空行跳过,JSONL 仍输出结构化安全 DTO。
35
49
  case "context_usage": return "";
50
+ // 关联等待只刷新交互状态;JSONL继续输出结构化事实。
51
+ case "thread_wait": return "";
36
52
  case "active_skills": return `active skills: ${event.skills.map(function skillId(skill) { return skill.skillId; }).join(", ") || "none"}`;
37
- case "status": return `status: ${event.status}${event.code ? ` (${event.code})` : ""}${event.reason ? ` · ${event.reason}` : ""}${event.termination ? ` · ${formatAgentTermination(event.termination)}` : ""}`;
53
+ case "status": return `status: ${event.status}${event.code ? ` (${event.code})` : ""}${event.reason ? ` · ${event.reason}` : ""}${event.providerHttpStatus !== undefined ? ` · HTTP 状态:${event.providerHttpStatus}` : ""}${event.providerFailureDetail ? ` · 上游标识:${event.providerFailureDetail}` : ""}${event.feedbackId ? ` · 反馈 ID:${event.feedbackId}` : ""}${event.termination ? ` · ${formatAgentTermination(event.termination)}` : ""}`;
38
54
  }
39
55
  }
40
56
  /** 创建 Plain Renderer;jsonl 模式只输出稳定安全事件 JSON。 */
@@ -0,0 +1,7 @@
1
+ /** CLI当前交互身份摘要:待审批/输入不把已释放的执行activeTurnId当作当前Turn身份。 */
2
+ import { type RuntimePorts, type SessionDirectoryEntry, type TurnExecutionView } from "@autopilot-agent/core";
3
+ /** 只读目录与最新Turn,校验归属/状态并在await后复核元数据;安全投影按游标追尾,取消后停止后续读取,不恢复执行。 */
4
+ export declare function readCliSessionSummary(ports: RuntimePorts, sessionId: string, signal?: AbortSignal): Promise<(SessionDirectoryEntry & {
5
+ currentTurnId?: string;
6
+ executionView?: TurnExecutionView | null;
7
+ }) | null>;
@@ -0,0 +1,25 @@
1
+ /** CLI当前交互身份摘要:待审批/输入不把已释放的执行activeTurnId当作当前Turn身份。 */
2
+ import { readTurnExecutionView } from "@autopilot-agent/core";
3
+ /** 只读目录与最新Turn,校验归属/状态并在await后复核元数据;安全投影按游标追尾,取消后停止后续读取,不恢复执行。 */
4
+ export async function readCliSessionSummary(ports, sessionId, signal) {
5
+ if (!ports.sessionStore.getDirectoryEntry)
6
+ throw new Error("CLI_SESSION_DIRECTORY_UNAVAILABLE");
7
+ signal?.throwIfAborted();
8
+ const summary = await ports.sessionStore.getDirectoryEntry(sessionId);
9
+ signal?.throwIfAborted();
10
+ if (!summary)
11
+ return null;
12
+ const executionView = await readTurnExecutionView(ports, { sessionId, signal });
13
+ signal?.throwIfAborted();
14
+ if (executionView)
15
+ return { ...summary, status: executionView.status, currentTurnId: executionView.turnId, executionView };
16
+ if (summary.status !== "waiting_approval" && summary.status !== "waiting_user_input")
17
+ return { ...summary, currentTurnId: summary.activeTurnId };
18
+ const latest = await ports.turnStore.getLatest(sessionId);
19
+ signal?.throwIfAborted();
20
+ const current = await ports.sessionStore.getDirectoryEntry(sessionId);
21
+ if (!current || current.status !== summary.status || current.activeTurnId !== summary.activeTurnId)
22
+ return null;
23
+ const valid = latest?.sessionId === sessionId && latest.status === current.status;
24
+ return { ...current, currentTurnId: valid ? latest.id : undefined };
25
+ }
@@ -0,0 +1,5 @@
1
+ /** CLI会话标题:沿Web短文本范式,不增加模型采样,普通界面不以机器ID作标题。 */
2
+ /** 从已有用户输入/成功回答得到20字短标题,清除终端控制字符和换行。 */
3
+ export declare function createCliSessionTitle(content: string): string;
4
+ /** 历史空标题与旧机器ID标题使用安全占位;手工标题仅做显示净化。 */
5
+ export declare function getCliSessionDisplayTitle(title: string | undefined, sessionId?: string): string;