@oyasmi/pipiclaw 0.8.0 → 0.8.2

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 (106) hide show
  1. package/README.md +115 -510
  2. package/dist/agent/channel-runner.d.ts +11 -6
  3. package/dist/agent/channel-runner.js +44 -24
  4. package/dist/agent/command-extension.js +5 -4
  5. package/dist/agent/commands.d.ts +50 -0
  6. package/dist/agent/commands.js +176 -67
  7. package/dist/agent/job-manager.d.ts +5 -5
  8. package/dist/agent/prompt-builder.d.ts +3 -13
  9. package/dist/agent/prompt-builder.js +44 -204
  10. package/dist/agent/run-queue.d.ts +1 -2
  11. package/dist/agent/run-queue.js +3 -5
  12. package/dist/agent/runner-factory.d.ts +1 -2
  13. package/dist/agent/runner-factory.js +2 -2
  14. package/dist/agent/status-render.d.ts +0 -7
  15. package/dist/agent/status-render.js +8 -3
  16. package/dist/agent/types.d.ts +4 -3
  17. package/dist/agent/workspace-resources.d.ts +1 -1
  18. package/dist/agent/workspace-resources.js +3 -15
  19. package/dist/executor.d.ts +20 -0
  20. package/dist/{sandbox.js → executor.js} +3 -95
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/log.d.ts +1 -3
  24. package/dist/log.js +1 -20
  25. package/dist/main.js +14 -4
  26. package/dist/memory/files.js +0 -0
  27. package/dist/memory/lifecycle.js +6 -5
  28. package/dist/memory/maintenance-jobs.d.ts +0 -1
  29. package/dist/memory/maintenance-jobs.js +2 -2
  30. package/dist/memory/maintenance-state.js +2 -1
  31. package/dist/memory/post-turn-review.d.ts +0 -1
  32. package/dist/memory/post-turn-review.js +4 -4
  33. package/dist/memory/scheduler.d.ts +0 -1
  34. package/dist/memory/scheduler.js +2 -2
  35. package/dist/memory/session.js +2 -2
  36. package/dist/paths.d.ts +2 -0
  37. package/dist/paths.js +11 -0
  38. package/dist/playbooks/event-scheduling.md +43 -0
  39. package/dist/playbooks/memory-and-learning.md +45 -0
  40. package/dist/playbooks/runtime-orientation.md +48 -0
  41. package/dist/playbooks/task-closeout.md +45 -0
  42. package/dist/playbooks/task-delegation.md +44 -0
  43. package/dist/playbooks/task-driving.md +43 -0
  44. package/dist/playbooks/task-planning.md +47 -0
  45. package/dist/playbooks/task-recurring.md +42 -0
  46. package/dist/playbooks/task-repair.md +43 -0
  47. package/dist/runtime/bootstrap.d.ts +7 -11
  48. package/dist/runtime/bootstrap.js +50 -57
  49. package/dist/runtime/delivery.js +4 -3
  50. package/dist/runtime/dingtalk.js +50 -57
  51. package/dist/runtime/durable-dispatch.d.ts +2 -0
  52. package/dist/runtime/durable-dispatch.js +29 -1
  53. package/dist/runtime/event-commands.js +4 -4
  54. package/dist/runtime/events.d.ts +1 -1
  55. package/dist/runtime/events.js +5 -5
  56. package/dist/runtime/task-commands.js +9 -4
  57. package/dist/runtime/task-driver.js +12 -14
  58. package/dist/security/config.js +2 -1
  59. package/dist/security/network.js +9 -2
  60. package/dist/security/path-guard.js +12 -24
  61. package/dist/security/types.d.ts +0 -1
  62. package/dist/shared/jsonl-appender.js +2 -1
  63. package/dist/shared/task-ledger.d.ts +9 -1
  64. package/dist/shared/task-ledger.js +28 -14
  65. package/dist/shared/text-utils.d.ts +1 -0
  66. package/dist/shared/text-utils.js +3 -0
  67. package/dist/subagents/discovery.js +3 -2
  68. package/dist/subagents/tool.d.ts +2 -3
  69. package/dist/subagents/tool.js +9 -24
  70. package/dist/tasks/control.js +2 -1
  71. package/dist/tasks/verification.js +2 -1
  72. package/dist/tools/bash.d.ts +1 -1
  73. package/dist/tools/bash.js +3 -5
  74. package/dist/tools/command-optimizer.d.ts +1 -1
  75. package/dist/tools/command-optimizer.js +4 -6
  76. package/dist/tools/config.js +4 -3
  77. package/dist/tools/edit.d.ts +1 -1
  78. package/dist/tools/edit.js +0 -0
  79. package/dist/tools/event-manage.d.ts +0 -1
  80. package/dist/tools/event-manage.js +9 -14
  81. package/dist/tools/grep.d.ts +1 -1
  82. package/dist/tools/grep.js +4 -6
  83. package/dist/tools/index.d.ts +1 -3
  84. package/dist/tools/index.js +1 -4
  85. package/dist/tools/read.d.ts +1 -1
  86. package/dist/tools/read.js +1 -2
  87. package/dist/tools/registry.d.ts +1 -2
  88. package/dist/tools/registry.js +3 -10
  89. package/dist/tools/skill-manage.d.ts +0 -1
  90. package/dist/tools/skill-manage.js +7 -14
  91. package/dist/tools/task-manage.d.ts +0 -1
  92. package/dist/tools/task-manage.js +18 -16
  93. package/dist/tools/write-content.d.ts +1 -1
  94. package/dist/tools/write-content.js +0 -1
  95. package/dist/tools/write.d.ts +1 -1
  96. package/dist/tui/app.d.ts +0 -2
  97. package/dist/tui/app.js +12 -7
  98. package/dist/tui/cli.d.ts +3 -2
  99. package/dist/tui/cli.js +12 -24
  100. package/dist/tui/commands.d.ts +4 -1
  101. package/dist/tui/commands.js +10 -14
  102. package/dist/tui/turn-controller.d.ts +7 -3
  103. package/dist/tui/turn-controller.js +18 -6
  104. package/dist/web/client.js +2 -1
  105. package/package.json +2 -2
  106. package/dist/sandbox.d.ts +0 -42
