@oyasmi/pipiclaw 0.9.4-beta.1 → 0.9.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +148 -1245
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +7 -1
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +5 -5
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/{session-adapter.js → session/session-adapter.js} +83 -1
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +10 -10
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +2 -2
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +3 -3
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +11 -8
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +0 -2
- package/dist/{runtime/app-home.js → app/home.js} +4 -75
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +10 -10
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +3 -3
- package/dist/commands/catalog.js +3 -3
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +5 -5
- package/dist/{settings.d.ts → config/settings.d.ts} +7 -8
- package/dist/{settings.js → config/settings.js} +7 -10
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +3 -0
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +6 -2
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +1 -1
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +6 -109
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +3 -146
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/main.js +2 -2
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +2 -1
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +37 -755
- package/dist/runtime/durable-dispatch.d.ts +17 -4
- package/dist/runtime/durable-dispatch.js +60 -18
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +2 -2
- package/dist/runtime/task-driver.js +3 -3
- package/dist/runtime/task-migration.js +2 -2
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +1 -1
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.js +4 -0
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/host-process.js +1 -1
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +1 -1
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +4 -3
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +2 -2
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +1 -1
- package/dist/subagents/external/run.d.ts +2 -1
- package/dist/subagents/external/run.js +2 -2
- package/dist/subagents/external/settlement.d.ts +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +7 -243
- package/dist/subagents/runs.js +8 -291
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/tasks/board.d.ts +2 -2
- package/dist/tasks/board.js +2 -2
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +12 -8
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/{log.js → loop-log.js} +1 -1
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +2 -2
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +2 -2
- package/dist/tools/{tool-details.js → contract/details.js} +4 -4
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.js +7 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.js +4 -3
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +3 -3
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +1 -1
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +1 -1
- package/dist/usage/ledger.js +4 -0
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1470
- package/dist/subagents/tool.d.ts +0 -213
- package/dist/subagents/tool.js +0 -1282
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-error.d.ts → turn/turn-error.d.ts} +0 -0
- /package/dist/agent/{turn-error.js → turn/turn-error.js} +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → app}/proxy.js +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/delivery.js +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/events/{event-validation.js → validation.js} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tasks/{log.d.ts → loop-log.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type JobStatus = "running" | "completed" | "failed" | "cancelled" | "lost";
|
|
2
|
+
export interface JobSnapshot {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
command: string;
|
|
6
|
+
status: JobStatus;
|
|
7
|
+
startedAt: number;
|
|
8
|
+
durationMs: number;
|
|
9
|
+
exitCode?: number;
|
|
10
|
+
/** The job's own wall-clock limit; a task's `work` ticket derives its backstop from it. */
|
|
11
|
+
timeoutSeconds: number;
|
|
12
|
+
/** The task this job's completion wake belongs to, if any — lets a caller verify that a
|
|
13
|
+
* `[JOB:<id>] ... belongs to task <taskId>.` wake actually names the job it claims to (T9). */
|
|
14
|
+
taskId?: string;
|
|
15
|
+
}
|
|
16
|
+
/** What should happen when the job finishes. */
|
|
17
|
+
export interface JobWakeContract {
|
|
18
|
+
/** Wake the channel on completion. Defaults to true — that is the point of the mechanism. */
|
|
19
|
+
notify: boolean;
|
|
20
|
+
/** The task this job is advancing, surfaced in the wake so the model lands in context. */
|
|
21
|
+
taskId?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface JobRecord extends JobSnapshot {
|
|
24
|
+
pid: number;
|
|
25
|
+
/** Process-group id of the launched job, as `ps` reported it right after spawn. `setsid` makes
|
|
26
|
+
* the job its own session/group leader, so this normally equals `pid` — the precondition for a
|
|
27
|
+
* safe negative-PGID kill. Absent on records written before this was captured. */
|
|
28
|
+
pgid?: number;
|
|
29
|
+
/** `ps -o lstart=` for `pid` at launch: the only OS-verifiable way to tell the still-running
|
|
30
|
+
* job apart from an unrelated process that later reused its pid. Absent on older records and
|
|
31
|
+
* whenever `ps` was unavailable at launch — callers must then treat identity as unprovable. */
|
|
32
|
+
pidStartedAt?: string;
|
|
33
|
+
spillFile: string;
|
|
34
|
+
exitFile: string;
|
|
35
|
+
timeoutSeconds: number;
|
|
36
|
+
contract: JobWakeContract;
|
|
37
|
+
/** When the job reached a terminal status; drives retention of the record and spill file. */
|
|
38
|
+
finishedAt?: number;
|
|
39
|
+
/** Set once the completion wake has been dispatched, so a restart cannot re-announce it. */
|
|
40
|
+
notified?: boolean;
|
|
41
|
+
/** Set once the owning task's log has this job's settlement (spec 052, D4); guards against a second record. */
|
|
42
|
+
taskLogged?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* A cancel or timeout whose kill could not be *confirmed* yet: the job stays `running` and
|
|
45
|
+
* manageable, and every sweep re-attempts the kill until the process is proven gone, at which
|
|
46
|
+
* point this terminal status is applied. Internal only — never surfaced in a `JobSnapshot`.
|
|
47
|
+
*/
|
|
48
|
+
pendingKill?: "cancelled" | "failed";
|
|
49
|
+
wakeClaimDispatchId?: string;
|
|
50
|
+
wakeConsumedAt?: number;
|
|
51
|
+
}
|
|
52
|
+
export declare function isTerminal(status: JobStatus): boolean;
|
|
53
|
+
/** Accept a persisted record only if the fields the manager actually relies on are intact. */
|
|
54
|
+
export declare function parseJobRecord(raw: string): JobRecord | undefined;
|
|
55
|
+
export declare function toSnapshot(record: JobRecord): JobSnapshot;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background-job record vocabulary: status, the snapshot handed to callers, the persisted record
|
|
3
|
+
* and its parser. No state and no I/O, shared by the job manager and its tool/callers (spec 054 D11).
|
|
4
|
+
*/
|
|
5
|
+
import { isRecord } from "../shared/type-guards.js";
|
|
6
|
+
export function isTerminal(status) {
|
|
7
|
+
return status !== "running";
|
|
8
|
+
}
|
|
9
|
+
/** Accept a persisted record only if the fields the manager actually relies on are intact. */
|
|
10
|
+
export function parseJobRecord(raw) {
|
|
11
|
+
const value = JSON.parse(raw);
|
|
12
|
+
if (!isRecord(value) ||
|
|
13
|
+
typeof value.id !== "string" ||
|
|
14
|
+
typeof value.pid !== "number" ||
|
|
15
|
+
typeof value.spillFile !== "string" ||
|
|
16
|
+
typeof value.exitFile !== "string" ||
|
|
17
|
+
typeof value.startedAt !== "number" ||
|
|
18
|
+
typeof value.timeoutSeconds !== "number" ||
|
|
19
|
+
!isRecord(value.contract)) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
export function toSnapshot(record) {
|
|
25
|
+
return {
|
|
26
|
+
id: record.id,
|
|
27
|
+
label: record.label,
|
|
28
|
+
command: record.command,
|
|
29
|
+
status: record.status,
|
|
30
|
+
startedAt: record.startedAt,
|
|
31
|
+
durationMs: record.status === "running" ? Date.now() - record.startedAt : record.durationMs,
|
|
32
|
+
exitCode: record.exitCode,
|
|
33
|
+
timeoutSeconds: record.timeoutSeconds,
|
|
34
|
+
taskId: record.contract.taskId,
|
|
35
|
+
};
|
|
36
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { runAuth } from "./app/auth-command.js";
|
|
3
|
+
import { formatCliCommandsHelp, isBootstrapExitError } from "./app/home.js";
|
|
2
4
|
import * as log from "./log.js";
|
|
3
|
-
import { runAuth } from "./models/auth-cli.js";
|
|
4
|
-
import { formatCliCommandsHelp, isBootstrapExitError } from "./runtime/app-home.js";
|
|
5
5
|
import { bootstrap } from "./runtime/bootstrap.js";
|
|
6
6
|
import { errorMessage } from "./shared/text-utils.js";
|
|
7
7
|
import { runTui } from "./tui/cli.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PipiclawMemoryMaintenanceSettings } from "../settings.js";
|
|
2
1
|
import type { MemoryMaintenanceState } from "./maintenance-state.js";
|
|
2
|
+
import type { MemoryMaintenanceSettings } from "./maintenance-tuning.js";
|
|
3
3
|
export interface MaintenanceGateDecision {
|
|
4
4
|
allowed: boolean;
|
|
5
5
|
skipReason?: string;
|
|
@@ -17,7 +17,7 @@ export interface ReflectMaterial {
|
|
|
17
17
|
export interface ReflectGateInput {
|
|
18
18
|
now: Date;
|
|
19
19
|
state: MemoryMaintenanceState;
|
|
20
|
-
maintenance:
|
|
20
|
+
maintenance: MemoryMaintenanceSettings;
|
|
21
21
|
channelActive: boolean;
|
|
22
22
|
material: () => ReflectMaterial;
|
|
23
23
|
}
|
|
@@ -13,4 +13,19 @@ export interface MemoryMaintenanceTuning {
|
|
|
13
13
|
reflectIntervalMinutes: number;
|
|
14
14
|
failureBackoffMinutes: number;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* What the gates and the scheduler consume: the user's one decision (`enabled`, from
|
|
18
|
+
* `settings.json`) plus the code-owned cadence constants.
|
|
19
|
+
*/
|
|
20
|
+
export type MemoryMaintenanceSettings = MemoryMaintenanceTuning & {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* What callers hand to the memory pipeline: the `settings.json` switch, optionally with explicit
|
|
25
|
+
* tuning values (tests pin them); anything omitted falls back to the code constants.
|
|
26
|
+
*/
|
|
27
|
+
export type MemoryMaintenanceInput = {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
} & Partial<MemoryMaintenanceTuning>;
|
|
30
|
+
export declare function resolveMemoryMaintenanceSettings(input: MemoryMaintenanceInput, env?: NodeJS.ProcessEnv): MemoryMaintenanceSettings;
|
|
16
31
|
export declare function getMemoryMaintenanceTuning(env?: NodeJS.ProcessEnv): MemoryMaintenanceTuning;
|
|
@@ -23,6 +23,9 @@ const FAST_MAINTENANCE_TUNING = {
|
|
|
23
23
|
reflectIntervalMinutes: 0,
|
|
24
24
|
failureBackoffMinutes: 1,
|
|
25
25
|
};
|
|
26
|
+
export function resolveMemoryMaintenanceSettings(input, env = process.env) {
|
|
27
|
+
return { ...getMemoryMaintenanceTuning(env), ...input };
|
|
28
|
+
}
|
|
26
29
|
export function getMemoryMaintenanceTuning(env = process.env) {
|
|
27
30
|
return env.PIPICLAW_TEST_FAST_MAINTENANCE === "1" ? FAST_MAINTENANCE_TUNING : PRODUCTION_TUNING;
|
|
28
31
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import type { PipiclawMemoryMaintenanceSettings } from "../settings.js";
|
|
5
4
|
import { type ChannelMemoryQueue } from "./channel-maintenance-queue.js";
|
|
5
|
+
import { type MemoryMaintenanceInput } from "./maintenance-tuning.js";
|
|
6
6
|
import { runReflect } from "./reflect.js";
|
|
7
7
|
/**
|
|
8
8
|
* Spec 050, D7/D9: the scheduler's idle-tick entry point into the reflect pass. Boundary
|
|
@@ -18,7 +18,7 @@ export interface ReflectJobInput {
|
|
|
18
18
|
channelActive: boolean;
|
|
19
19
|
now?: Date;
|
|
20
20
|
settings: {
|
|
21
|
-
memoryMaintenance:
|
|
21
|
+
memoryMaintenance: MemoryMaintenanceInput;
|
|
22
22
|
};
|
|
23
23
|
model: Model<Api>;
|
|
24
24
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
@@ -3,6 +3,7 @@ import { errorMessage } from "../shared/text-utils.js";
|
|
|
3
3
|
import { getDefaultChannelMemoryQueue } from "./channel-maintenance-queue.js";
|
|
4
4
|
import { shouldRunReflect } from "./maintenance-gates.js";
|
|
5
5
|
import { readMemoryMaintenanceState, updateMemoryMaintenanceState } from "./maintenance-state.js";
|
|
6
|
+
import { resolveMemoryMaintenanceSettings, } from "./maintenance-tuning.js";
|
|
6
7
|
import { runReflect } from "./reflect.js";
|
|
7
8
|
import { appendMemoryReviewLog } from "./review-log.js";
|
|
8
9
|
import { buildIncrementalMemorySourceWindow } from "./source-window.js";
|
|
@@ -14,6 +15,7 @@ export async function runReflectJob(input) {
|
|
|
14
15
|
const queue = input.queue ?? getDefaultChannelMemoryQueue();
|
|
15
16
|
return queue.run(input.channelId, async () => {
|
|
16
17
|
const now = input.now ?? new Date();
|
|
18
|
+
const maintenance = resolveMemoryMaintenanceSettings(input.settings.memoryMaintenance);
|
|
17
19
|
const state = await readMemoryMaintenanceState(input.appHomeDir, input.channelId);
|
|
18
20
|
let cachedWindow;
|
|
19
21
|
const loadSourceWindow = () => {
|
|
@@ -28,7 +30,7 @@ export async function runReflectJob(input) {
|
|
|
28
30
|
const decision = shouldRunReflect({
|
|
29
31
|
now,
|
|
30
32
|
state,
|
|
31
|
-
maintenance
|
|
33
|
+
maintenance,
|
|
32
34
|
channelActive: input.channelActive,
|
|
33
35
|
material: () => {
|
|
34
36
|
const window = loadSourceWindow();
|
|
@@ -75,7 +77,7 @@ export async function runReflectJob(input) {
|
|
|
75
77
|
catch (error) {
|
|
76
78
|
await updateMemoryMaintenanceState(input.appHomeDir, input.channelId, (current) => ({
|
|
77
79
|
...current,
|
|
78
|
-
failureBackoffUntil: backoffUntil(now,
|
|
80
|
+
failureBackoffUntil: backoffUntil(now, maintenance),
|
|
79
81
|
}));
|
|
80
82
|
const message = errorMessage(error);
|
|
81
83
|
await appendMemoryReviewLog(input.channelDir, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import type { SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import type
|
|
4
|
+
import { type MemoryMaintenanceInput } from "./maintenance-tuning.js";
|
|
5
5
|
export interface MemoryMaintenanceRuntimeContext {
|
|
6
6
|
channelId: string;
|
|
7
7
|
channelDir: string;
|
|
@@ -16,7 +16,7 @@ export interface MemoryMaintenanceRuntimeContext {
|
|
|
16
16
|
model: Model<Api>;
|
|
17
17
|
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
18
18
|
settings: {
|
|
19
|
-
memoryMaintenance:
|
|
19
|
+
memoryMaintenance: MemoryMaintenanceInput;
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
export interface MemoryMaintenanceSchedulerOptions {
|
|
@@ -26,7 +26,7 @@ export interface MemoryMaintenanceSchedulerOptions {
|
|
|
26
26
|
getRuntimeContext: (channelId: string) => Promise<MemoryMaintenanceRuntimeContext | null>;
|
|
27
27
|
isChannelActive: (channelId: string) => boolean;
|
|
28
28
|
getSettings: () => {
|
|
29
|
-
memoryMaintenance:
|
|
29
|
+
memoryMaintenance: MemoryMaintenanceInput;
|
|
30
30
|
};
|
|
31
31
|
intervalMs?: number;
|
|
32
32
|
}
|
package/dist/memory/scheduler.js
CHANGED
|
@@ -8,6 +8,7 @@ import * as log from "../log.js";
|
|
|
8
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
9
|
import { shouldRunReflect } from "./maintenance-gates.js";
|
|
10
10
|
import { getMemoryMaintenanceStateDir, readMemoryMaintenanceState } from "./maintenance-state.js";
|
|
11
|
+
import { resolveMemoryMaintenanceSettings } from "./maintenance-tuning.js";
|
|
11
12
|
import { runReflectJob } from "./reflect-job.js";
|
|
12
13
|
const DEFAULT_TICK_INTERVAL_MS = 60_000;
|
|
13
14
|
/**
|
|
@@ -25,7 +26,7 @@ async function mightReflectBeDue(input) {
|
|
|
25
26
|
return shouldRunReflect({
|
|
26
27
|
now: input.now,
|
|
27
28
|
state,
|
|
28
|
-
maintenance: input.settings.memoryMaintenance,
|
|
29
|
+
maintenance: resolveMemoryMaintenanceSettings(input.settings.memoryMaintenance),
|
|
29
30
|
channelActive: false,
|
|
30
31
|
material: () => ({ hasNewEntry: true, hasMeaningfulExchange: true }),
|
|
31
32
|
}).allowed;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Agent } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { streamSimple } from "@earendil-works/pi-ai/compat";
|
|
3
3
|
import { convertToLlm } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import { formatModelReference } from "../models/
|
|
4
|
+
import { formatModelReference } from "../models/reference.js";
|
|
5
5
|
import { extractAssistantText } from "../shared/text-utils.js";
|
|
6
6
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
7
7
|
const SIDE_CAR_RETRY_DELAY_MS = 2_000;
|
|
@@ -3,7 +3,7 @@ import { MEMORY_BOOTSTRAP_TAG } from "./render.js";
|
|
|
3
3
|
import { redactSecrets } from "./secret-redaction.js";
|
|
4
4
|
// The channel runner prepends the memory bootstrap, the task agenda and the channel
|
|
5
5
|
// capsule to the raw user input, then wraps the input itself in <user_message>
|
|
6
|
-
// (`agent/turn-prompt.ts`). If that combined text flows back into consolidation /
|
|
6
|
+
// (`agent/turn/turn-prompt.ts`). If that combined text flows back into consolidation /
|
|
7
7
|
// session refresh / signal scans, previously recalled memory gets re-summarized into
|
|
8
8
|
// MEMORY.md — a self-reinforcing echo. Strip the injected wrappers before any memory
|
|
9
9
|
// job reads the transcript.
|
|
@@ -31,6 +31,10 @@ export declare function takeFailedTurn(messages: readonly unknown[]): unknown[]
|
|
|
31
31
|
export declare function shouldRestorePrimary(primaryFailedAt: number | null, now: number): boolean;
|
|
32
32
|
/** Short one-line error summary for the user-facing switch notice. */
|
|
33
33
|
export declare function summarizeFallbackError(errorMessage: string | undefined): string;
|
|
34
|
+
export interface FallbackRetryPlan {
|
|
35
|
+
kind: "unsubmitted" | "failed-turn";
|
|
36
|
+
run(text: string, onReady: () => void): Promise<"attempted" | "stale">;
|
|
37
|
+
}
|
|
34
38
|
export interface FallbackRunDeps {
|
|
35
39
|
/** Submit a prompt. Must catch transport/prompt errors and record them into run error state. */
|
|
36
40
|
prompt(text: string): Promise<void>;
|
|
@@ -41,12 +45,8 @@ export interface FallbackRunDeps {
|
|
|
41
45
|
};
|
|
42
46
|
/** Clear stopReason/errorMessage/finalOutcome so the re-run starts clean. */
|
|
43
47
|
resetRunError(): void;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/** Assign the truncated transcript back (SDK setter copies the array). */
|
|
47
|
-
setMessages(messages: unknown[]): void;
|
|
48
|
-
/** Whether the first prompt actually enqueued its user message (false = pre-flight throw, e.g. no API key). */
|
|
49
|
-
promptWasSubmitted(): boolean;
|
|
48
|
+
prepareRetry(): FallbackRetryPlan | null;
|
|
49
|
+
canRetry(): boolean;
|
|
50
50
|
getCurrentModelRef(): string;
|
|
51
51
|
/** Resolve the configured backup model, or null (unset / unresolvable / no API key). */
|
|
52
52
|
resolveFallbackModel(): Promise<Model<Api> | null>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { isContextOverflow } from "@earendil-works/pi-ai";
|
|
2
|
-
import * as log from "../log.js";
|
|
3
|
-
import { formatModelReference } from "../models/utils.js";
|
|
4
2
|
import { isRecord } from "../shared/type-guards.js";
|
|
3
|
+
import { formatModelReference } from "./reference.js";
|
|
5
4
|
/**
|
|
6
5
|
* Backup-model fallback (spec 017).
|
|
7
6
|
*
|
|
@@ -96,36 +95,24 @@ export async function runPromptWithFallback(promptText, deps) {
|
|
|
96
95
|
if (firstError.stopReason !== "error" || !shouldFallback(firstError.errorMessage)) {
|
|
97
96
|
return false;
|
|
98
97
|
}
|
|
98
|
+
if (!deps.canRetry())
|
|
99
|
+
return false;
|
|
100
|
+
const plan = deps.prepareRetry();
|
|
101
|
+
if (!plan)
|
|
102
|
+
return false;
|
|
99
103
|
const candidate = await deps.resolveFallbackModel();
|
|
100
|
-
if (!candidate)
|
|
104
|
+
if (!candidate || !deps.canRetry())
|
|
101
105
|
return false;
|
|
102
|
-
}
|
|
103
106
|
const fromRef = deps.getCurrentModelRef();
|
|
104
107
|
const toRef = formatModelReference(candidate);
|
|
105
|
-
if (fromRef === toRef)
|
|
108
|
+
if (fromRef === toRef)
|
|
106
109
|
return false;
|
|
107
|
-
}
|
|
108
|
-
// Pre-compute the truncated transcript, but do not commit it until setModel
|
|
109
|
-
// succeeds. Surgery only when the failed turn was actually enqueued: a pre-flight
|
|
110
|
-
// throw (no API key on the primary) submits nothing, so there is nothing to
|
|
111
|
-
// remove — switch straight to the backup, which covers a mis-configured primary key.
|
|
112
|
-
let truncated = null;
|
|
113
|
-
if (deps.promptWasSubmitted()) {
|
|
114
|
-
truncated = takeFailedTurn(deps.getMessages());
|
|
115
|
-
if (!truncated) {
|
|
116
|
-
log.logWarn("agent.model.fallback_skipped", "Fallback skipped: transcript tail is not [user, assistant(error)]");
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
// Switch the model first: if setModel throws it propagates with the transcript
|
|
121
|
-
// still intact, so the failed turn's context is not silently lost.
|
|
122
|
-
deps.markPrimaryFailed();
|
|
123
110
|
await deps.setModel(candidate);
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
if (!deps.canRetry())
|
|
112
|
+
return false;
|
|
113
|
+
return ((await plan.run(promptText, () => {
|
|
114
|
+
deps.resetRunError();
|
|
115
|
+
deps.markPrimaryFailed();
|
|
116
|
+
deps.notifySwitch(fromRef, toRef, summarizeFallbackError(firstError.errorMessage));
|
|
117
|
+
})) === "attempted");
|
|
131
118
|
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { link, mkdir, open, readFile, unlink } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, join } from "node:path";
|
|
4
|
+
import { isRecord } from "../shared/type-guards.js";
|
|
5
|
+
function hasCode(error, code) {
|
|
6
|
+
return isRecord(error) && error.code === code;
|
|
7
|
+
}
|
|
8
|
+
/** Installation identity is published once, without ever replacing another process's winner. */
|
|
9
|
+
export async function getLoginInstallationId(appHomeDir, signal) {
|
|
10
|
+
if (!isAbsolute(appHomeDir))
|
|
11
|
+
throw new Error("OAuth identity requires an absolute appHomeDir. Pass the resolved application path.");
|
|
12
|
+
const directory = join(appHomeDir, "state", "auth");
|
|
13
|
+
const path = join(directory, "identity.json");
|
|
14
|
+
const readIdentity = async () => {
|
|
15
|
+
const data = JSON.parse(await readFile(path, "utf8"));
|
|
16
|
+
if (!isRecord(data) ||
|
|
17
|
+
data.version !== 1 ||
|
|
18
|
+
typeof data.installationId !== "string" ||
|
|
19
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(data.installationId)) {
|
|
20
|
+
throw new Error("Invalid installation identity schema or version");
|
|
21
|
+
}
|
|
22
|
+
return data.installationId;
|
|
23
|
+
};
|
|
24
|
+
let temporary;
|
|
25
|
+
try {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
try {
|
|
28
|
+
const id = await readIdentity();
|
|
29
|
+
signal.throwIfAborted();
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (!hasCode(error, "ENOENT"))
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
signal.throwIfAborted();
|
|
37
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
38
|
+
signal.throwIfAborted();
|
|
39
|
+
const installationId = randomUUID();
|
|
40
|
+
const candidatePath = join(directory, `.identity-${randomUUID()}.tmp`);
|
|
41
|
+
const file = await open(candidatePath, "wx", 0o600);
|
|
42
|
+
temporary = candidatePath;
|
|
43
|
+
try {
|
|
44
|
+
await file.writeFile(`${JSON.stringify({ version: 1, installationId })}\n`);
|
|
45
|
+
await file.sync();
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
await file.close();
|
|
49
|
+
}
|
|
50
|
+
signal.throwIfAborted();
|
|
51
|
+
let winner = installationId;
|
|
52
|
+
try {
|
|
53
|
+
await link(temporary, path);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (!hasCode(error, "EEXIST"))
|
|
57
|
+
throw error;
|
|
58
|
+
winner = await readIdentity();
|
|
59
|
+
}
|
|
60
|
+
// A published identity survives cancellation; finish its durability and cleanup first.
|
|
61
|
+
const dir = await open(directory, "r");
|
|
62
|
+
try {
|
|
63
|
+
await dir.sync();
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await dir.close();
|
|
67
|
+
}
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
return winner;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (signal.aborted)
|
|
73
|
+
throw error;
|
|
74
|
+
throw new Error(`OAuth installation identity failed at ${path}. Check storage access and restore a valid identity from backup before retrying; do not reset an existing identity.`, { cause: error });
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
if (temporary)
|
|
78
|
+
await unlink(temporary).catch((error) => {
|
|
79
|
+
if (!hasCode(error, "ENOENT"))
|
|
80
|
+
throw new Error(`OAuth installation identity cleanup failed at ${directory}. Check storage access before retrying.`, { cause: error });
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -35,7 +35,9 @@ export interface ProviderLoginResult {
|
|
|
35
35
|
}
|
|
36
36
|
/** List every provider x auth-type combination the provider supports (not just ones with an interactive `login`). */
|
|
37
37
|
export declare function listProviderLoginOptions(runtime: ModelRuntime, authType?: AuthType): ProviderLoginOption[];
|
|
38
|
-
export declare function loginProvider(runtime: ModelRuntime, providerId: string, authType: AuthType, ui: LoginUi
|
|
38
|
+
export declare function loginProvider(runtime: ModelRuntime, providerId: string, authType: AuthType, ui: LoginUi, context: {
|
|
39
|
+
appHomeDir: string;
|
|
40
|
+
}): Promise<ProviderLoginResult>;
|
|
39
41
|
export declare function logoutProvider(runtime: ModelRuntime, providerId: string): Promise<void>;
|
|
40
42
|
/** Render the `pipiclaw auth status` report: one row per provider, plus the auth.json path and any models.json error. */
|
|
41
43
|
export declare function renderAuthStatus(runtime: ModelRuntime, authPath: string): Promise<string>;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* this file (see docs/archive/specs/039-provider-login-cli/design.md §10).
|
|
6
6
|
*/
|
|
7
7
|
import { ModelsError, } from "@earendil-works/pi-ai";
|
|
8
|
+
import { getLoginInstallationId } from "./login-identity.js";
|
|
8
9
|
export class LoginCancelledError extends Error {
|
|
9
10
|
constructor(message = "登录已取消") {
|
|
10
11
|
super(message);
|
|
@@ -69,7 +70,12 @@ function humanizeLoginError(providerId, error) {
|
|
|
69
70
|
}
|
|
70
71
|
return new Error(`登录失败:${String(error)}`);
|
|
71
72
|
}
|
|
72
|
-
export async function loginProvider(runtime, providerId, authType, ui) {
|
|
73
|
+
export async function loginProvider(runtime, providerId, authType, ui, context) {
|
|
74
|
+
ui.signal.throwIfAborted();
|
|
75
|
+
const installationId = providerId === "openai" && authType === "oauth"
|
|
76
|
+
? await getLoginInstallationId(context.appHomeDir, ui.signal)
|
|
77
|
+
: undefined;
|
|
78
|
+
ui.signal.throwIfAborted();
|
|
73
79
|
const before = runtime.getAvailableSnapshot();
|
|
74
80
|
let credential;
|
|
75
81
|
try {
|
|
@@ -77,7 +83,7 @@ export async function loginProvider(runtime, providerId, authType, ui) {
|
|
|
77
83
|
signal: ui.signal,
|
|
78
84
|
prompt: (prompt) => ui.ask(prompt),
|
|
79
85
|
notify: (event) => ui.notify(event),
|
|
80
|
-
});
|
|
86
|
+
}, installationId ? { getDeviceId: () => installationId, agentName: "pipiclaw" } : undefined);
|
|
81
87
|
}
|
|
82
88
|
catch (error) {
|
|
83
89
|
throw humanizeLoginError(providerId, error);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model references: format `provider/id`, match user input against the available models, list
|
|
3
|
+
* them, and tell whether a model has usable pricing.
|
|
4
|
+
*/
|
|
5
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
6
|
+
export declare function formatModelReference(model: Model<Api>): string;
|
|
7
|
+
/**
|
|
8
|
+
* Pi fills omitted custom-model pricing with zero rates. An all-zero table therefore
|
|
9
|
+
* means "price unavailable", not reliably "free".
|
|
10
|
+
*/
|
|
11
|
+
export declare function hasKnownModelPricing(model: Model<Api> | undefined): boolean;
|
|
12
|
+
export declare function findExactModelReferenceMatch(modelReference: string, availableModels: Model<Api>[]): {
|
|
13
|
+
match?: Model<Api>;
|
|
14
|
+
ambiguous: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function findModelReferenceMatch(modelReference: string, availableModels: Model<Api>[]): {
|
|
17
|
+
match?: Model<Api>;
|
|
18
|
+
ambiguous: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function formatModelList(models: Model<Api>[], currentModel: Model<Api> | undefined, limit?: number): string;
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
import { isAbsolute } from "node:path";
|
|
2
|
-
import { getBuiltinModel as getModel } from "@earendil-works/pi-ai/providers/all";
|
|
3
|
-
import { ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
// Default model - will be overridden by ModelRegistry if custom models are configured
|
|
5
|
-
export const defaultModel = getModel("anthropic", "claude-sonnet-4-5");
|
|
6
|
-
/**
|
|
7
|
-
* Construct the canonical async model/auth runtime (replaces the old
|
|
8
|
-
* `AuthStorage.create` + `ModelRegistry` pairing). pi 0.80.8+ folded auth and
|
|
9
|
-
* model resolution into a single async `ModelRuntime`.
|
|
10
|
-
*
|
|
11
|
-
* `authConfigPath` must always be given explicitly and be absolute: pipiclaw
|
|
12
|
-
* never wants `AuthStorage`'s undefined-path fallback to `~/.pi/agent/auth.json`
|
|
13
|
-
* (spec 039 §4). Do not call the SDK's `getAuthPath()` / `getAgentDir()` /
|
|
14
|
-
* no-arg `readStoredCredential()`, and do not set `PI_CODING_AGENT_DIR` —
|
|
15
|
-
* all three can silently move credential I/O away from `APP_HOME_DIR`.
|
|
16
|
-
*/
|
|
17
|
-
export async function createModelRuntime(options) {
|
|
18
|
-
if (!options.authConfigPath || !isAbsolute(options.authConfigPath)) {
|
|
19
|
-
throw new Error(`createModelRuntime: authConfigPath must be a non-empty absolute path, got ${JSON.stringify(options.authConfigPath)}`);
|
|
20
|
-
}
|
|
21
|
-
return ModelRuntime.create({
|
|
22
|
-
authPath: options.authConfigPath,
|
|
23
|
-
modelsPath: options.modelsConfigPath,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Wrap a ModelRuntime in the synchronous extension-facing ModelRegistry shell so
|
|
28
|
-
* existing `getAvailable`/`find`/`getApiKeyForProvider` call sites stay unchanged.
|
|
29
|
-
*/
|
|
30
|
-
export function wrapModelRegistry(modelRuntime) {
|
|
31
|
-
return new ModelRegistry(modelRuntime);
|
|
32
|
-
}
|
|
33
1
|
export function formatModelReference(model) {
|
|
34
2
|
return `${model.provider}/${model.id}`;
|
|
35
3
|
}
|
|
@@ -108,19 +76,3 @@ export function formatModelList(models, currentModel, limit = 20) {
|
|
|
108
76
|
}
|
|
109
77
|
return `${refs.slice(0, limit).join("\n")}\n- ... and ${refs.length - limit} more`;
|
|
110
78
|
}
|
|
111
|
-
export function resolveInitialModel(modelRegistry, settingsManager) {
|
|
112
|
-
const savedProvider = settingsManager.getDefaultProvider();
|
|
113
|
-
const savedModelId = settingsManager.getDefaultModel();
|
|
114
|
-
const availableModels = modelRegistry.getAvailable();
|
|
115
|
-
if (savedProvider && savedModelId) {
|
|
116
|
-
const savedModel = modelRegistry.find(savedProvider, savedModelId);
|
|
117
|
-
if (savedModel &&
|
|
118
|
-
availableModels.some((model) => model.provider === savedModel.provider && model.id === savedModel.id)) {
|
|
119
|
-
return savedModel;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (availableModels.length > 0) {
|
|
123
|
-
return availableModels[0];
|
|
124
|
-
}
|
|
125
|
-
return defaultModel;
|
|
126
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
2
2
|
import { ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import type { PipiclawSettingsManager } from "../settings.js";
|
|
3
|
+
import type { PipiclawSettingsManager } from "../config/settings.js";
|
|
4
4
|
export declare const defaultModel: Model<"anthropic-messages">;
|
|
5
5
|
/**
|
|
6
6
|
* Construct the canonical async model/auth runtime (replaces the old
|
|
@@ -22,19 +22,4 @@ export declare function createModelRuntime(options: {
|
|
|
22
22
|
* existing `getAvailable`/`find`/`getApiKeyForProvider` call sites stay unchanged.
|
|
23
23
|
*/
|
|
24
24
|
export declare function wrapModelRegistry(modelRuntime: ModelRuntime): ModelRegistry;
|
|
25
|
-
export declare function formatModelReference(model: Model<Api>): string;
|
|
26
|
-
/**
|
|
27
|
-
* Pi fills omitted custom-model pricing with zero rates. An all-zero table therefore
|
|
28
|
-
* means "price unavailable", not reliably "free".
|
|
29
|
-
*/
|
|
30
|
-
export declare function hasKnownModelPricing(model: Model<Api> | undefined): boolean;
|
|
31
|
-
export declare function findExactModelReferenceMatch(modelReference: string, availableModels: Model<Api>[]): {
|
|
32
|
-
match?: Model<Api>;
|
|
33
|
-
ambiguous: boolean;
|
|
34
|
-
};
|
|
35
|
-
export declare function findModelReferenceMatch(modelReference: string, availableModels: Model<Api>[]): {
|
|
36
|
-
match?: Model<Api>;
|
|
37
|
-
ambiguous: boolean;
|
|
38
|
-
};
|
|
39
|
-
export declare function formatModelList(models: Model<Api>[], currentModel: Model<Api> | undefined, limit?: number): string;
|
|
40
25
|
export declare function resolveInitialModel(modelRegistry: ModelRegistry, settingsManager: PipiclawSettingsManager): Model<Api>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model runtime: the default model, construction of the async model/auth runtime and its
|
|
3
|
+
* registry shell, and the initial model choice from settings.
|
|
4
|
+
*/
|
|
5
|
+
import { isAbsolute } from "node:path";
|
|
6
|
+
import { getBuiltinModel as getModel } from "@earendil-works/pi-ai/providers/all";
|
|
7
|
+
import { ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
// Default model - will be overridden by ModelRegistry if custom models are configured
|
|
9
|
+
export const defaultModel = getModel("anthropic", "claude-sonnet-4-5");
|
|
10
|
+
/**
|
|
11
|
+
* Construct the canonical async model/auth runtime (replaces the old
|
|
12
|
+
* `AuthStorage.create` + `ModelRegistry` pairing). pi 0.80.8+ folded auth and
|
|
13
|
+
* model resolution into a single async `ModelRuntime`.
|
|
14
|
+
*
|
|
15
|
+
* `authConfigPath` must always be given explicitly and be absolute: pipiclaw
|
|
16
|
+
* never wants `AuthStorage`'s undefined-path fallback to `~/.pi/agent/auth.json`
|
|
17
|
+
* (spec 039 §4). Do not call the SDK's `getAuthPath()` / `getAgentDir()` /
|
|
18
|
+
* no-arg `readStoredCredential()`, and do not set `PI_CODING_AGENT_DIR` —
|
|
19
|
+
* all three can silently move credential I/O away from `APP_HOME_DIR`.
|
|
20
|
+
*/
|
|
21
|
+
export async function createModelRuntime(options) {
|
|
22
|
+
if (!options.authConfigPath || !isAbsolute(options.authConfigPath)) {
|
|
23
|
+
throw new Error(`createModelRuntime: authConfigPath must be a non-empty absolute path, got ${JSON.stringify(options.authConfigPath)}`);
|
|
24
|
+
}
|
|
25
|
+
return ModelRuntime.create({
|
|
26
|
+
authPath: options.authConfigPath,
|
|
27
|
+
modelsPath: options.modelsConfigPath,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Wrap a ModelRuntime in the synchronous extension-facing ModelRegistry shell so
|
|
32
|
+
* existing `getAvailable`/`find`/`getApiKeyForProvider` call sites stay unchanged.
|
|
33
|
+
*/
|
|
34
|
+
export function wrapModelRegistry(modelRuntime) {
|
|
35
|
+
return new ModelRegistry(modelRuntime);
|
|
36
|
+
}
|
|
37
|
+
export function resolveInitialModel(modelRegistry, settingsManager) {
|
|
38
|
+
const savedProvider = settingsManager.getDefaultProvider();
|
|
39
|
+
const savedModelId = settingsManager.getDefaultModel();
|
|
40
|
+
const availableModels = modelRegistry.getAvailable();
|
|
41
|
+
if (savedProvider && savedModelId) {
|
|
42
|
+
const savedModel = modelRegistry.find(savedProvider, savedModelId);
|
|
43
|
+
if (savedModel &&
|
|
44
|
+
availableModels.some((model) => model.provider === savedModel.provider && model.id === savedModel.id)) {
|
|
45
|
+
return savedModel;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (availableModels.length > 0) {
|
|
49
|
+
return availableModels[0];
|
|
50
|
+
}
|
|
51
|
+
return defaultModel;
|
|
52
|
+
}
|