@oyasmi/pipiclaw 0.7.7 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +23 -2
  2. package/dist/agent/channel-runner.d.ts +4 -4
  3. package/dist/agent/channel-runner.js +25 -23
  4. package/dist/agent/commands.js +7 -2
  5. package/dist/agent/job-manager.d.ts +5 -5
  6. package/dist/agent/prompt-builder.d.ts +3 -13
  7. package/dist/agent/prompt-builder.js +49 -159
  8. package/dist/agent/run-queue.js +2 -1
  9. package/dist/agent/runner-factory.d.ts +1 -2
  10. package/dist/agent/runner-factory.js +2 -2
  11. package/dist/agent/status-render.d.ts +0 -7
  12. package/dist/agent/status-render.js +8 -3
  13. package/dist/agent/types.d.ts +2 -0
  14. package/dist/agent/workspace-resources.d.ts +1 -1
  15. package/dist/agent/workspace-resources.js +3 -15
  16. package/dist/executor.d.ts +20 -0
  17. package/dist/{sandbox.js → executor.js} +3 -95
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/log.d.ts +1 -1
  21. package/dist/log.js +1 -2
  22. package/dist/memory/files.js +0 -0
  23. package/dist/memory/lifecycle.js +6 -5
  24. package/dist/memory/maintenance-jobs.d.ts +0 -1
  25. package/dist/memory/maintenance-jobs.js +2 -2
  26. package/dist/memory/maintenance-state.js +2 -1
  27. package/dist/memory/post-turn-review.d.ts +0 -1
  28. package/dist/memory/post-turn-review.js +4 -4
  29. package/dist/memory/scheduler.d.ts +0 -1
  30. package/dist/memory/scheduler.js +2 -2
  31. package/dist/memory/session.js +2 -2
  32. package/dist/memory/task-digest.js +17 -0
  33. package/dist/paths.d.ts +2 -0
  34. package/dist/paths.js +11 -0
  35. package/dist/playbooks/catalog.d.ts +9 -0
  36. package/dist/playbooks/catalog.js +44 -0
  37. package/dist/playbooks/event-scheduling.md +43 -0
  38. package/dist/playbooks/memory-and-learning.md +45 -0
  39. package/dist/playbooks/runtime-orientation.md +48 -0
  40. package/dist/playbooks/task-closeout.md +45 -0
  41. package/dist/playbooks/task-delegation.md +44 -0
  42. package/dist/playbooks/task-driving.md +43 -0
  43. package/dist/playbooks/task-planning.md +47 -0
  44. package/dist/playbooks/task-recurring.md +42 -0
  45. package/dist/playbooks/task-repair.md +43 -0
  46. package/dist/runtime/bootstrap.d.ts +12 -11
  47. package/dist/runtime/bootstrap.js +81 -57
  48. package/dist/runtime/delivery.js +4 -3
  49. package/dist/runtime/dingtalk.d.ts +2 -0
  50. package/dist/runtime/dingtalk.js +15 -14
  51. package/dist/runtime/durable-dispatch.d.ts +30 -0
  52. package/dist/runtime/durable-dispatch.js +172 -0
  53. package/dist/runtime/event-commands.js +4 -4
  54. package/dist/runtime/events.d.ts +5 -3
  55. package/dist/runtime/events.js +17 -13
  56. package/dist/runtime/task-commands.d.ts +6 -0
  57. package/dist/runtime/task-commands.js +292 -6
  58. package/dist/runtime/task-driver.d.ts +32 -0
  59. package/dist/runtime/task-driver.js +268 -0
  60. package/dist/security/config.js +2 -1
  61. package/dist/security/network.js +9 -2
  62. package/dist/security/path-guard.js +12 -24
  63. package/dist/security/types.d.ts +0 -1
  64. package/dist/settings.d.ts +12 -0
  65. package/dist/settings.js +30 -0
  66. package/dist/shared/jsonl-appender.js +2 -1
  67. package/dist/shared/task-ledger.d.ts +35 -0
  68. package/dist/shared/task-ledger.js +229 -15
  69. package/dist/shared/text-utils.d.ts +1 -0
  70. package/dist/shared/text-utils.js +3 -0
  71. package/dist/subagents/discovery.js +3 -2
  72. package/dist/subagents/tool.d.ts +15 -3
  73. package/dist/subagents/tool.js +194 -17
  74. package/dist/tasks/artifact-subject.d.ts +6 -0
  75. package/dist/tasks/artifact-subject.js +29 -0
  76. package/dist/tasks/control.d.ts +83 -0
  77. package/dist/tasks/control.js +293 -0
  78. package/dist/tasks/store.d.ts +32 -0
  79. package/dist/tasks/store.js +142 -0
  80. package/dist/tasks/verification.d.ts +23 -0
  81. package/dist/tasks/verification.js +69 -0
  82. package/dist/tools/bash.d.ts +1 -1
  83. package/dist/tools/bash.js +3 -5
  84. package/dist/tools/command-optimizer.d.ts +1 -1
  85. package/dist/tools/command-optimizer.js +4 -6
  86. package/dist/tools/config.js +4 -3
  87. package/dist/tools/edit.d.ts +1 -1
  88. package/dist/tools/edit.js +0 -0
  89. package/dist/tools/event-manage.d.ts +0 -1
  90. package/dist/tools/event-manage.js +9 -14
  91. package/dist/tools/grep.d.ts +1 -1
  92. package/dist/tools/grep.js +4 -6
  93. package/dist/tools/index.d.ts +1 -3
  94. package/dist/tools/index.js +1 -4
  95. package/dist/tools/read.d.ts +1 -1
  96. package/dist/tools/read.js +1 -2
  97. package/dist/tools/registry.d.ts +2 -3
  98. package/dist/tools/registry.js +5 -11
  99. package/dist/tools/skill-manage.d.ts +0 -1
  100. package/dist/tools/skill-manage.js +7 -14
  101. package/dist/tools/task-manage.d.ts +37 -4
  102. package/dist/tools/task-manage.js +398 -39
  103. package/dist/tools/write-content.d.ts +1 -1
  104. package/dist/tools/write-content.js +0 -1
  105. package/dist/tools/write.d.ts +1 -1
  106. package/dist/tui/app.d.ts +0 -2
  107. package/dist/tui/app.js +12 -7
  108. package/dist/tui/cli.d.ts +0 -2
  109. package/dist/tui/cli.js +3 -25
  110. package/dist/tui/turn-controller.d.ts +7 -3
  111. package/dist/tui/turn-controller.js +9 -6
  112. package/dist/web/client.js +2 -1
  113. package/package.json +2 -2
  114. package/dist/sandbox.d.ts +0 -42