@@ -130,33 +130,26 @@ export const TOOL_REGISTRY = [
130
130
  promptHint: "List, view, create, or maintain workspace-level procedural memory in skills/",
131
131
  availableToSubagents: false,
132
132
  enabledBy: (ctx) => ctx.toolsConfig?.tools.skills.manage.enabled !== false,
133
- create: (ctx) => createSkillManageTool({ workspaceDir: ctx.workspaceDir, workspacePath: ctx.workspacePath }),
133
+ create: (ctx) => createSkillManageTool({ workspaceDir: ctx.workspaceDir }),
134
134
  },
135
135
  {
136
136
  name: "event_manage",
137
- promptHint: "Schedule your own follow-ups: create/update/delete one-shot check-ins and periodic cadences for this channel. " +
138
- "Name task-owned events `task.<channelId>.<taskId>.<use>` (e.g. .checkin, .schedule) so they clean up together. " +
139
- "Task wake/resume is handled natively; use task-owned events mainly for canonical recurring .schedule cadences. " +
140
- "No immediate events; periodic no more often than every 30 min (or 5 min when it carries a preAction gate).",
137
+ promptHint: "Create/update/delete validated one-shot reminders, periodic cadences, and preAction-gated sensors",
141
138
  availableToSubagents: false,
142
139
  enabledBy: (ctx) => ctx.toolsConfig?.tools.events.enabled !== false,
143
140
  create: (ctx) => createEventManageTool({
144
141
  workspaceDir: ctx.workspaceDir,
145
- workspacePath: ctx.workspacePath,
146
142
  channelId: ctx.channelId,
147
143
  commandGuardConfig: ctx.securityConfig.commandGuard,
148
144
  }),
149
145
  },
