@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.
- package/dist/agent/channel-runner.d.ts +1 -0
- package/dist/agent/channel-runner.js +21 -2
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/job-manager.d.ts +3 -3
- package/dist/agent/job-manager.js +0 -1
- package/dist/agent/runner-factory.d.ts +16 -4
- package/dist/agent/runner-factory.js +9 -23
- package/dist/agent/types.d.ts +9 -1
- package/dist/agent/types.js +3 -16
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/scheduler.d.ts +1 -0
- package/dist/memory/scheduler.js +64 -6
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/bootstrap.d.ts +10 -2
- package/dist/runtime/bootstrap.js +83 -55
- package/dist/runtime/channel-event.d.ts +41 -0
- package/dist/runtime/channel-event.js +1 -0
- package/dist/runtime/delivery.d.ts +3 -2
- package/dist/runtime/dingtalk.d.ts +9 -31
- package/dist/runtime/durable-dispatch.d.ts +4 -2
- package/dist/runtime/durable-dispatch.js +36 -25
- package/dist/runtime/events.d.ts +3 -2
- package/dist/runtime/events.js +2 -3
- package/dist/runtime/subagent-commands.js +48 -10
- package/dist/runtime/task-commands.js +2 -2
- package/dist/runtime/task-driver.d.ts +7 -7
- package/dist/runtime/task-driver.js +1 -4
- package/dist/runtime/task-migration.js +1 -1
- package/dist/runtime/task-wake.d.ts +4 -4
- package/dist/settings.d.ts +0 -106
- package/dist/settings.js +0 -224
- package/dist/shared/host-process.d.ts +25 -9
- package/dist/shared/host-process.js +59 -10
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.js +10 -1
- package/dist/subagents/discovery.d.ts +24 -0
- package/dist/subagents/discovery.js +103 -17
- package/dist/subagents/external/claude-code.js +10 -3
- package/dist/subagents/external/codex-cli.js +9 -3
- package/dist/subagents/external/exec.js +1 -0
- package/dist/subagents/external/harness.d.ts +22 -0
- package/dist/subagents/external/harness.js +22 -4
- package/dist/subagents/external/run.d.ts +23 -3
- package/dist/subagents/external/run.js +112 -131
- package/dist/subagents/external/settlement.d.ts +50 -0
- package/dist/subagents/external/settlement.js +123 -0
- package/dist/subagents/format.d.ts +4 -0
- package/dist/subagents/format.js +7 -0
- package/dist/subagents/runs.d.ts +73 -16
- package/dist/subagents/runs.js +197 -120
- package/dist/subagents/tool.d.ts +38 -6
- package/dist/subagents/tool.js +93 -61
- package/dist/subagents/verification-outcome.d.ts +26 -0
- package/dist/subagents/verification-outcome.js +16 -0
- package/dist/subagents/workspace-lease.d.ts +10 -1
- package/dist/subagents/workspace-lease.js +15 -2
- package/dist/tasks/ledger.js +1 -1
- package/dist/{shared → tasks}/task-schedule.js +1 -1
- package/dist/tools/bash.js +1 -1
- package/dist/tools/event-manage.js +1 -4
- package/dist/tools/grep.js +2 -3
- package/dist/tools/index.js +6 -0
- package/dist/tools/job.js +5 -5
- package/dist/tools/memory-manage.js +3 -6
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-manage.js +3 -3
- package/dist/tools/subagent-manage.d.ts +20 -6
- package/dist/tools/subagent-manage.js +88 -18
- package/dist/tools/task-manage/shared.js +2 -2
- package/dist/tools/task-manage.js +1 -4
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tui/app.js +4 -4
- package/package.json +1 -1
- /package/dist/{shared → tasks}/task-events.d.ts +0 -0
- /package/dist/{shared → tasks}/task-events.js +0 -0
- /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 {
|
|
7
|
+
import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
|
|
7
8
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
8
|
-
import {
|
|
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} (${
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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: {
|
|
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
|
-
//
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
|
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
|
-
|
|
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: {
|
|
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";
|
package/dist/tools/web-fetch.js
CHANGED
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 {
|
|
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 =
|
|
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
|
-
|
|
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
|
File without changes
|
|
File without changes
|
|
File without changes
|