@oyasmi/pipiclaw 0.9.3-beta.5 → 0.9.3
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/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/agent/channel-runner.d.ts +4 -8
- package/dist/agent/channel-runner.js +14 -34
- package/dist/agent/job-manager.d.ts +12 -0
- package/dist/agent/job-manager.js +42 -1
- package/dist/agent/prompt/sections.js +2 -2
- package/dist/agent/runner-factory.d.ts +2 -2
- package/dist/agent/types.d.ts +11 -7
- package/dist/channel/channel-index.d.ts +9 -2
- package/dist/channel/channel-index.js +25 -6
- package/dist/channel/project-scope-store.d.ts +20 -0
- package/dist/channel/project-scope-store.js +22 -7
- package/dist/commands/catalog.js +6 -12
- package/dist/events/event-commands.js +2 -2
- package/dist/events/events.d.ts +51 -30
- package/dist/events/events.js +70 -98
- package/dist/memory/journal.d.ts +2 -3
- package/dist/memory/journal.js +2 -3
- package/dist/memory/maintenance-tuning.d.ts +0 -1
- package/dist/memory/maintenance-tuning.js +0 -1
- package/dist/memory/scheduler.js +8 -16
- package/dist/memory/search.js +2 -3
- package/dist/memory/session-search.js +3 -9
- package/dist/memory/store.d.ts +1 -1
- package/dist/memory/store.js +9 -1
- package/dist/memory/task-digest.js +10 -11
- package/dist/memory/tombstones.js +2 -4
- package/dist/models/provider-login.d.ts +1 -1
- package/dist/models/provider-login.js +1 -1
- package/dist/playbooks/agent-delegation.md +6 -6
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/event-scheduling.md +22 -13
- package/dist/playbooks/memory-and-learning.md +2 -2
- package/dist/playbooks/outbound-media.md +1 -1
- package/dist/playbooks/runtime-orientation.md +3 -3
- package/dist/playbooks/task-lead.md +82 -0
- package/dist/runtime/bootstrap.js +94 -187
- package/dist/runtime/durable-dispatch.js +30 -3
- package/dist/runtime/report-commands.d.ts +30 -0
- package/dist/runtime/report-commands.js +71 -0
- package/dist/runtime/subagent-commands.js +1 -1
- package/dist/runtime/task-commands.d.ts +0 -8
- package/dist/runtime/task-commands.js +48 -85
- package/dist/runtime/task-driver.d.ts +15 -10
- package/dist/runtime/task-driver.js +36 -41
- package/dist/runtime/task-migration.d.ts +23 -29
- package/dist/runtime/task-migration.js +364 -183
- package/dist/runtime/task-spawn.d.ts +24 -0
- package/dist/runtime/task-spawn.js +49 -0
- package/dist/runtime/task-wake.d.ts +33 -46
- package/dist/runtime/task-wake.js +15 -90
- package/dist/security/network.js +44 -9
- package/dist/settings.d.ts +1 -8
- package/dist/settings.js +1 -8
- package/dist/subagents/discovery.js +3 -15
- package/dist/subagents/external/run.d.ts +3 -1
- package/dist/subagents/external/run.js +2 -20
- package/dist/subagents/external/settlement.d.ts +4 -16
- package/dist/subagents/external/settlement.js +16 -67
- package/dist/subagents/runs.d.ts +15 -29
- package/dist/subagents/runs.js +70 -158
- package/dist/subagents/tool.d.ts +20 -4
- package/dist/subagents/tool.js +63 -87
- package/dist/subagents/verification-outcome.d.ts +13 -19
- package/dist/subagents/verification-outcome.js +8 -22
- package/dist/subagents/workspace-summary.d.ts +8 -0
- package/dist/subagents/workspace-summary.js +29 -0
- package/dist/tasks/board.d.ts +43 -0
- package/dist/tasks/board.js +134 -0
- package/dist/tasks/brief.d.ts +10 -5
- package/dist/tasks/brief.js +78 -26
- package/dist/tasks/budget.d.ts +13 -14
- package/dist/tasks/budget.js +21 -40
- package/dist/tasks/contract-input.d.ts +19 -0
- package/dist/tasks/contract-input.js +55 -0
- package/dist/tasks/create.d.ts +17 -0
- package/dist/tasks/create.js +36 -0
- package/dist/tasks/frontmatter.d.ts +20 -27
- package/dist/tasks/frontmatter.js +18 -31
- package/dist/tasks/ledger.d.ts +61 -117
- package/dist/tasks/ledger.js +78 -223
- package/dist/tasks/log.d.ts +62 -35
- package/dist/tasks/log.js +51 -29
- package/dist/tasks/session-path.d.ts +3 -3
- package/dist/tasks/session-path.js +4 -5
- package/dist/tasks/store.d.ts +27 -28
- package/dist/tasks/store.js +89 -83
- package/dist/tasks/ticket.d.ts +33 -66
- package/dist/tasks/ticket.js +31 -120
- package/dist/tasks/work-log.d.ts +20 -0
- package/dist/tasks/work-log.js +42 -0
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +1 -1
- package/dist/tools/event-manage.d.ts +16 -2
- package/dist/tools/event-manage.js +30 -12
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +5 -5
- package/dist/tools/registry.d.ts +6 -4
- package/dist/tools/registry.js +1 -4
- package/dist/tools/subagent-manage.js +4 -2
- package/dist/tools/task-manage/create.js +11 -27
- package/dist/tools/task-manage/lifecycle.d.ts +6 -7
- package/dist/tools/task-manage/lifecycle.js +23 -106
- package/dist/tools/task-manage/log-view.d.ts +3 -2
- package/dist/tools/task-manage/log-view.js +6 -6
- package/dist/tools/task-manage/schema.d.ts +10 -30
- package/dist/tools/task-manage/schema.js +33 -49
- package/dist/tools/task-manage/shared.d.ts +35 -42
- package/dist/tools/task-manage/shared.js +53 -192
- package/dist/tools/task-manage/step-end.d.ts +6 -6
- package/dist/tools/task-manage/step-end.js +61 -98
- package/dist/tools/task-manage/types.d.ts +8 -9
- package/dist/tools/task-manage.js +5 -5
- package/dist/tui/app.js +11 -38
- package/dist/tui/commands.d.ts +18 -8
- package/dist/tui/commands.js +2 -9
- package/dist/tui/turn-controller.d.ts +2 -14
- package/dist/tui/turn-controller.js +1 -17
- package/dist/web/client.js +9 -1
- package/examples/sub-agents/README.md +7 -4
- package/examples/sub-agents/agents/codex-flash.md +2 -2
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +1 -1
- package/examples/sub-agents/agents/codex-review.md +23 -0
- package/examples/sub-agents/roles/verifier.md +1 -1
- package/package.json +1 -1
- package/dist/memory/maintenance-migration.d.ts +0 -5
- package/dist/memory/maintenance-migration.js +0 -91
- package/dist/memory/migrate.d.ts +0 -15
- package/dist/memory/migrate.js +0 -364
- package/dist/playbooks/task-loop.md +0 -90
- package/dist/tasks/artifact-subject.d.ts +0 -40
- package/dist/tasks/artifact-subject.js +0 -334
- package/dist/tasks/cycle.d.ts +0 -48
- package/dist/tasks/cycle.js +0 -94
- package/dist/tasks/rounds.d.ts +0 -41
- package/dist/tasks/rounds.js +0 -53
- package/dist/tasks/task-events.d.ts +0 -6
- package/dist/tasks/task-events.js +0 -14
- package/dist/tasks/task-schedule.d.ts +0 -18
- package/dist/tasks/task-schedule.js +0 -50
- package/dist/tasks/verification.d.ts +0 -114
- package/dist/tasks/verification.js +0 -226
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { SpawnTaskRequest, SpawnTaskResult } from "../events/events.js";
|
|
2
|
+
export interface TaskSpawnerOptions {
|
|
3
|
+
/** The channel's directory under the workspace. */
|
|
4
|
+
getChannelDir: (channelId: string) => string;
|
|
5
|
+
/** Wake the driver so the new instance's first step is queued promptly. */
|
|
6
|
+
nudge: () => void;
|
|
7
|
+
/** Direct, non-LLM message to the channel — used for the "previous instance still running" receipt. */
|
|
8
|
+
notify: (channelId: string, text: string) => Promise<unknown>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create the task instance a template event asks for (spec 052, D2).
|
|
12
|
+
*
|
|
13
|
+
* The instance id is `<event>-<YYYYMMDD>-<HHmm>` of the occurrence, so it is a pure function of
|
|
14
|
+
* *which occurrence this is*: a replay after a crash lands on the same id and is recognized as
|
|
15
|
+
* already spawned. That check comes first — otherwise the replay would find the instance it just
|
|
16
|
+
* made and misreport it as a still-running predecessor.
|
|
17
|
+
*
|
|
18
|
+
* A second instance of the same event never runs alongside the first: two copies of the same
|
|
19
|
+
* recurring job mostly duplicate work or collide. The occurrence is skipped and the user is told
|
|
20
|
+
* every time (INV-7) — a stuck instance is something they need to know about, not something to
|
|
21
|
+
* hide behind a quiet skip. The stuck instance itself is bounded by its budget, idle detection and
|
|
22
|
+
* ticket backstops, so the skipping cannot go on forever.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createTaskSpawner(options: TaskSpawnerOptions): (request: SpawnTaskRequest) => Promise<SpawnTaskResult>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import * as log from "../log.js";
|
|
3
|
+
import { createTaskDocument, instanceStamp } from "../tasks/create.js";
|
|
4
|
+
import { readActiveTasks } from "../tasks/ledger.js";
|
|
5
|
+
import { archivedTaskPath, taskPath, tasksDir } from "../tasks/store.js";
|
|
6
|
+
const STATE_LABEL = { open: "进行中", parked: "等待中" };
|
|
7
|
+
/**
|
|
8
|
+
* Create the task instance a template event asks for (spec 052, D2).
|
|
9
|
+
*
|
|
10
|
+
* The instance id is `<event>-<YYYYMMDD>-<HHmm>` of the occurrence, so it is a pure function of
|
|
11
|
+
* *which occurrence this is*: a replay after a crash lands on the same id and is recognized as
|
|
12
|
+
* already spawned. That check comes first — otherwise the replay would find the instance it just
|
|
13
|
+
* made and misreport it as a still-running predecessor.
|
|
14
|
+
*
|
|
15
|
+
* A second instance of the same event never runs alongside the first: two copies of the same
|
|
16
|
+
* recurring job mostly duplicate work or collide. The occurrence is skipped and the user is told
|
|
17
|
+
* every time (INV-7) — a stuck instance is something they need to know about, not something to
|
|
18
|
+
* hide behind a quiet skip. The stuck instance itself is bounded by its budget, idle detection and
|
|
19
|
+
* ticket backstops, so the skipping cannot go on forever.
|
|
20
|
+
*/
|
|
21
|
+
export function createTaskSpawner(options) {
|
|
22
|
+
return async (request) => {
|
|
23
|
+
const channelDir = options.getChannelDir(request.channelId);
|
|
24
|
+
const id = `${request.eventName}-${instanceStamp(request.occurrence)}`;
|
|
25
|
+
if (existsSync(taskPath(channelDir, id)) || existsSync(archivedTaskPath(channelDir, id))) {
|
|
26
|
+
return { outcome: "exists", id };
|
|
27
|
+
}
|
|
28
|
+
const active = (await readActiveTasks(tasksDir(channelDir))).find((entry) => entry.fields.origin === request.eventName && !entry.fields.outcome);
|
|
29
|
+
if (active) {
|
|
30
|
+
const state = STATE_LABEL[active.fields.state] ?? active.fields.state;
|
|
31
|
+
await options
|
|
32
|
+
.notify(request.channelId, `周期任务 ${request.eventName} 本次(${instanceStamp(request.occurrence)})未启动:上一实例 ${active.id} 仍在进行(${state}${active.fields.paused ? ",已暂停" : ""})。\n查看:/tasks show ${active.id}`)
|
|
33
|
+
.catch((error) => {
|
|
34
|
+
log.logWarning(`Could not deliver skip receipt for ${request.eventName}`, String(error));
|
|
35
|
+
});
|
|
36
|
+
return { outcome: "skipped", id: active.id };
|
|
37
|
+
}
|
|
38
|
+
await createTaskDocument({
|
|
39
|
+
channelDir,
|
|
40
|
+
id,
|
|
41
|
+
input: request.template,
|
|
42
|
+
origin: request.eventName,
|
|
43
|
+
now: request.occurrence,
|
|
44
|
+
});
|
|
45
|
+
log.logInfo(`[${request.channelId}] Event ${request.eventName} spawned task ${id}`);
|
|
46
|
+
options.nudge();
|
|
47
|
+
return { outcome: "spawned", id };
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,59 +1,46 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
2
|
+
* Claiming a background job's or delegation run's completion wake before it may reopen a parked
|
|
3
|
+
* task (spec 040, D7/T9). Pure functions over an explicit `event`/`workspaceDir`/owner, with no
|
|
4
|
+
* dependency on `createRuntimeContext`'s closures.
|
|
5
|
+
*
|
|
6
|
+
* Trust comes from two things only: the producer-created `internalWake` envelope (DingTalk
|
|
7
|
+
* inbound parsing never populates it, so user text or an external agent's stdout cannot forge
|
|
8
|
+
* one), and the owner's `beginWakeConsumption`, which re-checks that the resource exists, has
|
|
9
|
+
* settled, names this task, and that the dispatch id is exactly the one its own completion wake
|
|
10
|
+
* carries.
|
|
6
11
|
*/
|
|
7
|
-
import type { ChannelJobManager, JobSnapshot } from "../agent/job-manager.js";
|
|
8
12
|
import type { ChannelEvent } from "../channel/channel-event.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* accepting it anyway would let a message merely mentioning a live job's id activate a task
|
|
14
|
-
* early), and really is the one whose own contract names `taskId` (spec 040, T9). The text itself
|
|
15
|
-
* is never sufficient — it can be typed by any user, or echoed back by an external agent's own
|
|
16
|
-
* untrusted stdout.
|
|
17
|
-
*/
|
|
18
|
-
export declare function isVerifiedJobWake(jobs: JobSnapshot[], jobId: string, taskId: string): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
21
|
-
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
22
|
-
* because it is published with the terminal record before usage/archive/wake side effects — the
|
|
23
|
-
* same idempotency guard the manager itself relies on. A pending settlement intent leaves it unset.
|
|
24
|
-
*/
|
|
25
|
-
export declare function isVerifiedDelegationWake(record: RunRecord | undefined, taskId: string): boolean;
|
|
26
|
-
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
27
|
-
* and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
|
|
28
|
-
* not populate `internalWake`, so copying a real wake's text is insufficient. */
|
|
29
|
-
export declare function isTrustedInternalWake(event: ChannelEvent, kind: "job" | "subagent", resourceId: string, taskId: string): event is ChannelEvent & {
|
|
30
|
-
dispatchId: string;
|
|
31
|
-
};
|
|
32
|
-
export interface ClaimedDelegationWake {
|
|
33
|
-
taskId: string;
|
|
34
|
-
activated: boolean;
|
|
35
|
-
/** True when it is safe to drop this wake without a turn even though it did not redeem a
|
|
36
|
-
* ticket itself — see `isTaskActivelyDriven`. Always true when `activated` is true. */
|
|
37
|
-
taskStillDriven: boolean;
|
|
38
|
-
finish(): Promise<void>;
|
|
39
|
-
rollback(): Promise<void>;
|
|
13
|
+
/** The slice of `ChannelJobManager` / `SubAgentRunManager` a wake claim needs. */
|
|
14
|
+
export interface WakeOwner {
|
|
15
|
+
beginWakeConsumption(id: string, taskId: string, dispatchId: string): Promise<boolean>;
|
|
16
|
+
finishWakeConsumption(id: string, dispatchId: string): Promise<void>;
|
|
40
17
|
}
|
|
41
18
|
/** Test-only fault seam, kept for the restart/interrupt cases that exercise a failed write. */
|
|
42
19
|
export interface WakeTaskTransitionHooks {
|
|
43
20
|
beforeActivation?: () => void;
|
|
44
21
|
}
|
|
45
|
-
|
|
46
|
-
* final marker separate lets transports such as TUI mark it consumed only after they have accepted
|
|
47
|
-
* the corresponding turn; a rejected submit remains replayable in the same or next process. */
|
|
48
|
-
export declare function claimVerifiedDelegationWake(event: ChannelEvent, workspaceDir: string, runManager: SubAgentRunManager, hooks?: WakeTaskTransitionHooks): Promise<ClaimedDelegationWake | undefined>;
|
|
49
|
-
export interface ClaimedJobWake {
|
|
22
|
+
export interface ClaimedWake {
|
|
50
23
|
taskId: string;
|
|
24
|
+
/** True when this wake redeemed the task's `work` ticket. */
|
|
51
25
|
activated: boolean;
|
|
52
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* True when it is safe to drop this wake without a turn even though it did not redeem a ticket
|
|
28
|
+
* itself: the task is already `open` and not paused, so some other wake in the same fan-out
|
|
29
|
+
* reopened it and the driver will pick up the result. Every other case — done, archived,
|
|
30
|
+
* paused, or the task missing — has nobody left to look at the result if it is dropped, so the
|
|
31
|
+
* caller must still route it to a normal turn. Always true when `activated` is true.
|
|
32
|
+
*/
|
|
53
33
|
taskStillDriven: boolean;
|
|
34
|
+
/** Mark the wake consumed. Kept separate so the caller finalizes only after it accepted the turn. */
|
|
54
35
|
finish(): Promise<void>;
|
|
55
36
|
}
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Claim a producer-created completion wake and redeem the task's ticket for it. Returns
|
|
39
|
+
* `undefined` for an event with no (or an unverifiable) `internalWake`.
|
|
40
|
+
*
|
|
41
|
+
* Only a `work` ticket may be redeemed by a settling run or job (any bound run or job settling
|
|
42
|
+
* wakes the leader, spec 052, D3): a task parked on a clock or a question to the user is not
|
|
43
|
+
* waiting for it, and reopening it here would be exactly the unverified resumption path spec 051
|
|
44
|
+
* exists to remove.
|
|
45
|
+
*/
|
|
46
|
+
export declare function claimVerifiedWake(event: ChannelEvent, workspaceDir: string, owner: WakeOwner, hooks?: WakeTaskTransitionHooks): Promise<ClaimedWake | undefined>;
|
|
@@ -1,107 +1,32 @@
|
|
|
1
1
|
import { getChannelDir } from "../channel/channel-paths.js";
|
|
2
|
-
import {
|
|
3
|
-
/**
|
|
4
|
-
* True when `taskId` is already `open` and not paused — i.e. the driver already owns advancing
|
|
5
|
-
* it. A completion wake that could not redeem a ticket (because the task was not parked on one)
|
|
6
|
-
* is safe to drop without spending an agent turn only in this case: some other wake in the same
|
|
7
|
-
* fan-out already reopened it, and the driver will pick up the result. Every other case — done,
|
|
8
|
-
* archived, paused, or the task missing entirely — has nobody left to look at the wake's result
|
|
9
|
-
* if it is dropped here, so the caller must still route it to a normal turn.
|
|
10
|
-
*/
|
|
2
|
+
import { readStoredTask, redeemTicket } from "../tasks/store.js";
|
|
11
3
|
async function isTaskActivelyDriven(channelDir, taskId) {
|
|
12
4
|
const document = await readStoredTask(channelDir, taskId).catch(() => undefined);
|
|
13
5
|
return document !== undefined && document.fields.state === "open" && !document.fields.paused;
|
|
14
6
|
}
|
|
15
7
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
export function isVerifiedJobWake(jobs, jobId, taskId) {
|
|
24
|
-
const job = jobs.find((candidate) => candidate.id === jobId);
|
|
25
|
-
return job !== undefined && job.status !== "running" && job.taskId === taskId;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
29
|
-
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
30
|
-
* because it is published with the terminal record before usage/archive/wake side effects — the
|
|
31
|
-
* same idempotency guard the manager itself relies on. A pending settlement intent leaves it unset.
|
|
8
|
+
* Claim a producer-created completion wake and redeem the task's ticket for it. Returns
|
|
9
|
+
* `undefined` for an event with no (or an unverifiable) `internalWake`.
|
|
10
|
+
*
|
|
11
|
+
* Only a `work` ticket may be redeemed by a settling run or job (any bound run or job settling
|
|
12
|
+
* wakes the leader, spec 052, D3): a task parked on a clock or a question to the user is not
|
|
13
|
+
* waiting for it, and reopening it here would be exactly the unverified resumption path spec 051
|
|
14
|
+
* exists to remove.
|
|
32
15
|
*/
|
|
33
|
-
export function
|
|
34
|
-
return record !== undefined && record.settledAt !== undefined && record.taskId === taskId;
|
|
35
|
-
}
|
|
36
|
-
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
37
|
-
* and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
|
|
38
|
-
* not populate `internalWake`, so copying a real wake's text is insufficient. */
|
|
39
|
-
export function isTrustedInternalWake(event, kind, resourceId, taskId) {
|
|
40
|
-
const wake = event.internalWake;
|
|
41
|
-
return (wake?.kind === kind &&
|
|
42
|
-
wake.resourceId === resourceId &&
|
|
43
|
-
wake.taskId === taskId &&
|
|
44
|
-
typeof event.dispatchId === "string" &&
|
|
45
|
-
wake.dispatchId === event.dispatchId);
|
|
46
|
-
}
|
|
47
|
-
/** Claim and activate a producer-created delegation wake without consuming it yet. Keeping the
|
|
48
|
-
* final marker separate lets transports such as TUI mark it consumed only after they have accepted
|
|
49
|
-
* the corresponding turn; a rejected submit remains replayable in the same or next process. */
|
|
50
|
-
export async function claimVerifiedDelegationWake(event, workspaceDir, runManager, hooks) {
|
|
51
|
-
const wake = event.internalWake;
|
|
52
|
-
if (wake?.kind !== "subagent")
|
|
53
|
-
return undefined;
|
|
54
|
-
const record = runManager.get(wake.resourceId);
|
|
55
|
-
if (!isTrustedInternalWake(event, "subagent", wake.resourceId, wake.taskId) ||
|
|
56
|
-
!isVerifiedDelegationWake(record, wake.taskId) ||
|
|
57
|
-
!(await runManager.beginWakeConsumption(wake.resourceId, wake.taskId, event.dispatchId))) {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
61
|
-
hooks?.beforeActivation?.();
|
|
62
|
-
// Only a `run` ticket naming this very run may be redeemed: a task parked on something else
|
|
63
|
-
// (a job, a question to the user) is not waiting for this delegation, and reopening it here
|
|
64
|
-
// would be exactly the unverified resumption path spec 051 D2 exists to remove.
|
|
65
|
-
const redeemed = await redeemTicket(channelDir, wake.taskId, (ticket) => ticket.kind === "run" && ticket.id === wake.resourceId);
|
|
66
|
-
const taskStillDriven = redeemed !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId));
|
|
67
|
-
return {
|
|
68
|
-
taskId: wake.taskId,
|
|
69
|
-
activated: redeemed !== undefined,
|
|
70
|
-
taskStillDriven,
|
|
71
|
-
finish: async () => {
|
|
72
|
-
await runManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
73
|
-
},
|
|
74
|
-
// Re-park on the same ticket when the transport could not accept the turn, so a rejected
|
|
75
|
-
// submit leaves the task exactly as it was rather than silently `open` with no step queued.
|
|
76
|
-
rollback: async () => {
|
|
77
|
-
if (redeemed)
|
|
78
|
-
await parkTask(channelDir, wake.taskId, redeemed.ticket);
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
83
|
-
* <taskId>.` completion wake. A background job has no rollback bookkeeping — its wake
|
|
84
|
-
* activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
|
|
85
|
-
export async function claimVerifiedJobWake(event, workspaceDir, jobManager, hooks) {
|
|
16
|
+
export async function claimVerifiedWake(event, workspaceDir, owner, hooks) {
|
|
86
17
|
const wake = event.internalWake;
|
|
87
|
-
if (wake
|
|
18
|
+
if (!wake || typeof event.dispatchId !== "string")
|
|
88
19
|
return undefined;
|
|
89
|
-
|
|
90
|
-
if (!isTrustedInternalWake(event, "job", wake.resourceId, wake.taskId) ||
|
|
91
|
-
!isVerifiedJobWake(jobs, wake.resourceId, wake.taskId) ||
|
|
92
|
-
!(await jobManager.beginWakeConsumption(wake.resourceId, wake.taskId, event.dispatchId))) {
|
|
20
|
+
if (!(await owner.beginWakeConsumption(wake.resourceId, wake.taskId, event.dispatchId)))
|
|
93
21
|
return undefined;
|
|
94
|
-
|
|
22
|
+
const dispatchId = event.dispatchId;
|
|
95
23
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
96
24
|
hooks?.beforeActivation?.();
|
|
97
|
-
const redeemed = await redeemTicket(channelDir, wake.taskId, (ticket) => ticket.kind === "
|
|
98
|
-
const taskStillDriven = redeemed !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId));
|
|
25
|
+
const redeemed = await redeemTicket(channelDir, wake.taskId, (ticket) => ticket.kind === "work");
|
|
99
26
|
return {
|
|
100
27
|
taskId: wake.taskId,
|
|
101
28
|
activated: redeemed !== undefined,
|
|
102
|
-
taskStillDriven,
|
|
103
|
-
finish:
|
|
104
|
-
await jobManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
105
|
-
},
|
|
29
|
+
taskStillDriven: redeemed !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId)),
|
|
30
|
+
finish: () => owner.finishWakeConsumption(wake.resourceId, dispatchId),
|
|
106
31
|
};
|
|
107
32
|
}
|
package/dist/security/network.js
CHANGED
|
@@ -129,22 +129,57 @@ function matchesAllowedHost(hostname, allowedHosts) {
|
|
|
129
129
|
const normalized = normalizeHost(hostname);
|
|
130
130
|
return allowedHosts.some((candidate) => normalizeHost(candidate) === normalized);
|
|
131
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* An IPv4-mapped IPv6 address (`::ffff:a.b.c.d`, the `::ffff:0:0/96` range) is the same host as
|
|
134
|
+
* the embedded IPv4 address — a dual-stack socket connecting to `::ffff:127.0.0.1` reaches
|
|
135
|
+
* loopback exactly as `127.0.0.1` would. `isPrivateAddress`/`matchesAllowedCidr` used to check
|
|
136
|
+
* such an address only against the IPv6 private ranges, which do not cover this mapped range, so
|
|
137
|
+
* a mapped private/loopback address (R4) sailed through as "not private". Returns the dotted-quad
|
|
138
|
+
* form when `address` is a mapped IPv4 address, else `null`.
|
|
139
|
+
*/
|
|
140
|
+
function ipv4MappedEmbeddedAddress(address) {
|
|
141
|
+
if (isIP(address) !== 6) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const value = parseIpv6(address);
|
|
145
|
+
if (value === null) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
if (value >> 32n !== 0xffffn) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
const low32 = value & 0xffffffffn;
|
|
152
|
+
return [24n, 16n, 8n, 0n].map((shift) => Number((low32 >> shift) & 0xffn)).join(".");
|
|
153
|
+
}
|
|
154
|
+
/** Every address form a guard check must consider for `address`: itself, plus (when it is an
|
|
155
|
+
* IPv4-mapped IPv6 address) the IPv4 address it actually maps to. */
|
|
156
|
+
function expandForGuardCheck(address) {
|
|
157
|
+
const version = isIP(address);
|
|
158
|
+
if (version === 4) {
|
|
159
|
+
return [{ address, version: 4 }];
|
|
160
|
+
}
|
|
161
|
+
if (version === 6) {
|
|
162
|
+
const mapped = ipv4MappedEmbeddedAddress(address);
|
|
163
|
+
return mapped
|
|
164
|
+
? [
|
|
165
|
+
{ address, version: 6 },
|
|
166
|
+
{ address: mapped, version: 4 },
|
|
167
|
+
]
|
|
168
|
+
: [{ address, version: 6 }];
|
|
169
|
+
}
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
132
172
|
function matchesAllowedCidr(address, allowedCidrs) {
|
|
133
|
-
return allowedCidrs.some((cidr) => ipInCidr(
|
|
173
|
+
return expandForGuardCheck(address).some(({ address: candidate }) => allowedCidrs.some((cidr) => ipInCidr(candidate, cidr.trim())));
|
|
134
174
|
}
|
|
135
175
|
function isBlockedHost(hostname) {
|
|
136
176
|
const normalized = normalizeHost(hostname);
|
|
137
177
|
return normalized.endsWith(".localhost") || BLOCKED_HOSTS.has(normalized);
|
|
138
178
|
}
|
|
139
179
|
function isPrivateAddress(address) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
if (version === 6) {
|
|
145
|
-
return PRIVATE_IPV6_CIDRS.some((cidr) => ipInCidr(address, cidr));
|
|
146
|
-
}
|
|
147
|
-
return false;
|
|
180
|
+
return expandForGuardCheck(address).some(({ address: candidate, version }) => version === 4
|
|
181
|
+
? PRIVATE_IPV4_CIDRS.some((cidr) => ipInCidr(candidate, cidr))
|
|
182
|
+
: PRIVATE_IPV6_CIDRS.some((cidr) => ipInCidr(candidate, cidr)));
|
|
148
183
|
}
|
|
149
184
|
async function validateUrlTarget(rawUrl, context, stage) {
|
|
150
185
|
const url = (() => {
|
package/dist/settings.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings management for pipiclaw.
|
|
3
|
-
*
|
|
4
|
-
* `log.jsonl` and `context.jsonl` are treated as raw cold storage.
|
|
5
|
-
* They are not proactively scanned or loaded as part of the memory model.
|
|
6
|
-
*
|
|
7
|
-
* This module currently provides only PipiclawSettingsManager.
|
|
8
|
-
*/
|
|
1
|
+
/** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
|
|
9
2
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
10
3
|
import { type MemoryMaintenanceTuning } from "./memory/maintenance-tuning.js";
|
|
11
4
|
import type { ResponseMode } from "./runtime/dingtalk.js";
|
package/dist/settings.js
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settings management for pipiclaw.
|
|
3
|
-
*
|
|
4
|
-
* `log.jsonl` and `context.jsonl` are treated as raw cold storage.
|
|
5
|
-
* They are not proactively scanned or loaded as part of the memory model.
|
|
6
|
-
*
|
|
7
|
-
* This module currently provides only PipiclawSettingsManager.
|
|
8
|
-
*/
|
|
1
|
+
/** Settings management for pipiclaw: `settings.json` (product intent only) and the code constants that replaced the retired knobs. */
|
|
9
2
|
import { existsSync, mkdirSync, readFileSync } from "fs";
|
|
10
3
|
import { dirname, join } from "path";
|
|
11
4
|
import * as log from "./log.js";
|
|
@@ -22,8 +22,6 @@ const MAX_SUB_AGENT_TASK_CHARS = 12000;
|
|
|
22
22
|
const MAX_SUB_AGENT_SYSTEM_PROMPT_CHARS = 16000;
|
|
23
23
|
const ALLOWED_CONTEXT_MODES = ["isolated", "contextual"];
|
|
24
24
|
const ALLOWED_MEMORY_MODES = ["none", "index"];
|
|
25
|
-
/** Spec 050, D12: `session`/`relevant` are retired — both collapse to `index`. */
|
|
26
|
-
const LEGACY_MEMORY_MODE_ALIASES = { session: "index", relevant: "index" };
|
|
27
25
|
// "max" is a real SDK ThinkingLevel; pipiclaw's own whitelist previously omitted it (spec 040, D4).
|
|
28
26
|
const ALLOWED_THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
29
27
|
const ALLOWED_RUNTIMES = ["internal", "external"];
|
|
@@ -195,8 +193,7 @@ function parseContextChoice(raw) {
|
|
|
195
193
|
}
|
|
196
194
|
/**
|
|
197
195
|
* `defaultValue` is computed per call site rather than derived from `contextMode` inside this
|
|
198
|
-
* function (spec 042 D4): internal keeps following `contextMode` (`contextual` → `
|
|
199
|
-
* but an external role's default is always `none` regardless of `contextMode` — a role that
|
|
196
|
+
* function (spec 042 D4): internal keeps following `contextMode` (`contextual` → `index`), but an external role's default is always `none` regardless of `contextMode` — a role that
|
|
200
197
|
* merely wants `paths` injected (via `contextMode: contextual`) should not also silently start
|
|
201
198
|
* sending session/memory content to a third-party process.
|
|
202
199
|
*/
|
|
@@ -208,13 +205,6 @@ function parseMemoryMode(raw, defaultValue) {
|
|
|
208
205
|
if (ALLOWED_MEMORY_MODES.includes(normalized)) {
|
|
209
206
|
return { value: normalized };
|
|
210
207
|
}
|
|
211
|
-
// Frontmatter lives in the user's workspace, not under this codebase's control, so a role
|
|
212
|
-
// written against the retired `session`/`relevant` values keeps loading — with a warning —
|
|
213
|
-
// instead of being dropped (spec 050, D12).
|
|
214
|
-
const legacy = LEGACY_MEMORY_MODE_ALIASES[normalized];
|
|
215
|
-
if (legacy) {
|
|
216
|
-
return { value: legacy, warning: `memory: "${normalized}" is retired; treating it as "${legacy}"` };
|
|
217
|
-
}
|
|
218
208
|
return {
|
|
219
209
|
value: defaultValue,
|
|
220
210
|
error: `Unknown memory "${normalized}". Allowed values: ${ALLOWED_MEMORY_MODES.join(", ")}`,
|
|
@@ -404,9 +394,7 @@ function parseInternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
404
394
|
const bashWithoutMutatesWarning = toolParse.tools.includes("bash") && mutates.value === undefined
|
|
405
395
|
? 'tools include bash but "mutates" is not declared; if this role writes to the workspace, declare mutates: write so it participates in the workspace write lease'
|
|
406
396
|
: undefined;
|
|
407
|
-
const combinedWarningBody = [numericWarning,
|
|
408
|
-
.filter(Boolean)
|
|
409
|
-
.join("; ");
|
|
397
|
+
const combinedWarningBody = [numericWarning, bashWithoutMutatesWarning].filter(Boolean).join("; ");
|
|
410
398
|
return {
|
|
411
399
|
warning: combinedWarningBody ? `${entryName}: ${combinedWarningBody}` : undefined,
|
|
412
400
|
agent: {
|
|
@@ -511,7 +499,7 @@ function parseExternalAgent(entryName, filePath, frontmatter, body, name, descri
|
|
|
511
499
|
: undefined;
|
|
512
500
|
// All non-fatal (the role still loads); joined rather than picking one so an unlucky
|
|
513
501
|
// combination never silently loses one of them.
|
|
514
|
-
const combinedWarning = [
|
|
502
|
+
const combinedWarning = [memoryDisclosureWarning, modelPlaceholderWarning].filter(Boolean).join("; ") || undefined;
|
|
515
503
|
return {
|
|
516
504
|
warning: combinedWarning,
|
|
517
505
|
agent: {
|
|
@@ -18,7 +18,7 @@ export interface LaunchExternalRunInput {
|
|
|
18
18
|
runManager: SubAgentRunManager;
|
|
19
19
|
runId: string;
|
|
20
20
|
channelId: string;
|
|
21
|
-
/**
|
|
21
|
+
/** Where a task-bound run logs its dispatch and settlement (spec 052, D4). */
|
|
22
22
|
channelDir?: string;
|
|
23
23
|
label: string;
|
|
24
24
|
agent: string;
|
|
@@ -38,6 +38,8 @@ export interface LaunchExternalRunInput {
|
|
|
38
38
|
artifactDir: string;
|
|
39
39
|
purpose: "work" | "verify";
|
|
40
40
|
taskId?: string;
|
|
41
|
+
/** The Work Items id this run was dispatched for (spec 052, D4). */
|
|
42
|
+
item?: string;
|
|
41
43
|
leaseKey?: string;
|
|
42
44
|
resumeSessionId?: string;
|
|
43
45
|
/** The role's own `mutates` declaration, carried through to the dispatch audit event (D8.1). */
|
|
@@ -8,7 +8,6 @@ import { killProcessGroup, probeCliVersion, readProcessStartTime, reapProcessGro
|
|
|
8
8
|
import { splitShellWords } from "../../shared/shell-words.js";
|
|
9
9
|
import { errorMessage } from "../../shared/text-utils.js";
|
|
10
10
|
import { createEmptyUsageTotals } from "../../shared/types.js";
|
|
11
|
-
import { workspaceSubjectSnapshot } from "../../tasks/artifact-subject.js";
|
|
12
11
|
import { getExternalHarness } from "./registry.js";
|
|
13
12
|
import { finalizeExternalRun } from "./settlement.js";
|
|
14
13
|
/**
|
|
@@ -133,14 +132,6 @@ export async function launchExternalRun(input) {
|
|
|
133
132
|
await writeFile(promptFile, `${input.task.trim()}\n`, "utf-8");
|
|
134
133
|
if (systemPromptFile)
|
|
135
134
|
await writeFile(systemPromptFile, `${trimmedSystemPrompt}\n`, "utf-8");
|
|
136
|
-
// D9: an external verifier's advisory attestation needs a before/after subject snapshot the
|
|
137
|
-
// same way the internal path does — taken here, before the process starts, since this is the
|
|
138
|
-
// earliest point at which the run is committed to running against this workingDirectory. The
|
|
139
|
-
// fixed base and initial untracked manifest survive a later normal Git commit.
|
|
140
|
-
const verifySubjectSnapshot = input.purpose === "verify" ? await workspaceSubjectSnapshot(input.workingDirectory) : undefined;
|
|
141
|
-
const verifySubjectBefore = verifySubjectSnapshot?.hash;
|
|
142
|
-
const verifyBaseCommit = verifySubjectSnapshot?.baseCommit;
|
|
143
|
-
const verifyBaselineUntrackedPaths = verifySubjectSnapshot?.baselineUntrackedPaths;
|
|
144
135
|
const argv = input.shell ? [] : splitShellWords(input.command);
|
|
145
136
|
const invocation = input.shell
|
|
146
137
|
? { executable: "/bin/sh", args: ["-lc", input.command], resumable: false }
|
|
@@ -172,6 +163,7 @@ export async function launchExternalRun(input) {
|
|
|
172
163
|
model: input.externalModelRef,
|
|
173
164
|
purpose: input.purpose,
|
|
174
165
|
taskId: input.taskId,
|
|
166
|
+
item: input.item,
|
|
175
167
|
workingDirectory: input.workingDirectory,
|
|
176
168
|
artifactDir: input.artifactDir,
|
|
177
169
|
channelDir: input.channelDir,
|
|
@@ -295,10 +287,7 @@ export async function launchExternalRun(input) {
|
|
|
295
287
|
sessionId: invocation.presetSessionId,
|
|
296
288
|
// Spec 042 D1: persisted so a restart reconciliation has the same inputs the live watcher
|
|
297
289
|
// below would — without these, a run that finishes after the daemon disappears would settle
|
|
298
|
-
// with an inaccurate timeout message
|
|
299
|
-
verifySubjectBefore,
|
|
300
|
-
verifyBaseCommit,
|
|
301
|
-
verifyBaselineUntrackedPaths,
|
|
290
|
+
// with an inaccurate timeout message and an unestimatable duration.
|
|
302
291
|
maxWallTimeSec: input.maxWallTimeSec,
|
|
303
292
|
processStartedAt,
|
|
304
293
|
channelDir: input.channelDir,
|
|
@@ -386,21 +375,14 @@ export async function launchExternalRun(input) {
|
|
|
386
375
|
// id — `finalizeExternalRun` keeps all of that; only `status` and `failureReason` get overridden
|
|
387
376
|
// by `terminationReason` (P1-1).
|
|
388
377
|
await finalizeExternalRun({
|
|
389
|
-
runId: input.runId,
|
|
390
|
-
channelId: input.channelId,
|
|
391
|
-
channelDir: input.channelDir,
|
|
392
378
|
harnessId: harness.id,
|
|
393
379
|
purpose: input.purpose,
|
|
394
|
-
taskId: input.taskId,
|
|
395
380
|
workingDirectory: input.workingDirectory,
|
|
396
381
|
artifactDir: input.artifactDir,
|
|
397
382
|
exitCode,
|
|
398
383
|
durationMs,
|
|
399
384
|
terminationReason,
|
|
400
385
|
maxWallTimeSec: input.maxWallTimeSec,
|
|
401
|
-
verifySubjectBefore,
|
|
402
|
-
verifyBaseCommit,
|
|
403
|
-
verifyBaselineUntrackedPaths,
|
|
404
386
|
mutates: input.mutates,
|
|
405
387
|
}, (settleInput, options) => runManager.settle(input.runId, settleInput, options), { announce: terminationReason !== "cancelled" }).catch((error) => {
|
|
406
388
|
log.logWarning(`Failed to settle external run ${input.runId}`, errorMessage(error));
|
|
@@ -16,14 +16,8 @@ export interface BuildExternalSettleInputInput {
|
|
|
16
16
|
*/
|
|
17
17
|
export declare function buildExternalSettleInput(input: BuildExternalSettleInputInput): SettleInput;
|
|
18
18
|
export interface FinalizeExternalRunInput {
|
|
19
|
-
runId: string;
|
|
20
|
-
channelId: string;
|
|
21
|
-
/** Needed only for `purpose=verify`: where the attestation gets written. Absent on an older
|
|
22
|
-
* record (predating spec 042) — verify processing degrades to "skip" rather than guessing. */
|
|
23
|
-
channelDir?: string;
|
|
24
19
|
harnessId: RunHarness;
|
|
25
20
|
purpose: "work" | "verify";
|
|
26
|
-
taskId?: string;
|
|
27
21
|
workingDirectory: string;
|
|
28
22
|
artifactDir: string;
|
|
29
23
|
/** `undefined` when the process was killed by a signal, or when this is a restart
|
|
@@ -33,21 +27,15 @@ export interface FinalizeExternalRunInput {
|
|
|
33
27
|
durationEstimated?: boolean;
|
|
34
28
|
terminationReason?: "timeout" | "cancelled";
|
|
35
29
|
maxWallTimeSec?: number;
|
|
36
|
-
/** The workspace subject hash taken just before this run started (D9's before/after pair for
|
|
37
|
-
* external verify) — persisted at launch so restart reconciliation has it too. */
|
|
38
|
-
verifySubjectBefore?: string;
|
|
39
|
-
/** Fixed verification base and initial untracked manifest, persisted for restart reconciliation. */
|
|
40
|
-
verifyBaseCommit?: string;
|
|
41
|
-
verifyBaselineUntrackedPaths?: string[];
|
|
42
30
|
/** P2-2: only a `write` run's completion pays for a `git status` summary — a `read` run cannot
|
|
43
31
|
* have changed anything, and this must never become a hidden cost on the common read-only path. */
|
|
44
32
|
mutates?: RunMutates;
|
|
45
33
|
}
|
|
46
34
|
/**
|
|
47
|
-
* Read this run's artifact files, parse them through its harness, decide its verdict (
|
|
48
|
-
* verify
|
|
49
|
-
*
|
|
50
|
-
*
|
|
35
|
+
* Read this run's artifact files, parse them through its harness, decide its verdict (for a
|
|
36
|
+
* `purpose=verify` run), and hand the result to `settle`. Both the live post-exit path and
|
|
37
|
+
* restart reconciliation call this and only this — there is no second implementation to drift out
|
|
38
|
+
* of sync with the first (spec 042 F1).
|
|
51
39
|
*/
|
|
52
40
|
export declare function finalizeExternalRun(input: FinalizeExternalRunInput, settle: (settleInput: SettleInput, options: {
|
|
53
41
|
announce: boolean;
|