@oyasmi/pipiclaw 0.9.0-beta.7 → 0.9.0-beta.9

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 (77) hide show
  1. package/dist/agent/channel-runner.d.ts +1 -0
  2. package/dist/agent/channel-runner.js +21 -2
  3. package/dist/agent/index.d.ts +1 -1
  4. package/dist/agent/index.js +1 -1
  5. package/dist/agent/job-manager.d.ts +3 -3
  6. package/dist/agent/job-manager.js +0 -1
  7. package/dist/agent/runner-factory.d.ts +16 -4
  8. package/dist/agent/runner-factory.js +9 -23
  9. package/dist/agent/types.d.ts +9 -1
  10. package/dist/agent/types.js +3 -16
  11. package/dist/memory/review-log.js +0 -0
  12. package/dist/memory/scheduler.d.ts +1 -0
  13. package/dist/memory/scheduler.js +64 -6
  14. package/dist/playbooks/agent-delegation.md +2 -2
  15. package/dist/runtime/bootstrap.d.ts +10 -2
  16. package/dist/runtime/bootstrap.js +83 -55
  17. package/dist/runtime/channel-event.d.ts +41 -0
  18. package/dist/runtime/channel-event.js +1 -0
  19. package/dist/runtime/delivery.d.ts +3 -2
  20. package/dist/runtime/dingtalk.d.ts +9 -31
  21. package/dist/runtime/durable-dispatch.d.ts +4 -2
  22. package/dist/runtime/durable-dispatch.js +36 -25
  23. package/dist/runtime/events.d.ts +3 -2
  24. package/dist/runtime/events.js +2 -3
  25. package/dist/runtime/subagent-commands.js +48 -10
  26. package/dist/runtime/task-commands.js +2 -2
  27. package/dist/runtime/task-driver.d.ts +7 -7
  28. package/dist/runtime/task-driver.js +1 -4
  29. package/dist/runtime/task-migration.js +1 -1
  30. package/dist/runtime/task-wake.d.ts +4 -4
  31. package/dist/settings.d.ts +0 -106
  32. package/dist/settings.js +0 -224
  33. package/dist/shared/host-process.d.ts +25 -9
  34. package/dist/shared/host-process.js +59 -10
  35. package/dist/shared/types.d.ts +1 -0
  36. package/dist/shared/types.js +10 -1
  37. package/dist/subagents/discovery.d.ts +24 -0
  38. package/dist/subagents/discovery.js +103 -17
  39. package/dist/subagents/external/claude-code.js +10 -3
  40. package/dist/subagents/external/codex-cli.js +9 -3
  41. package/dist/subagents/external/exec.js +1 -0
  42. package/dist/subagents/external/harness.d.ts +22 -0
  43. package/dist/subagents/external/harness.js +22 -4
  44. package/dist/subagents/external/run.d.ts +23 -3
  45. package/dist/subagents/external/run.js +112 -131
  46. package/dist/subagents/external/settlement.d.ts +50 -0
  47. package/dist/subagents/external/settlement.js +123 -0
  48. package/dist/subagents/format.d.ts +4 -0
  49. package/dist/subagents/format.js +7 -0
  50. package/dist/subagents/runs.d.ts +73 -16
  51. package/dist/subagents/runs.js +197 -120
  52. package/dist/subagents/tool.d.ts +38 -6
  53. package/dist/subagents/tool.js +93 -61
  54. package/dist/subagents/verification-outcome.d.ts +26 -0
  55. package/dist/subagents/verification-outcome.js +16 -0
  56. package/dist/subagents/workspace-lease.d.ts +10 -1
  57. package/dist/subagents/workspace-lease.js +15 -2
  58. package/dist/tasks/ledger.js +1 -1
  59. package/dist/{shared → tasks}/task-schedule.js +1 -1
  60. package/dist/tools/bash.js +1 -1
  61. package/dist/tools/event-manage.js +1 -4
  62. package/dist/tools/grep.js +2 -3
  63. package/dist/tools/index.js +6 -0
  64. package/dist/tools/job.js +5 -5
  65. package/dist/tools/memory-manage.js +3 -6
  66. package/dist/tools/session-search.js +0 -1
  67. package/dist/tools/skill-manage.js +3 -3
  68. package/dist/tools/subagent-manage.d.ts +20 -6
  69. package/dist/tools/subagent-manage.js +88 -18
  70. package/dist/tools/task-manage/shared.js +2 -2
  71. package/dist/tools/task-manage.js +1 -4
  72. package/dist/tools/web-fetch.js +0 -1
  73. package/dist/tui/app.js +4 -4
  74. package/package.json +1 -1
  75. /package/dist/{shared → tasks}/task-events.d.ts +0 -0
  76. /package/dist/{shared → tasks}/task-events.js +0 -0
  77. /package/dist/{shared → tasks}/task-schedule.d.ts +0 -0