150
146
  {
151
147
  name: "task_manage",
152
- promptHint: "Manage governed tasks: structured control/budgets/dependencies, atomic progress, candidate verification, verifier attestations, " +
153
- "verified completion, cancellation, and listing. The native driver resumes ready tasks and escalates hard limits; " +
154
- "use write/edit only for substantial body changes.",
148
+ promptHint: "Create, checkpoint, govern, verify, complete, cancel, or list persistent tasks",
155
149
  availableToSubagents: false,
156
150
  enabledBy: (ctx) => ctx.toolsConfig?.tools.tasks.enabled !== false,
157
151
  create: (ctx) => createTaskManageTool({
158
152
  workspaceDir: ctx.workspaceDir,
159
- workspacePath: ctx.workspacePath,
160
153
  channelDir: ctx.channelDir,
161
154
  channelId: ctx.channelId,
162
155
  workingDirectory: ctx.securityContext.cwd,
@@ -34,7 +34,6 @@ export interface WorkspaceSkillSummary {
34
34
  }
35
35
  export interface SkillManageToolOptions {
36
36
  workspaceDir: string;
37
- workspacePath: string;
38
37
  }
39
38
  export declare function listWorkspaceSkills(options: SkillManageToolOptions): Promise<WorkspaceSkillSummary[]>;
40
39
  export declare function manageWorkspaceSkill(options: SkillManageToolOptions, request: SkillManageRequest): Promise<SkillManageResult>;
@@ -24,12 +24,6 @@ const skillManageSchema = Type.Object({
24
24
  find: Type.Optional(Type.String({ description: "Exact text to replace when action is patch." })),
25
25
  replace: Type.Optional(Type.String({ description: "Replacement text when action is patch." })),
26
26
  });
27
- function toWorkspacePath(options, hostPath) {
28
- if (hostPath.startsWith(options.workspaceDir)) {
29
- return `${options.workspacePath}${hostPath.slice(options.workspaceDir.length)}`;
30
- }
31
- return hostPath;
32
- }
33
27
  function isNodeError(error) {
34
28
  return error instanceof Error && "code" in error;
35
29
  }
@@ -88,7 +82,7 @@ export async function listWorkspaceSkills(options) {
88
82
  summaries.push({
89
83
  name,
90
84
  description: extractDescription(content),
91
- path: `${options.workspacePath}/skills/${name}/SKILL.md`,
85
+ path: `${options.workspaceDir}/skills/${name}/SKILL.md`,
92
86
  warning: validation.ok ? undefined : validation.error,
93
87
  });
94
88
  }
@@ -138,7 +132,7 @@ export async function manageWorkspaceSkill(options, request) {
138
132
  return {
139
133
  action: "create",
140
134
  name: request.name,
141
- path: toWorkspacePath(options, skillPath),
135
+ path: skillPath,
142
136
  bytesWritten: Buffer.byteLength(content, "utf-8"),
143
137
  requiresResourceRefresh: true,
144
138
  notice: `已沉淀:创建 workspace skill \`${request.name}\`。`,
@@ -158,7 +152,7 @@ export async function manageWorkspaceSkill(options, request) {
158
152
  return {
159
153
  action: "write_file",
160
154
  name: request.name,
161
- path: toWorkspacePath(options, targetPath),
155
+ path: targetPath,
162
156
  bytesWritten: Buffer.byteLength(content, "utf-8"),
163
157
  requiresResourceRefresh: true,
164
158
  notice: `已沉淀:更新 workspace skill \`${request.name}\` 的支持文件。`,
@@ -178,7 +172,7 @@ export async function manageWorkspaceSkill(options, request) {
178
172
  return {
179
173
  action: "patch",
180
174
  name: request.name,
181
- path: toWorkspacePath(options, targetPath),
175
+ path: targetPath,
182
176
  bytesWritten: Buffer.byteLength(nextContent, "utf-8"),
183
177
  requiresResourceRefresh: true,
184
178
  notice: `已沉淀:更新 workspace skill \`${request.name}\`。`,
@@ -187,17 +181,16 @@ export async function manageWorkspaceSkill(options, request) {
187
181
  async function viewWorkspaceSkill(options, name, filePath) {
188
182
  const skillDir = resolveSkillPath(options.workspaceDir, name);
189
183
  const targetPath = filePath ? resolveSkillSupportingFile(skillDir, filePath) : join(skillDir, "SKILL.md");
190
- const workspacePath = toWorkspacePath(options, targetPath);
191
184
  const content = await readFile(targetPath, "utf-8");
192
185
  // Cap with the shared truncation limits so a large supporting file cannot flood context.
193
186
  const truncation = truncateHead(content);
194
187
  let body = truncation.content;
195
188
  if (truncation.truncated) {
196
- body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${workspacePath} to page through the rest.]`;
189
+ body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${targetPath} to page through the rest.]`;
197
190
  }
198
191
  return {
199
- content: [{ type: "text", text: `Skill: ${name}\nPath: ${workspacePath}\n\n${body}` }],
200
- details: { kind: "skill_manage", action: "view", name, path: workspacePath, truncated: truncation.truncated },
192
+ content: [{ type: "text", text: `Skill: ${name}\nPath: ${targetPath}\n\n${body}` }],
193
+ details: { kind: "skill_manage", action: "view", name, path: targetPath, truncated: truncation.truncated },
201
194
  };
202
195
  }
203
196
  export function createSkillManageTool(options) {
@@ -80,7 +80,6 @@ export interface TaskManageRequest {
80
80
  }
81
81
  export interface TaskManageToolOptions {
82
82
  workspaceDir: string;
83
- workspacePath: string;
84
83
  channelDir: string;
85
84
  channelId: string;
86
85
  /** Project checkout whose artifact state an independent verifier binds to. */
@@ -57,7 +57,9 @@ const taskManageSchema = Type.Object({
57
57
  id: Type.Optional(Type.String({ description: "Task id (filename without .md). Required for create/progress/set/done." })),
58
58
  title: Type.Optional(Type.String({ description: "Required for create: task title used as the H1 heading." })),
59
59
  goal: Type.Optional(Type.String({ description: "Required for create: concise task goal." })),
60
- dod: Type.Optional(Type.String({ description: "Required for create: acceptance criteria / definition of done." })),
60
+ dod: Type.Optional(Type.String({
61
+ description: 'Required for create: acceptance criteria as Markdown checklist items, one per line, e.g. "- [ ] <criterion>". Plain prose or a numbered list without checkboxes is rejected — candidate/done can only verify items that are checkable.',
62
+ })),
61
63
  manual: Type.Optional(Type.String({ description: "Optional for create: initial operating steps or checklist." })),
62
64
  verificationPlan: Type.Optional(Type.String({ description: "Optional for create: deterministic checks the verifier must perform." })),
63
65
  control: Type.Optional(taskControlSchema),
@@ -92,12 +94,6 @@ function parseAction(action) {
92
94
  }
93
95
  throw new Error("Unsupported task action. Use create, progress, set, verify, done, cancel, start-cycle, or list.");
94
96
  }
95
- function toWorkspacePath(options, hostPath) {
96
- if (hostPath.startsWith(options.workspaceDir)) {
97
- return `${options.workspacePath}${hostPath.slice(options.workspaceDir.length)}`;
98
- }
99
- return hostPath;
100
- }
101
97
  function tasksDir(options) {
102
98
  return join(options.channelDir, "tasks");
103
99
  }
@@ -283,13 +279,16 @@ async function createTask(options, request) {
283
279
  throw new Error(`Archived task "${id}" already exists; choose a new id or restore it manually first.`);
284
280
  }
285
281
  const { fields, body } = renderTaskSkeleton(request);
282
+ const badDod = uncheckedTaskAcceptanceItems(body).find((item) => item.startsWith("DoD has no checklist items"));
283
+ if (badDod)
284
+ throw new Error(badDod);
286
285
  await validateTaskRelations(options, id, fields);
287
286
  await mkdir(dir, { recursive: true });
288
287
  await writeFileAtomically(taskPath, renderTaskFile(fields, body));
289
288
  return {
290
289
  action: "create",
291
290
  id,
292
- path: toWorkspacePath(options, taskPath),
291
+ path: taskPath,
293
292
  status: fields.status,
294
293
  notice: `已创建任务 \`${id}\`(status: ${fields.status})。`,
295
294
  };
@@ -298,7 +297,7 @@ async function createTask(options, request) {
298
297
  * On close-out, keep only the task's recurring cadence event
299
298
  * (`task.<channelId>.<id>.schedule`) and delete every other task-owned event.
300
299
  *
301
- * A task may also own temporary periodic events (for example an agentmux idle sensor).
300
+ * A task may also own temporary periodic sensor/check-in events.
302
301
  * Those are lifecycle check-ins, not proof that the task itself is recurring, so they
303
302
  * must not prevent a one-shot task from being archived.
304
303
  */
@@ -347,7 +346,7 @@ async function setTask(options, request) {
347
346
  return {
348
347
  action: "set",
349
348
  id,
350
- path: toWorkspacePath(options, taskPath),
349
+ path: taskPath,
351
350
  status: nextFields.status,
352
351
  notice: `已更新任务 \`${id}\`(status: ${nextFields.status}${nextFields.wake ? `, wake: ${nextFields.wake}` : ""})。`,
353
352
  };
@@ -359,6 +358,9 @@ async function progressTask(options, request) {
359
358
  const note = requiredField(request.note, "note", "progress");
360
359
  const taskPath = join(tasksDir(options), `${id}.md`);
361
360
  const { fields, body } = await readTaskDocument(taskPath, id);
361
+ if (["done", "cancelled", "escalated", "paused"].includes(fields.status)) {
362
+ throw new Error(`Task "${id}" is ${fields.status} and cannot be progressed.`);
363
+ }
362
364
  const nextFields = applySet(fields, request);
363
365
  await validateTaskRelations(options, id, nextFields);
364
366
  if (nextFields.control) {
@@ -378,7 +380,7 @@ async function progressTask(options, request) {
378
380
  return {
379
381
  action: "progress",
380
382
  id,
381
- path: toWorkspacePath(options, taskPath),
383
+ path: taskPath,
382
384
  status: nextFields.status,
383
385
  notice: `已记录任务 \`${id}\` 的进展(status: ${nextFields.status}${nextFields.wake ? `, wake: ${nextFields.wake}` : ""})。`,
384
386
  };
@@ -412,7 +414,7 @@ async function candidateTask(options, request) {
412
414
  return {
413
415
  action: "candidate",
414
416
  id,
415
- path: toWorkspacePath(options, taskPath),
417
+ path: taskPath,
416
418
  status: "verifying",
417
419
  notice: `任务 \`${id}\` 已进入独立验收队列;driver 将安排 verifier。`,
418
420
  };
@@ -461,7 +463,7 @@ async function verifyTask(options, request) {
461
463
  return {
462
464
  action: "verify",
463
465
  id,
464
- path: toWorkspacePath(options, task.path),
466
+ path: task.path,
465
467
  status: task.fields.status,
466
468
  notice: `任务 \`${id}\` 独立验收结果:${attestation.verdict.toUpperCase()}(run: ${runId})。`,
467
469
  };
@@ -538,7 +540,7 @@ async function doneTask(options, request) {
538
540
  return {
539
541
  action: "done",
540
542
  id,
541
- path: toWorkspacePath(options, finalPath),
543
+ path: finalPath,
542
544
  status: "done",
543
545
  archived,
544
546
  deletedEvents: deleted,
@@ -571,7 +573,7 @@ async function cancelTask(options, request) {
571
573
  return {
572
574
  action: "cancel",
573
575
  id,
574
- path: toWorkspacePath(options, finalPath),
576
+ path: finalPath,
575
577
  status: "cancelled",
576
578
  archived: true,
577
579
  deletedEvents: deleted,
@@ -597,7 +599,7 @@ async function startCycleTask(options, request) {
597
599
  return {
598
600
  action: "start-cycle",
599
601
  id,
600
- path: toWorkspacePath(options, taskPath),
602
+ path: taskPath,
601
603
  status: "in-progress",
602
604
  notice: `已开启周期任务 \`${id}\` 的新周期 \`${cycleId}\`。`,
603
605
  };
@@ -1,4 +1,4 @@
1
- import type { Executor } from "../sandbox.js";
1
+ import type { Executor } from "../executor.js";
2
2
  import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
3
3
  export declare function writeContent(executor: Executor, path: string, content: string, signal: AbortSignal | undefined, options?: {
4
4
  createParentDir?: boolean;
@@ -16,7 +16,6 @@ export async function writeContent(executor, path, content, signal, options) {
16
16
  const securityConfig = options?.securityConfig ?? DEFAULT_SECURITY_CONFIG;
17
17
  const securityContext = options?.securityContext ?? {
18
18
  workspaceDir: process.cwd(),
19
- workspacePath: process.cwd(),
20
19
  cwd: process.cwd(),
21
20
  };
22
21
  if (securityConfig.enabled && securityConfig.pathGuard.enabled) {
@@ -1,6 +1,6 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
- import type { Executor } from "../sandbox.js";
3
+ import type { Executor } from "../executor.js";
4
4
  import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
5
5
  declare const writeSchema: Type.TObject<{
6
6
  label: Type.TString;
package/dist/tui/app.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import { type BootstrapIO, type BootstrapPaths } from "../runtime/bootstrap.js";
2
- import type { SandboxConfig } from "../sandbox.js";
3
2
  export interface TuiAppOptions {
4
- sandbox: SandboxConfig;
5
3
  channel?: string;
6
4
  /** One-shot, non-interactive run: process a single prompt then exit. */
7
5
  print?: boolean;
package/dist/tui/app.js CHANGED
@@ -44,7 +44,6 @@ function safeUserName() {
44
44
  export async function runTuiApp(options) {
45
45
  const io = options.io ?? console;
46
46
  const paths = options.paths ?? DEFAULT_BOOTSTRAP_PATHS;
47
- const { sandbox } = options;
48
47
  const channelId = resolveChannelId(options.channel, io);
49
48
  // The pi-tui frontend owns stdout; the plain frontend prints only the final
50
49
  // answer. Either way the human-readable console log sink would corrupt output,
@@ -53,15 +52,15 @@ export async function runTuiApp(options) {
53
52
  log.setConsoleLoggingEnabled(false);
54
53
  // Transport-neutral init. Unlike the DingTalk path, the TUI ignores
55
54
  // channelTemplateCreated (it needs no channel.json) and shares app services
56
- // (settings, diagnostics, sandbox check) with bootstrap via prepareAppServices.
55
+ // (settings, diagnostics) with bootstrap via prepareAppServices.
57
56
  printBootstrapSummary(bootstrapAppHome(paths), io, paths);
58
- const { settingsManager } = await prepareAppServices(sandbox, paths, io);
57
+ const { settingsManager } = prepareAppServices(paths);
59
58
  log.configureLogging(settingsManager.getLoggingSettings());
60
- log.logStartup(paths.workspaceDir, sandbox.type === "host" ? "host" : `docker:${sandbox.container}`);
59
+ log.logStartup(paths.workspaceDir);
61
60
  const channelDir = ensureChannelDir(paths.workspaceDir, channelId);
62
61
  ensureChannelMemoryFilesSync(channelDir);
63
62
  const store = new ChannelStore({ workingDir: paths.workspaceDir });
64
- const runner = getOrCreateRunner(sandbox, channelId, channelDir, {
63
+ const runner = getOrCreateRunner(channelId, channelDir, {
65
64
  appHomeDir: paths.appHomeDir,
66
65
  authConfigPath: paths.authConfigPath,
67
66
  modelsConfigPath: paths.modelsConfigPath,
@@ -89,8 +88,14 @@ export async function runTuiApp(options) {
89
88
  renderHelp: () => renderBuiltInHelp(),
90
89
  renderUsage: (args) => renderUsageReport(getUsageLedger(), channelId, parseUsageMode(args), new Date()),
91
90
  runEvents: (args) => handleEventsCommand({ args, workspaceDir: paths.workspaceDir, historyPath: paths.eventHistoryPath }),
92
- runTasks: (args) => handleTasksCommand({ args, channelDir, workspaceDir: paths.workspaceDir, channelId }),
93
- statusInfo: { version: readCliVersion(), sandbox, startedAt: Date.now() },
91
+ runTasks: (args) => handleTasksCommand({
92
+ args,
93
+ channelDir,
94
+ workspaceDir: paths.workspaceDir,
95
+ channelId,
96
+ approver: safeUserName(),
97
+ }),
98
+ statusInfo: { version: readCliVersion(), startedAt: Date.now() },
94
99
  });
95
100
  try {
96
101
  if (options.print) {
package/dist/tui/cli.d.ts CHANGED
@@ -3,11 +3,9 @@
3
3
  * (`parseTuiArgs`) so it can be unit-tested; `runTui` wires it to `runTuiApp`.
4
4
  */
5
5
  import { type BootstrapIO } from "../runtime/bootstrap.js";
6
- import { type SandboxConfig } from "../sandbox.js";
7
6
  export type ParsedTui = {
8
7
  kind: "run";
9
8
  channel?: string;
10
- sandbox: SandboxConfig;
11
9
  print: boolean;
12
10
  quiet: boolean;
13
11
  plain: boolean;
@@ -16,6 +14,9 @@ export type ParsedTui = {
16
14
  kind: "help";
17
15
  } | {
18
16
  kind: "version";
17
+ } | {
18
+ kind: "error";
19
+ message: string;
19
20
  };
20
21
  /** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
21
22
  export declare function parseTuiArgs(args: string[]): ParsedTui;
package/dist/tui/cli.js CHANGED
@@ -3,12 +3,10 @@
3
3
  * (`parseTuiArgs`) so it can be unit-tested; `runTui` wires it to `runTuiApp`.
4
4
  */
5
5
  import { BootstrapExitError, readCliVersion } from "../runtime/bootstrap.js";
6
- import { parseSandboxArg, SandboxConfigError } from "../sandbox.js";
7
6
  import { runTuiApp } from "./app.js";
8
7
  /** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
9
8
  export function parseTuiArgs(args) {
10
9
  let channel;
11
- let sandbox = { type: "host" };
12
10
  let print = false;
13
11
  let quiet = false;
14
12
  let plain = false;
@@ -22,13 +20,6 @@ export function parseTuiArgs(args) {
22
20
  else if (arg.startsWith("--channel=")) {
23
21
  channel = arg.slice("--channel=".length);
24
22
  }
25
- else if (arg === "--sandbox") {
26
- sandbox = parseSandboxArg(args[index + 1] ?? "");
27
- index += 1;
28
- }
29
- else if (arg.startsWith("--sandbox=")) {
30
- sandbox = parseSandboxArg(arg.slice("--sandbox=".length));
31
- }
32
23
  else if (arg === "--print" || arg === "-p") {
33
24
  print = true;
34
25
  }
@@ -44,11 +35,16 @@ export function parseTuiArgs(args) {
44
35
  else if (arg === "--version") {
45
36
  return { kind: "version" };
46
37
  }
38
+ else if (arg.startsWith("--")) {
39
+ // An unknown long option is a typo, not part of the prompt — reject it
40
+ // instead of silently sending `--pritn` to the model as prompt text.
41
+ return { kind: "error", message: `Unknown option: ${arg}` };
42
+ }
47
43
  else {
48
44
  positional.push(arg);
49
45
  }
50
46
  }
51
- return { kind: "run", channel, sandbox, print, quiet, plain, positional };
47
+ return { kind: "run", channel, print, quiet, plain, positional };
52
48
  }
53
49
  function printTuiHelp(io) {
54
50
  io.log("Usage: pipiclaw tui [options] [prompt]");
@@ -64,8 +60,6 @@ function printTuiHelp(io) {
64
60
  io.log("Options:");
65
61
  io.log(" --channel <id> Channel to attach to (default: tui_local).");
66
62
  io.log(" Use dm_<staffId> to share a DingTalk conversation's memory.");
67
- io.log(" --sandbox=host Run tools on host (default)");
68
- io.log(" --sandbox=docker:<name> Run tools in a Docker container");
69
63
  io.log(" --print, -p One-shot: run [prompt] (or stdin), print the answer, exit");
70
64
  io.log(" --quiet, -q Plain mode: print only the final answer");
71
65
  io.log(" --plain Force the plain frontend (no full-screen UI)");
@@ -81,17 +75,7 @@ async function readStdin() {
81
75
  return Buffer.concat(chunks).toString("utf8");
82
76
  }
83
77
  export async function runTui(argv, io = console) {
84
- let parsed;
85
- try {
86
- parsed = parseTuiArgs(argv.slice(3));
87
- }
88
- catch (err) {
89
- if (err instanceof SandboxConfigError) {
90
- io.error(`Error: ${err.message}`);
91
- throw new BootstrapExitError(1);
92
- }
93
- throw err;
94
- }
78
+ const parsed = parseTuiArgs(argv.slice(3));
95
79
  if (parsed.kind === "help") {
96
80
  printTuiHelp(io);
97
81
  return;
@@ -100,12 +84,16 @@ export async function runTui(argv, io = console) {
100
84
  io.log(readCliVersion());
101
85
  return;
102
86
  }
87
+ if (parsed.kind === "error") {
88
+ io.error(parsed.message);
89
+ io.error(`Run \`pipiclaw tui --help\` for usage.`);
90
+ throw new BootstrapExitError(1);
91
+ }
103
92
  let initialPrompt = parsed.positional.join(" ").trim() || undefined;
104
93
  if (parsed.print && !initialPrompt && process.stdin.isTTY !== true) {
105
94
  initialPrompt = (await readStdin()).trim() || undefined;
106
95
  }
107
96
  await runTuiApp({
108
- sandbox: parsed.sandbox,
109
97
  channel: parsed.channel,
110
98
  print: parsed.print,
111
99
  quiet: parsed.quiet,
@@ -40,7 +40,10 @@ export interface DispatchDeps {
40
40
  runTasks(args: string): Promise<string>;
41
41
  }
42
42
  export declare function dispatch(input: string, deps: DispatchDeps): Promise<DispatchOutcome>;
43
- /** Slash commands offered in editor autocomplete: transport + session + TUI-only. */
43
+ /**
44
+ * Slash commands offered in editor autocomplete: transport + session (both
45
+ * derived from the shared command tables) plus the TUI-only `/exit`.
46
+ */
44
47
  export declare const TUI_SLASH_COMMANDS: Array<{
45
48
  name: string;
46
49
  description: string;
@@ -13,7 +13,7 @@
13
13
  * depend on whether a turn is running, which only the app knows — so those come
14
14
  * back as intents rather than being applied here.
15
15
  */
16
- import { parseBuiltInCommand } from "../agent/commands.js";
16
+ import { BUILT_IN_COMMANDS, parseBuiltInCommand, SESSION_COMMANDS } from "../agent/commands.js";
17
17
  export async function dispatch(input, deps) {
18
18
  const trimmed = input.trim();
19
19
  if (!trimmed)
@@ -49,19 +49,15 @@ export async function dispatch(input, deps) {
49
49
  : { kind: "noop", text: "/followup requires a message." };
50
50
  }
51
51
  }
52
- /** Slash commands offered in editor autocomplete: transport + session + TUI-only. */
52
+ function toAutocompleteEntry(spec) {
53
+ return { name: spec.name, description: spec.description, argumentHint: spec.argumentHint };
54
+ }
55
+ /**
56
+ * Slash commands offered in editor autocomplete: transport + session (both
57
+ * derived from the shared command tables) plus the TUI-only `/exit`.
58
+ */
53
59
  export const TUI_SLASH_COMMANDS = [
54
- { name: "help", description: "Show command help" },
55
- { name: "stop", description: "Stop the current task" },
56
- { name: "steer", description: "Adjust the running task", argumentHint: "<message>" },
57
- { name: "followup", description: "Queue a request after the current task", argumentHint: "<message>" },
58
- { name: "status", description: "Show model, context and run state" },
59
- { name: "usage", description: "Show LLM cost for this channel", argumentHint: "[7d|month]" },
60
- { name: "events", description: "Manage scheduled events", argumentHint: "<list|show|delete|history>" },
61
- { name: "tasks", description: "View the task ledger (read-only)", argumentHint: "[show <id>|archive|doctor]" },
62
- { name: "model", description: "Show or switch the model", argumentHint: "[provider/model]" },
63
- { name: "new", description: "Start a new session" },
64
- { name: "compact", description: "Compact the session context", argumentHint: "[instructions]" },
65
- { name: "session", description: "Show session state" },
60
+ ...BUILT_IN_COMMANDS.map(toAutocompleteEntry),
61
+ ...SESSION_COMMANDS.map(toAutocompleteEntry),
66
62
  { name: "exit", description: "Leave the TUI" },
67
63
  ];
@@ -8,7 +8,6 @@
8
8
  */
9
9
  import type { AgentRunner } from "../agent/types.js";
10
10
  import type { ChannelStore } from "../runtime/store.js";
11
- import type { SandboxConfig } from "../sandbox.js";
12
11
  import type { Frontend } from "./renderer.js";
13
12
  import { type DeliveryTraits } from "./terminal-context.js";
14
13
  export interface TurnControllerDeps {
@@ -26,7 +25,6 @@ export interface TurnControllerDeps {
26
25
  /** Static bits the status renderer needs alongside the live run state. */
27
26
  statusInfo: {
28
27
  version: string;
29
- sandbox: SandboxConfig;
30
28
  startedAt: number;
31
29
  };
32
30
  /** Injectable clock for deterministic Ctrl-C timing in tests. */
@@ -48,7 +46,13 @@ export declare class TurnController {
48
46
  constructor(deps: TurnControllerDeps);
49
47
  /** Interactive mode: wire input, run an optional first prompt, resolve on exit. */
50
48
  startInteractive(initialPrompt?: string): Promise<void>;
51
- /** One-shot mode: run a single prompt (if any) then shut down. */
49
+ /**
50
+ * One-shot mode: run a single prompt (if any) then shut down.
51
+ *
52
+ * Routed through the same `dispatch()` as interactive input so built-in
53
+ * slash commands (`/tasks`, `/events`, `/status`, ...) resolve zero-LLM here
54
+ * too, instead of falling through to the model as a plain message.
55
+ */
52
56
  runOnce(prompt?: string): Promise<void>;
53
57
  /** Test/observability hook. */
54
58
  isRunning(): boolean;
@@ -6,8 +6,10 @@
6
6
  * Collaborators (runner, frontend, store) are injected so the machine can be
7
7
  * unit-tested with fakes and a fake clock. `app.ts` builds the real ones.
8
8
  */
9
+ import { formatUnknownCommandMessage, slashCommandName } from "../agent/commands.js";
9
10
  import { renderStatus } from "../agent/status-render.js";
10
11
  import * as log from "../log.js";
12
+ import { errorMessage } from "../shared/text-utils.js";
11
13
  import { bold, dim } from "./colors.js";
12
14
  import { dispatch } from "./commands.js";
13
15
  import { createTerminalContext } from "./terminal-context.js";
@@ -15,9 +17,6 @@ const SHUTDOWN_ABORT_WAIT_MS = 5000;
15
17
  // Cap the exit-time memory flush so a slow/stuck LLM consolidation can't trap
16
18
  // the user in a non-responsive process. Memory may be partially saved on timeout.
17
19
  const SHUTDOWN_FLUSH_WAIT_MS = 20_000;
18
- function errorMessage(err) {
19
- return err instanceof Error ? err.message : String(err);
20
- }
21
20
  export class TurnController {
22
21
  constructor(deps) {
23
22
  this.running = false;
@@ -40,7 +39,6 @@ export class TurnController {
40
39
  state: { running: this.running, currentTaskText: this.currentTaskText, runner: this.deps.runner },
41
40
  version: deps.statusInfo.version,
42
41
  uptimeMs: this.now() - deps.statusInfo.startedAt,
43
- sandbox: deps.statusInfo.sandbox,
44
42
  }),
45
43
  };
46
44
  }
@@ -57,11 +55,17 @@ export class TurnController {
57
55
  this.submit(initialPrompt);
58
56
  return this.exitPromise;
59
57
  }
60
- /** One-shot mode: run a single prompt (if any) then shut down. */
58
+ /**
59
+ * One-shot mode: run a single prompt (if any) then shut down.
60
+ *
61
+ * Routed through the same `dispatch()` as interactive input so built-in
62
+ * slash commands (`/tasks`, `/events`, `/status`, ...) resolve zero-LLM here
63
+ * too, instead of falling through to the model as a plain message.
64
+ */
61
65
  async runOnce(prompt) {
62
66
  const trimmed = prompt?.trim();
63
67
  if (trimmed) {
64
- this.beginTurn(trimmed);
68
+ await this.processSubmit(trimmed);
65
69
  await this.currentTurn;
66
70
  }
67
71
  await this.shutdown();
@@ -107,7 +111,15 @@ export class TurnController {
107
111
  this.applyFollowup(outcome.text);
108
112
  return;
109
113
  case "steer":
114
+ await this.applyText(outcome.text);
115
+ return;
110
116
  case "run":
117
+ // Reject an unknown slash command rather than steering/running its raw
118
+ // text. Session commands, skills, and prompt templates pass through.
119
+ if (outcome.text.trim().startsWith("/") && !this.deps.runner.isKnownSlashCommand(outcome.text)) {
120
+ this.deps.frontend.showFinal(formatUnknownCommandMessage(slashCommandName(outcome.text) ?? ""));
121
+ return;
122
+ }
111
123
  await this.applyText(outcome.text);
112
124
  return;
113
125
  }
@@ -6,6 +6,7 @@ import { getProxyForUrl } from "proxy-from-env";
6
6
  import { SocksProxyAgent } from "socks-proxy-agent";
7
7
  import { logSecurityEvent } from "../security/logger.js";
8
8
  import { NetworkGuardError, validateNetworkTarget, validateRedirectTarget } from "../security/network.js";
9
+ import { errorMessage } from "../shared/text-utils.js";
9
10
  export const WEB_USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Pipiclaw/0.5";
10
11
  const agentCache = new Map();
11
12
  function normalizeHeaders(headers) {
@@ -177,7 +178,7 @@ export class WebHttpClient {
177
178
  };
178
179
  }
179
180
  catch (error) {
180
- throw new Error(`Expected JSON response from ${options.url}, got invalid JSON: ${error instanceof Error ? error.message : String(error)}`);
181
+ throw new Error(`Expected JSON response from ${options.url}, got invalid JSON: ${errorMessage(error)}`);
181
182
  }
182
183
  }
183
184
  async requestText(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true }); require('node:fs').rmSync('coverage', { recursive: true, force: true });\"",
25
- "build": "tsc -p tsconfig.build.json && node -e \"require('node:fs').chmodSync('dist/main.js', 0o755)\"",
25
+ "build": "tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); const src = 'src/playbooks', dst = 'dist/playbooks'; fs.rmSync(dst, { recursive: true, force: true }); fs.mkdirSync(dst, { recursive: true }); for (const f of fs.readdirSync(src)) if (f.endsWith('.md')) fs.copyFileSync(src + '/' + f, dst + '/' + f); fs.chmodSync('dist/main.js', 0o755)\"",
26
26
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
27
27
  "lint": "biome check .",
28
28
  "typecheck": "tsc --noEmit -p tsconfig.json",