@@ -7,6 +7,7 @@ import { resolveEventPath } from "../runtime/event-commands.js";
7
7
  import { parseScheduledEventContent } from "../runtime/events.js";
8
8
  import { guardCommand } from "../security/command-guard.js";
9
9
  import { writeFileAtomically } from "../shared/atomic-file.js";
10
+ import { errorMessage } from "../shared/text-utils.js";
10
11
  import { isRecord } from "../shared/type-guards.js";
11
12
  /** one-shot events must be scheduled at least this far out; anything sooner is effectively self-triggering. */
12
13
  const MIN_ONE_SHOT_LEAD_MS = 2 * 60 * 1000;
@@ -15,8 +16,8 @@ const MIN_PERIODIC_INTERVAL_MS = 30 * 60 * 1000;
15
16
  /**
16
17
  * periodic events WITH a preAction gate may fire this often: the sensor is the token guard
17
18
  * (it exits non-zero and stays silent when there is nothing to do), so a tighter cadence is
18
- * safe and is exactly the design-endorsed posture for completion-driven checks (e.g. polling
19
- * an agentmux instance until it goes idle). A hard sub-floor still applies so a bogus
19
+ * safe and is exactly the design-endorsed posture for completion-driven checks. A hard
20
+ * sub-floor still applies so a bogus
20
21
  * always-pass preAction cannot drive an arbitrarily hot loop.
21
22
  */
22
23
  const MIN_PERIODIC_INTERVAL_WITH_PREACTION_MS = 5 * 60 * 1000;
@@ -40,12 +41,6 @@ function parseAction(action) {
40
41
  }
41
42
  throw new Error('Unsupported event action. Use "create", "update", or "delete".');
42
43
  }