@@ -1,11 +1,12 @@
1
- import { join } from "node:path";
1
+ import { dirname, join } from "node:path";
2
2
  import { Type } from "typebox";
3
3
  import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
4
4
  import { RecoverableToolError } from "../shared/recoverable-error.js";
5
+ import { externalRoleFingerprint } from "../subagents/discovery.js";
5
6
  import { launchExternalRun } from "../subagents/external/run.js";
6
- import { elapsedMs, formatCost, formatDuration, harnessLabel } from "../subagents/format.js";
7
+ import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
7
8
  import { getSubAgentRunManager } from "../subagents/runs.js";
8
- import { buildVerificationProtocol } from "../subagents/tool.js";
9
+ import { assertVerifyAdmissible, buildContextualBlocks, buildSubAgentTask, } from "../subagents/tool.js";
9
10
  import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease, } from "../subagents/workspace-lease.js";
10
11
  const subagentManageSchema = Type.Object({
11
12
  label: Type.String({ description: "Brief description of what you're checking (shown to user)" }),
@@ -16,12 +17,14 @@ const subagentManageSchema = Type.Object({
16
17
  runId: Type.Optional(Type.String({ description: "Required for cancel and follow_up." })),
17
18
  task: Type.Optional(Type.String({ description: "Follow-up instruction. Required for op=follow_up." })),
18
19
  });
20
+ /** Spec 042 D9: cap on `op=list`'s output — see the call site for why running runs are exempt. */
21
+ const LIST_CAP = 50;
19
22
  function formatRunLine(record) {
20
23
  const task = record.taskId ? `, task ${record.taskId}` : "";
21
24
  const lease = record.leaseKey ? ", lease held" : "";
22
25
  const cost = formatCost(record);
23
26
  const costPart = cost ? `, ${cost}` : "";
24
- const header = `- [${record.runId}] ${record.agent} (${harnessLabel(record)}) — "${record.label}" — ${record.status} (${formatDuration(elapsedMs(record))}${task}${lease}${costPart})`;
27
+ const header = `- [${record.runId}] ${record.agent} (${harnessLabel(record)}) — "${record.label}" — ${record.status} (${formatRunDuration(record)}${task}${lease}${costPart})`;
25
28
  if (record.status === "failed" && record.failureReason) {
26
29
  return `${header}\n failed: ${record.failureReason}`;
27
30
  }
@@ -47,9 +50,25 @@ export function createSubAgentManageTool(options) {
47
50
  parameters: subagentManageSchema,
48
51
  execute: async (_toolCallId, { op, runId, task }) => {
49
52
  if (op === "list") {
50
- const runs = manager().list();
51
- const text = runs.length === 0 ? "No delegation runs." : runs.map(formatRunLine).join("\n");
52
- return { content: [{ type: "text", text }], details: { kind: "subagent_manage", op, runs } };
53
+ // Spec 042 D9: this used to return every run on the channel, unbounded, in both the
54
+ // text and `details.runs` — a long-lived channel could dump thousands of historical
55
+ // records into a single tool result. Running runs (the ones a decision might depend
56
+ // on) are never dropped; only the terminal tail is capped, newest first.
57
+ const allRuns = manager().list();
58
+ const running = allRuns.filter((record) => record.status === "running");
59
+ const terminal = allRuns
60
+ .filter((record) => record.status !== "running")
61
+ .sort((a, b) => (b.finishedAt ?? b.startedAt) - (a.finishedAt ?? a.startedAt));
62
+ const shownTerminal = terminal.slice(0, Math.max(0, LIST_CAP - running.length));
63
+ const runs = [...running, ...shownTerminal];
64
+ const lines = runs.length === 0 ? ["No delegation runs."] : runs.map(formatRunLine);
65
+ if (runs.length < allRuns.length) {
66
+ lines.push(`… showing ${runs.length} of ${allRuns.length} runs (all running + most recently finished). Ask about a specific runId if you need an older one not shown here.`);
67
+ }
68
+ return {
69
+ content: [{ type: "text", text: lines.join("\n") }],
70
+ details: { op, runs },
71
+ };
53
72
  }
54
73
  if (!runId) {
55
74
  throw new RecoverableToolError(`${op} requires runId.`);
@@ -66,7 +85,7 @@ export function createSubAgentManageTool(options) {
66
85
  const status = await manager().cancel(resolvedRunId);
67
86
  return {
68
87
  content: [{ type: "text", text: `Cancel requested for run ${resolvedRunId}: ${status}` }],
69
- details: { kind: "subagent_manage", op, runId: resolvedRunId, status },
88
+ details: { op, runId: resolvedRunId, status },
70
89
  };
71
90
  }
72
91
  // follow_up
@@ -106,6 +125,19 @@ export function createSubAgentManageTool(options) {
106
125
  if (role.shell) {
107
126
  throw new RecoverableToolError(`Role "${record.agent}" runs its command through a shell, which has no way to carry a resume session id. Delegate a new run instead, carrying forward whatever context it needs.`);
108
127
  }
128
+ // Spec 042 D7: verify admission is re-checked against the *current* role config, shared
129
+ // with the initial dispatch — a role hot-edited to mutates: write since the original run
130
+ // must not silently take the write lease and dispatch just because it once was read-only.
131
+ assertVerifyAdmissible(role, record.purpose, record.workingDirectory);
132
+ // Spec 042 D7: a role hot-edited since the original dispatch (different command, model,
133
+ // or shell mode) would resume the old session under a harness invocation it never wrote.
134
+ // Only enforced when the original run actually recorded a fingerprint — an older record
135
+ // predating this field cannot be checked, so it is let through rather than made
136
+ // permanently unresumable.
137
+ const currentFingerprint = externalRoleFingerprint(role);
138
+ if (record.roleFingerprint !== undefined && record.roleFingerprint !== currentFingerprint) {
139
+ throw new RecoverableToolError(`Role "${record.agent}" has changed (command, model, or shell mode) since run "${resolvedRunId}" was dispatched; resuming under the new config could reinterpret the old session incorrectly. Delegate a new run instead.`);
140
+ }
109
141
  // A short, human-typeable id (spec 041) — the follow-up gets a fresh identity, not the
110
142
  // dispatching tool call's own id.
111
143
  const newRunId = manager().mintRunId();
@@ -121,13 +153,42 @@ export function createSubAgentManageTool(options) {
121
153
  }
122
154
  leaseKey = lease.leaseKey;
123
155
  }
124
- // The initial dispatch envelopes verify runs with the protocol (tool.ts); a follow-up
125
- // on a verify run must carry the same protocol, not just the bare instruction (D9).
126
- const envelopedTask = record.purpose === "verify" && record.taskId
127
- ? `${task.trim()}\n\n${buildVerificationProtocol(join(options.workspaceDir ?? "", options.channelId, "tasks", `${record.taskId}.md`))}`
128
- : task;
156
+ // Spec 042 D7: the same `<subagent-artifacts>/<runId>` layout the initial dispatch uses,
157
+ // computed with a real path join rather than a regex substitution that assumed the old
158
+ // runId was the last path segment with no separators of its own.
159
+ const artifactDir = join(dirname(record.artifactDir), newRunId);
160
+ const runContext = {
161
+ runId: newRunId,
162
+ purpose: record.purpose,
163
+ taskId: record.taskId,
164
+ workingDirectory: record.workingDirectory,
165
+ artifactDir,
166
+ };
167
+ // Spec 042 D7: the same envelope construction the initial dispatch uses — runtime context
168
+ // (including this run's own artifact directory), paths/session/memory context blocks, and
169
+ // (for a verify run) the verification protocol — not a hand-rolled "task + maybe verify
170
+ // protocol" that left the external agent unaware of its own working/artifact directories.
171
+ // `getCurrentModel`/`resolveApiKey` are only needed for the `memory: relevant` recall path
172
+ // inside `buildContextualBlocks` — optional here so a caller that only ever exercises
173
+ // list/cancel is not forced to wire an LLM-backed dependency it will never use. Absent
174
+ // either, context blocks degrade to none rather than guessing at a model or key.
175
+ const contextualBlocks = options.getCurrentModel && options.resolveApiKey
176
+ ? await buildContextualBlocks(task, role, {
177
+ channelDir: options.channelDir,
178
+ workspaceDir: options.workspaceDir,
179
+ runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
180
+ getMemoryRecallSettings: options.getMemoryRecallSettings,
181
+ resolveApiKey: options.resolveApiKey,
182
+ memoryCandidateStore: options.memoryCandidateStore,
183
+ }, options.getCurrentModel())
184
+ : [];
185
+ const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext,
186
+ // returns: "artifact" has no external equivalent (spec 042 D3) and follow_up never
187
+ // requests it — always "text", matching the initial external dispatch.
188
+ "text");
189
+ let launchResult;
129
190
  try {
130
- await launchExternalRun({
191
+ launchResult = await launchExternalRun({
131
192
  runId: newRunId,
132
193
  channelId: options.channelId,
133
194
  channelDir: options.channelDir,
@@ -144,13 +205,14 @@ export function createSubAgentManageTool(options) {
144
205
  systemPrompt: role.systemPrompt,
145
206
  task: envelopedTask,
146
207
  workingDirectory: record.workingDirectory,
147
- artifactDir: record.artifactDir.replace(/[^/\\]+$/, newRunId),
208
+ artifactDir,
148
209
  purpose: record.purpose,
149
210
  taskId: record.taskId,
150
211
  leaseKey,
151
212
  resumeSessionId: record.sessionId,
152
213
  mutates: role.mutates,
153
- workspaceDir: options.workspaceDir ?? "",
214
+ roleFingerprint: currentFingerprint,
215
+ workspaceDir: options.workspaceDir,
154
216
  securityConfig: options.securityConfig ?? DEFAULT_SECURITY_CONFIG,
155
217
  });
156
218
  }
@@ -158,9 +220,17 @@ export function createSubAgentManageTool(options) {
158
220
  // Until launchExternalRun has durably registered the run, no settlement authority owns
159
221
  // this lease. Releasing here mirrors the initial subagent dispatch path and covers prompt,
160
222
  // artifact, audit, invocation, and pre-spawn failures in follow_up.
161
- releaseWorkspaceLease(leaseKey);
223
+ releaseWorkspaceLease(leaseKey, newRunId);
162
224
  throw error;
163
225
  }
226
+ // Spec 042 D2: a pre-spawn failure is reported in this same turn — settle() already
227
+ // released the lease, so there is nothing left to clean up here.
228
+ if (!launchResult.ok) {
229
+ if (launchResult.kind === "missing-binary") {
230
+ throw new Error(`Follow-up on run "${resolvedRunId}" failed to launch: ${launchResult.reason} Install the CLI or fix "command" in its role file; the follow-up was not dispatched.`);
231
+ }
232
+ throw new RecoverableToolError(`Follow-up on run "${resolvedRunId}" failed to launch: ${launchResult.reason} The follow-up was not dispatched.`);
233
+ }
164
234
  return {
165
235
  content: [
166
236
  {
@@ -168,7 +238,7 @@ export function createSubAgentManageTool(options) {
168
238
  text: `Follow-up dispatched as runId=${newRunId} (resuming ${resolvedRunId}). This channel will be woken when it finishes.`,
169
239
  },
170
240
  ],
171
- details: { kind: "subagent_manage", op, runId: newRunId, resumedFrom: resolvedRunId },
241
+ details: { op, runId: newRunId, resumedFrom: resolvedRunId },
172
242
  };
173
243
  },
174
244
  };
@@ -4,11 +4,11 @@ import { join } from "node:path";
4
4
  import * as log from "../../log.js";
5
5
  import { parseScheduledEventContent } from "../../runtime/events.js";
6
6
  import { formatLocalTime, parseWakeInput } from "../../shared/local-time.js";
7
- import { taskEventPrefix } from "../../shared/task-events.js";
8
- import { nextTaskWake, validateTaskSchedule } from "../../shared/task-schedule.js";
9
7
  import { errorMessage } from "../../shared/text-utils.js";
10
8
  import { applyTaskControlPatch, createDefaultTaskControl } from "../../tasks/control.js";
11
9
  import { normalizeTaskFields, parseTaskFrontmatter, renderStandardTaskBody, renderTaskDocument, taskBody, upsertCurrentCycleCompletionEvidence, } from "../../tasks/ledger.js";
10
+ import { taskEventPrefix } from "../../tasks/task-events.js";
11
+ import { nextTaskWake, validateTaskSchedule } from "../../tasks/task-schedule.js";
12
12
  import { isSettableTaskStatus } from "../../tasks/transitions.js";
13
13
  import { RecoverableToolError } from "../tool-details.js";
14
14
  import { SETTABLE_STATUSES } from "./schema.js";
@@ -58,10 +58,7 @@ export function createTaskManageTool(options) {
58
58
  });
59
59
  return {
60
60
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
61
- details: {
62
- kind: "task_manage",
63
- ...result,
64
- },
61
+ details: { ...result },
65
62
  };
66
63
  },
67
64
  };
@@ -40,7 +40,6 @@ function windowResult(body, offset, maxChars, url, fromCache) {
40
40
  return {
41
41
  content: [{ type: "text", text }],
42
42
  details: {
43
- kind: "web_fetch",
44
43
  url,
45
44
  offset: start,
46
45
  shownChars: slice.length,
package/dist/tui/app.js CHANGED
@@ -8,8 +8,7 @@
8
8
  */
9
9
  import { userInfo } from "node:os";
10
10
  import { renderBuiltInHelp } from "../agent/commands.js";
11
- import { getOrCreateRunner } from "../agent/index.js";
12
- import { resetRunner } from "../agent/runner-factory.js";
11
+ import { createRunner } from "../agent/index.js";
13
12
  import * as log from "../log.js";
14
13
  import { ensureChannelMemoryFilesSync } from "../memory/files.js";
15
14
  import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, printBootstrapSummary, readCliVersion, } from "../runtime/app-home.js";
@@ -78,10 +77,11 @@ export async function runTuiApp(options) {
78
77
  const channelDir = ensureChannelDir(paths.workspaceDir, channelId);
79
78
  ensureChannelMemoryFilesSync(channelDir);
80
79
  const store = new ChannelStore({ workingDir: paths.workspaceDir });
81
- const runner = getOrCreateRunner(channelId, channelDir, {
80
+ const runner = createRunner(channelId, channelDir, {
82
81
  appHomeDir: paths.appHomeDir,
83
82
  authConfigPath: paths.authConfigPath,
84
83
  modelsConfigPath: paths.modelsConfigPath,
84
+ settingsManager,
85
85
  mediaSender: createTerminalMediaSender(io),
86
86
  });
87
87
  const tuiSettings = settingsManager.getTuiSettings();
@@ -125,7 +125,7 @@ export async function runTuiApp(options) {
125
125
  }
126
126
  }
127
127
  finally {
128
- resetRunner(channelId);
128
+ await runner.dispose();
129
129
  await waitForStorageFlush(Promise.allSettled([store.close(), getUsageLedger().flush?.() ?? Promise.resolve(), flushSecurityLogs()]));
130
130
  await waitForStorageFlush(log.flushLogging());
131
131
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.9.0-beta.7",
3
+ "version": "0.9.0-beta.9",
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": {
File without changes
File without changes
File without changes