43
- function toWorkspacePath(options, hostPath) {
44
- if (hostPath.startsWith(options.workspaceDir)) {
45
- return `${options.workspacePath}${hostPath.slice(options.workspaceDir.length)}`;
46
- }
47
- return hostPath;
48
- }
49
44
  function validateTimezone(timezone) {
50
45
  try {
51
46
  new Intl.DateTimeFormat(undefined, { timeZone: timezone });
@@ -72,7 +67,7 @@ function validatePeriodic(event) {
72
67
  cron.stop();
73
68
  }
74
69
  catch (error) {
75
- const message = error instanceof Error ? error.message : String(error);
70
+ const message = errorMessage(error);
76
71
  throw new Error(`Invalid cron schedule "${event.schedule}": ${message}`);
77
72
  }
78
73
  // A preAction gate makes a tighter cadence safe (the sensor keeps most fires silent);
@@ -107,7 +102,7 @@ function validateDefinition(rawDefinition, name, options) {
107
102
  data = JSON.parse(rawDefinition);
108
103
  }
109
104
  catch (error) {
110
- const message = error instanceof Error ? error.message : String(error);
105
+ const message = errorMessage(error);
111
106
  throw new Error(`definition is not valid JSON: ${message}`);
112
107
  }
113
108
  if (!isRecord(data)) {
@@ -140,7 +135,7 @@ async function readOwnedEvent(eventPath, name, options) {
140
135
  existing = parseScheduledEventContent(await readFile(eventPath, "utf-8"), `${name}.json`);
141
136
  }
142
137
  catch (error) {
143
- const message = error instanceof Error ? error.message : String(error);
138
+ const message = errorMessage(error);
144
139
  throw new Error(`Existing event "${name}" could not be parsed (${message}); use /events to manage it directly.`);
145
140
  }
146
141
  if (existing.channelId !== options.channelId) {
@@ -162,7 +157,7 @@ export async function manageEvent(options, request) {
162
157
  return {
163
158
  action: "delete",
164
159
  name: eventName,
165
- path: toWorkspacePath(options, eventPath),
160
+ path: eventPath,
166
161
  deleted: false,
167
162
  notice: `事件 \`${eventName}\` 不存在,无需删除。`,
168
163
  };
@@ -172,7 +167,7 @@ export async function manageEvent(options, request) {
172
167
  return {
173
168
  action: "delete",
174
169
  name: eventName,
175
- path: toWorkspacePath(options, eventPath),
170
+ path: eventPath,
176
171
  deleted: true,
177
172
  notice: `已删除事件 \`${eventName}\`。`,
178
173
  };
@@ -203,7 +198,7 @@ export async function manageEvent(options, request) {
203
198
  return {
204
199
  action: request.action,
205
200
  name: eventName,
206
- path: toWorkspacePath(options, eventPath),
201
+ path: eventPath,
207
202
  eventType: event.type,
208
203
  channelId: event.channelId,
209
204
  bytesWritten: Buffer.byteLength(content, "utf-8"),
@@ -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 grepSchema: Type.TObject<{
6
6
  label: Type.TString;
@@ -5,11 +5,10 @@ import { guardPath } from "../security/path-guard.js";
5
5
  import { shellEscape } from "../shared/shell-escape.js";
6
6
  import { DEFAULT_MAX_BYTES, truncateHead } from "./truncate.js";
7
7
  /**
8
- * Structured content search over the sandbox filesystem. The execution layer is deliberately thin
9
- * — one `grep -rnH -B1 -A3` invocation through the shared Executor, so it works identically on the
10
- * host and inside the Docker (busybox) sandbox with no native dependency. The value lives in the
11
- * JS-side output shaping: per-file grouping, per-file and per-page caps, and a final byte bound, so
12
- * a broad search can never flood the model's context the way raw `bash grep -rn` would.
8
+ * Structured content search over the filesystem. The execution layer is deliberately thin — one
9
+ * `grep -rnH -B1 -A3` invocation through the shared Executor, with no native dependency. The value
10
+ * lives in the JS-side output shaping: per-file grouping, per-file and per-page caps, and a final
11
+ * byte bound, so a broad search can never flood the model's context the way raw `bash grep -rn` would.
13
12
  */
14
13
  const CONTEXT_BEFORE = 1;
15
14
  const CONTEXT_AFTER = 3;
@@ -136,7 +135,6 @@ export function createGrepTool(executor, options = {}) {
136
135
  const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
137
136
  const securityContext = options.securityContext ?? {
138
137
  workspaceDir: process.cwd(),
139
- workspacePath: process.cwd(),
140
138
  cwd: process.cwd(),
141
139
  };
142
140
  return {
@@ -1,7 +1,7 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import type { Api, Model } from "@earendil-works/pi-ai";
3
+ import type { Executor } from "../executor.js";
3
4
  import type { MemoryCandidateStore } from "../memory/candidates.js";
4
- import type { Executor, SandboxConfig } from "../sandbox.js";
5
5
  import type { SecurityConfig } from "../security/types.js";
6
6
  import type { PipiclawMemoryRecallSettings, PipiclawSessionSearchSettings } from "../settings.js";
7
7
  import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
@@ -13,9 +13,7 @@ export interface CreatePipiclawToolsOptions {
13
13
  resolveApiKey: (model: Model<Api>) => Promise<string>;
14
14
  workspaceDir: string;
15
15
  channelDir: string;
16
- workspacePath: string;
17
16
  channelId: string;
18
- sandboxConfig: SandboxConfig;
19
17
  getSubAgentDiscovery: () => SubAgentDiscoveryResult;
20
18
  getMemoryRecallSettings: () => PipiclawMemoryRecallSettings;
21
19
  getSessionSearchSettings: () => PipiclawSessionSearchSettings;
@@ -9,7 +9,6 @@ export function createPipiclawTools(options) {
9
9
  const toolsConfig = options.toolsConfig ?? loadToolsConfig(APP_HOME_DIR);
10
10
  const securityContext = {
11
11
  workspaceDir: options.workspaceDir,
12
- workspacePath: options.workspacePath,
13
12
  cwd: process.cwd(),
14
13
  };
15
14
  // The leaf tools (files, web, memory, skills) come from the single declarative
@@ -23,7 +22,6 @@ export function createPipiclawTools(options) {
23
22
  channelId: options.channelId,
24
23
  channelDir: options.channelDir,
25
24
  workspaceDir: options.workspaceDir,
26
- workspacePath: options.workspacePath,
27
25
  webConfig: toolsConfig.tools.web,
28
26
  toolsConfig,
29
27
  rtkEnabled: toolsConfig.tools.rtk.enabled,
@@ -53,9 +51,8 @@ export function createPipiclawTools(options) {
53
51
  webConfig: toolsConfig.tools.web,
54
52
  rtkEnabled: toolsConfig.tools.rtk.enabled,
55
53
  runtimeContext: {
56
- workspacePath: options.workspacePath,
54
+ workspaceDir: options.workspaceDir,
57
55
  channelId: options.channelId,
58
- sandbox: options.sandboxConfig.type === "host" ? "host" : `docker:${options.sandboxConfig.container}`,
59
56
  },
60
57
  }),
61
58
  ];
@@ -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 readSchema: Type.TObject<{
6
6
  label: Type.TString;
@@ -90,7 +90,6 @@ export function createReadTool(executor, options = {}) {
90
90
  const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
91
91
  const securityContext = options.securityContext ?? {
92
92
  workspaceDir: process.cwd(),
93
- workspacePath: process.cwd(),
94
93
  cwd: process.cwd(),
95
94
  };
96
95
  return {
@@ -138,7 +137,7 @@ export function createReadTool(executor, options = {}) {
138
137
  if (isPdf) {
139
138
  const converted = await executor.exec(`pdftotext -layout ${shellEscape(path)} - 2>&1`, { signal });
140
139
  if (converted.code === 127) {
141
- throw new Error(`Cannot read ${path}: pdftotext is not installed. Install poppler-utils (host) or rebuild the Docker sandbox image, or ask the user to send a text version.`);
140
+ throw new Error(`Cannot read ${path}: pdftotext is not installed. Install poppler-utils, or ask the user to send a text version.`);
142
141
  }
143
142
  if (converted.code !== 0 || !converted.stdout.trim()) {
144
143
  throw new Error(`Cannot read .pdf file ${path}: ${converted.stdout.trim() || "conversion produced no text"}. ` +
@@ -1,8 +1,8 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import type { Api, Model } from "@earendil-works/pi-ai";
3
3
  import type { ChannelJobManager } from "../agent/job-manager.js";
4
+ import type { Executor } from "../executor.js";
4
5
  import type { MemoryCandidateStore } from "../memory/candidates.js";
5
- import type { Executor } from "../sandbox.js";
6
6
  import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
7
7
  import type { PipiclawSessionSearchSettings } from "../settings.js";
8
8
  import type { PipiclawToolsConfig, PipiclawWebToolsConfig } from "./config.js";
@@ -22,7 +22,6 @@ export interface ToolBuildContext {
22
22
  channelId: string;
23
23
  channelDir: string;
24
24
  workspaceDir: string;
25
- workspacePath: string;
26
25
  /** Main set: `toolsConfig.tools.web`; sub-agent set: the sub-agent's own webConfig. */
27
26
  webConfig?: PipiclawWebToolsConfig;
28
27
  /** Present only on the main path; gates session_search / memory_manage / skills. */
@@ -60,7 +59,7 @@ export interface ToolRegistration {
60
59
  */
61
60
  export declare const TOOL_REGISTRY: ToolRegistration[];
62
61
  /** Prompt hint for the `subagent` tool, which is registered outside TOOL_REGISTRY. */
63
- export declare const SUBAGENT_TOOL_HINT = "Delegate a focused task to a sub-agent with its own isolated context";
62
+ export declare const SUBAGENT_TOOL_HINT = "Delegate focused work or independent verification; optionally isolate implementation in a task-owned git worktree";
64
63
  /** Single source of truth for prompt hints, keyed by tool name (leaf tools + subagent). */
65
64
  export declare const TOOL_PROMPT_HINTS: Record<string, string>;
66
65
  export interface BuildToolSetOptions {
@@ -130,35 +130,29 @@ 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
- "Keep a task's `wake` and its .checkin one-shot in sync — move both, clear both. " +
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 the task ledger: create standard task skeletons, set status/wake/recurrence, close tasks out " +
153
- "(archives one-shot tasks and cleans up residual events; done requires summary and evidence), or list active " +
154
- "tasks. Use write/edit 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,
155
+ workingDirectory: ctx.securityContext.cwd,
162
156
  }),
163
157
  },
164
158
  {
@@ -171,7 +165,7 @@ export const TOOL_REGISTRY = [
171
165
  },
172
166
  ];
173
167
  /** Prompt hint for the `subagent` tool, which is registered outside TOOL_REGISTRY. */
174
- export const SUBAGENT_TOOL_HINT = "Delegate a focused task to a sub-agent with its own isolated context";
168
+ export const SUBAGENT_TOOL_HINT = "Delegate focused work or independent verification; optionally isolate implementation in a task-owned git worktree";
175
169
  /** Single source of truth for prompt hints, keyed by tool name (leaf tools + subagent). */
176
170
  export const TOOL_PROMPT_HINTS = {
177
171
  ...Object.fromEntries(TOOL_REGISTRY.map((registration) => [registration.name, registration.promptHint])),
@@ -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) {
@@ -1,21 +1,46 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { Type } from "typebox";
3
+ import { type TaskControl, type TaskControlPatch } from "../tasks/control.js";
3
4
  declare const taskManageSchema: Type.TObject<{
4
5
  label: Type.TString;
5
- action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"set">, Type.TLiteral<"done">, Type.TLiteral<"list">]>;
6
+ action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"progress">, Type.TLiteral<"set">, Type.TLiteral<"verify">, Type.TLiteral<"done">, Type.TLiteral<"cancel">, Type.TLiteral<"start-cycle">, Type.TLiteral<"candidate">, Type.TLiteral<"list">]>;
6
7
  id: Type.TOptional<Type.TString>;
7
8
  title: Type.TOptional<Type.TString>;
8
9
  goal: Type.TOptional<Type.TString>;
9
10
  dod: Type.TOptional<Type.TString>;
10
11
  manual: Type.TOptional<Type.TString>;
11
- status: Type.TOptional<Type.TUnion<Type.TLiteral<"open" | "blocked" | "in-progress" | "awaiting-user">[]>>;
12
+ verificationPlan: Type.TOptional<Type.TString>;
13
+ control: Type.TOptional<Type.TObject<{
14
+ priority: Type.TOptional<Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"normal">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>>;
15
+ deadline: Type.TOptional<Type.TString>;
16
+ nextAction: Type.TOptional<Type.TString>;
17
+ lastOutcome: Type.TOptional<Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"progress">, Type.TLiteral<"blocked">, Type.TLiteral<"failed">, Type.TLiteral<"verified">]>>;
18
+ blockedReason: Type.TOptional<Type.TString>;
19
+ parent: Type.TOptional<Type.TString>;
20
+ dependsOn: Type.TOptional<Type.TArray<Type.TString>>;
21
+ isolation: Type.TOptional<Type.TUnion<[Type.TLiteral<"shared">, Type.TLiteral<"worktree">]>>;
22
+ sideEffects: Type.TOptional<Type.TUnion<[Type.TLiteral<"read-only">, Type.TLiteral<"workspace">, Type.TLiteral<"external">]>>;
23
+ externalApproval: Type.TOptional<Type.TUnion<[Type.TLiteral<"not-required">, Type.TLiteral<"required">]>>;
24
+ maxAttempts: Type.TOptional<Type.TInteger>;
25
+ maxTokens: Type.TOptional<Type.TNumber>;
26
+ maxCostUsd: Type.TOptional<Type.TNumber>;
27
+ maxWallTimeMinutes: Type.TOptional<Type.TNumber>;
28
+ verificationMode: Type.TOptional<Type.TUnion<[Type.TLiteral<"evidence">, Type.TLiteral<"independent">]>>;
29
+ worktreePath: Type.TOptional<Type.TString>;
30
+ worktreeBranch: Type.TOptional<Type.TString>;
31
+ }>>;
32
+ status: Type.TOptional<Type.TUnion<Type.TLiteral<"blocked" | "paused" | "open" | "in-progress" | "awaiting-user">[]>>;
12
33
  wake: Type.TOptional<Type.TString>;
13
34
  recurrence: Type.TOptional<Type.TString>;
35
+ note: Type.TOptional<Type.TString>;
36
+ verifierRunId: Type.TOptional<Type.TString>;
14
37
  summary: Type.TOptional<Type.TString>;
15
38
  evidence: Type.TOptional<Type.TString>;
16
39
  residualRisk: Type.TOptional<Type.TString>;
40
+ reason: Type.TOptional<Type.TString>;
41
+ cycleId: Type.TOptional<Type.TString>;
17
42
  }>;
18
- export type TaskManageAction = "create" | "set" | "done" | "list";
43
+ export type TaskManageAction = "create" | "progress" | "candidate" | "set" | "verify" | "done" | "cancel" | "start-cycle" | "list";
19
44
  export interface TaskManageResult {
20
45
  action: TaskManageAction;
21
46
  id?: string;
@@ -29,6 +54,7 @@ export interface TaskManageResult {
29
54
  status: string;
30
55
  wake?: string;
31
56
  actionable: boolean;
57
+ control?: TaskControl;
32
58
  }>;
33
59
  notice: string;
34
60
  }
@@ -42,15 +68,22 @@ export interface TaskManageRequest {
42
68
  status?: string;
43
69
  wake?: string;
44
70
  recurrence?: string;
71
+ note?: string;
72
+ verificationPlan?: string;
73
+ control?: TaskControlPatch;
74
+ verifierRunId?: string;
45
75
  summary?: string;
46
76
  evidence?: string;
47
77
  residualRisk?: string;
78
+ reason?: string;
79
+ cycleId?: string;
48
80
  }
49
81
  export interface TaskManageToolOptions {
50
82
  workspaceDir: string;
51
- workspacePath: string;
52
83
  channelDir: string;
53
84
  channelId: string;
85
+ /** Project checkout whose artifact state an independent verifier binds to. */
86
+ workingDirectory?: string;
54
87
  }
55
88
  export declare function manageTask(options: TaskManageToolOptions, request: TaskManageRequest): Promise<TaskManageResult>;
56
89
  export declare function createTaskManageTool(options: TaskManageToolOptions): AgentTool<typeof taskManageSchema>;