@sleep2agi/agent-network 2.3.0-preview.11 → 2.3.0-preview.111
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.md +35 -324
- package/dist/bin/anet.cjs +101 -0
- package/dist/bin/cli.d.ts +1 -0
- package/dist/bin/cli.js +20 -1
- package/dist/bin/goal-wake-log-render.d.ts +31 -0
- package/dist/src/active-network-task.d.ts +28 -0
- package/dist/src/batch-workdir.d.ts +9 -0
- package/dist/src/bootstrap-password-db.d.ts +13 -0
- package/dist/src/channel-attachments.d.ts +29 -0
- package/dist/src/channel-meta.d.ts +10 -0
- package/dist/src/channel-task-trace.d.ts +14 -0
- package/dist/src/claude-vendor-env.d.ts +28 -0
- package/dist/src/cli-args.d.ts +8 -0
- package/dist/src/cli-version-display.d.ts +16 -0
- package/dist/src/client-task-trace.d.ts +9 -0
- package/dist/src/client.js +1 -1
- package/dist/src/codex-auth-fingerprint.d.ts +211 -0
- package/dist/src/codex-copresence-preflight.d.ts +65 -0
- package/dist/src/codex-copresence-profile.d.ts +125 -0
- package/dist/src/codex-copresence-recovery.d.ts +43 -0
- package/dist/src/codex-copresence-thread.d.ts +13 -0
- package/dist/src/codex-lifecycle-account.d.ts +104 -0
- package/dist/src/codex-lifecycle-canary.d.ts +20 -0
- package/dist/src/codex-lifecycle-facts.d.ts +53 -0
- package/dist/src/codex-lifecycle-fork.d.ts +91 -0
- package/dist/src/codex-lifecycle-preflight.d.ts +77 -0
- package/dist/src/codex-lifecycle-receipt.d.ts +44 -0
- package/dist/src/codex-lifecycle-restart.d.ts +86 -0
- package/dist/src/codex-model-default.d.ts +6 -0
- package/dist/src/codex-tui-client-health.d.ts +17 -0
- package/dist/src/commhub-response.d.ts +1 -0
- package/dist/src/controlled-upload.d.ts +83 -0
- package/dist/src/copresence-deps.d.ts +22 -0
- package/dist/src/copresence-identity.d.ts +353 -0
- package/dist/src/copresence-startup-diagnosis.d.ts +17 -0
- package/dist/src/daemon-anet-bin.d.ts +32 -0
- package/dist/src/daemon-capability-display.d.ts +110 -0
- package/dist/src/daemon-capability-display.js +21 -0
- package/dist/src/daemon-runtime-path-preflight.d.ts +22 -0
- package/dist/src/daemon-runtime-staleness.d.ts +13 -0
- package/dist/src/dashboard-managed-process.d.ts +35 -0
- package/dist/src/display-width.d.ts +27 -0
- package/dist/src/doctor-node-count.d.ts +28 -0
- package/dist/src/environ-alias.d.ts +14 -0
- package/dist/src/grok-attach-client.d.ts +129 -0
- package/dist/src/grok-build-drift.d.ts +15 -0
- package/dist/src/grok-copresence-disclosure.d.ts +11 -0
- package/dist/src/grok-copresence-orchestration.d.ts +75 -0
- package/dist/src/grok-copresence-profile.d.ts +65 -0
- package/dist/src/host-telemetry.d.ts +14 -0
- package/dist/src/hub-health-timeout.d.ts +4 -0
- package/dist/src/hub-time-display.d.ts +20 -0
- package/dist/src/hub-version-skew.d.ts +19 -0
- package/dist/src/im/correlation-store.d.ts +34 -0
- package/dist/src/im/feishu/adapter.d.ts +80 -0
- package/dist/src/im/feishu/bridge.d.ts +78 -14
- package/dist/src/im/feishu/config.d.ts +31 -0
- package/dist/src/im/feishu/hub-upload.d.ts +88 -0
- package/dist/src/im/feishu/outbound-route.d.ts +62 -0
- package/dist/src/im/feishu/worker-lifecycle.d.ts +13 -0
- package/dist/src/im/feishu/worker.js +187 -144
- package/dist/src/im/types.d.ts +30 -1
- package/dist/src/inbox-drain.d.ts +20 -0
- package/dist/src/local-process-state.d.ts +12 -0
- package/dist/src/locale-diagnostic.d.ts +12 -0
- package/dist/src/ls-columns.d.ts +15 -0
- package/dist/src/mock-llm.d.ts +12 -0
- package/dist/src/node-activity-log.d.ts +4 -0
- package/dist/src/node-not-found.d.ts +1 -0
- package/dist/src/node-running-guard.d.ts +9 -0
- package/dist/src/node-server-payload.d.ts +66 -0
- package/dist/src/node-server-rules-file.d.ts +12 -0
- package/dist/src/node-server.js +7 -1
- package/dist/src/normalize-runtime.d.ts +29 -2
- package/dist/src/offline-age.d.ts +29 -0
- package/dist/src/one-line-cell.d.ts +20 -0
- package/dist/src/opencode-agent-node-pair.d.ts +25 -0
- package/dist/src/opencode-auth-login.d.ts +43 -0
- package/dist/src/opencode-launch-env.d.ts +13 -0
- package/dist/src/opencode-owner-mode.d.ts +6 -0
- package/dist/src/opencode-package-binary.d.ts +26 -0
- package/dist/src/opencode-pin.d.ts +44 -0
- package/dist/src/opencode-preset.d.ts +73 -0
- package/dist/src/opencode-runtime-binding.d.ts +30 -0
- package/dist/src/opencode-safe-root.d.ts +36 -0
- package/dist/src/opencode-smoke-env.d.ts +1 -0
- package/dist/src/outbound-attachments.d.ts +60 -0
- package/dist/src/outbound-tool-names.d.ts +1 -0
- package/dist/src/owned-roots.d.ts +58 -0
- package/dist/src/owner-env-file.d.ts +2 -0
- package/dist/src/package-mode-preflight.d.ts +41 -0
- package/dist/src/posix-codex-copresence.d.ts +8 -0
- package/dist/src/posix-modes.d.ts +36 -0
- package/dist/src/primary-network.d.ts +23 -0
- package/dist/src/private-state.d.ts +10 -0
- package/dist/src/process-telemetry.d.ts +12 -0
- package/dist/src/profile-serialize.d.ts +1 -0
- package/dist/src/project-key.d.ts +1 -0
- package/dist/src/reply-local-links.d.ts +47 -0
- package/dist/src/reply-originator.d.ts +20 -0
- package/dist/src/resume-runtime-infer.d.ts +18 -0
- package/dist/src/rules-file.d.ts +40 -0
- package/dist/src/secret-shell-guidance.d.ts +3 -0
- package/dist/src/session-status-class.d.ts +48 -0
- package/dist/src/sibling-agent-node.d.ts +23 -0
- package/dist/src/stale-socket.d.ts +118 -0
- package/dist/src/subcommand-redirect.d.ts +26 -0
- package/dist/src/task-trace.d.ts +33 -0
- package/dist/src/tmux-attach.d.ts +8 -0
- package/dist/src/tmux-capability.d.ts +58 -0
- package/dist/src/tmux-exact-target.d.ts +34 -0
- package/dist/src/tmux-pane-prompt.d.ts +22 -0
- package/dist/src/token-cli.d.ts +13 -0
- package/dist/src/tool-allowlist.d.ts +28 -0
- package/dist/src/unsafe-package-path-reason.d.ts +17 -0
- package/dist/src/win-launcher.d.ts +20 -0
- package/dist/src/windows-codex-copresence.d.ts +60 -0
- package/package.json +10 -5
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export interface CodexCopresenceProfileFields {
|
|
2
|
+
readonly runtime?: string;
|
|
3
|
+
readonly codexCopresence?: boolean;
|
|
4
|
+
readonly codexCopresenceFullAccess?: boolean;
|
|
5
|
+
readonly flags?: Record<string, unknown>;
|
|
6
|
+
/** Absolute project directory to launch the codex TUI in. Passed as
|
|
7
|
+
* `-C <dir>` to `codex resume`. Also cross-checked against hub-reported
|
|
8
|
+
* `session.project_dir` in Phase 4.3. */
|
|
9
|
+
readonly codexProjectDir?: string;
|
|
10
|
+
/** Which launch adapter to use in Phase 3.2. `"codex-standard"` = stock
|
|
11
|
+
* `codex app-server` + `codex resume`; `"codex-custom-wrapper"` = partner-team-class
|
|
12
|
+
* custom LLM API wrapper (hosted tool / compaction / image-output compat).
|
|
13
|
+
* Unknown / absent → Phase 0 fail-closed (unknown adapters must not fall
|
|
14
|
+
* through to a default that might not fit the node's real topology). */
|
|
15
|
+
readonly codexLaunchAdapter?: "codex-standard" | "codex-custom-wrapper";
|
|
16
|
+
/** Alias of the peer that will verify this node's identity in Phase 6.
|
|
17
|
+
* Peer MUST be (a) registered in the same network, (b) online at resume
|
|
18
|
+
* time, (c) not this node itself. Identity attestation uses a fresh
|
|
19
|
+
* Hub outbound `send_task` from THIS node's Bridge to <codexProbePeer>
|
|
20
|
+
* carrying a nonce; peer echoes the nonce back; CLI cross-checks Hub's
|
|
21
|
+
* recorded `from_name / from_node_id / to_name / to_node_id`.
|
|
22
|
+
*
|
|
23
|
+
* 🔴 self-loop is deliberately not accepted here — it cannot prove
|
|
24
|
+
* cross-node routing closure (design v7 Phase 6 = D, per the partner team
|
|
25
|
+
* 06cfb29a). Single-node users cannot run `anet node resume` in
|
|
26
|
+
* this initial cut; tracked at #1527. */
|
|
27
|
+
readonly codexProbePeer?: string;
|
|
28
|
+
}
|
|
29
|
+
/** #1521 — the three fields `anet node resume <alias>` will require on a
|
|
30
|
+
* codex-copresence node once the resume dispatcher lands (#1528, Draft).
|
|
31
|
+
* In this PR, only shape-level enumeration exists (see
|
|
32
|
+
* `missingCodexResumeFields` below); no CLI code reads that enumeration
|
|
33
|
+
* and the operator-facing remediation flow is deliberately deferred
|
|
34
|
+
* along with its real caller. */
|
|
35
|
+
export type CodexResumeRequiredField = "codexProjectDir" | "codexLaunchAdapter" | "codexProbePeer";
|
|
36
|
+
export declare const CODEX_RESUME_REQUIRED_FIELDS: readonly CodexResumeRequiredField[];
|
|
37
|
+
/** Enumerate which of the three resume-required fields are absent /
|
|
38
|
+
* wrong-shaped on this profile. Returns [] when all three are present
|
|
39
|
+
* and well-shaped.
|
|
40
|
+
*
|
|
41
|
+
* 🔴 SHAPE-ONLY validation:
|
|
42
|
+
* - codexProjectDir : string starting with `/`. This is a CHEAP typo
|
|
43
|
+
* filter, NOT the security gate. Phase 0 (in #1528) MUST additionally
|
|
44
|
+
* `realpath`/canonicalize + reject NUL, `/`, and any untrusted target
|
|
45
|
+
* before passing this value to `codex resume -C <dir>` (per the partner team
|
|
46
|
+
* 4bab8196: "startsWith('/') 不是最终安全门").
|
|
47
|
+
* - codexLaunchAdapter : enum membership.
|
|
48
|
+
* - codexProbePeer : Hub exact-alias lookup, so value MUST equal its own
|
|
49
|
+
* trim. Values with leading/trailing whitespace would fail Hub lookup
|
|
50
|
+
* 100% of the time; rejecting them at the shape layer is a witnessed-red
|
|
51
|
+
* canary rather than a permissive pass-through (per the partner team 048d0061 R2:
|
|
52
|
+
* "不要 pin 一个必然在 Hub exact lookup 阶段失败的 well-shaped 值").
|
|
53
|
+
* Liveness (registered + online + non-self) is a separate hub-side
|
|
54
|
+
* check in Phase 0.
|
|
55
|
+
*
|
|
56
|
+
* Deliberately NOT included: an operator-facing diagnostic helper. An
|
|
57
|
+
* earlier draft included `codexResumeMissingConfigHint` that referenced
|
|
58
|
+
* a `anet node config apply` verb which does not exist in the tree —
|
|
59
|
+
* 外部团队 4bab8196 blocked it as the exact "存在 ≠ 会执行" antipattern.
|
|
60
|
+
* The diagnostic lands with its real caller in a later PR that either
|
|
61
|
+
* (a) implements `anet node config apply` first, or (b) reworks the
|
|
62
|
+
* diagnostic to reference existing commands only. */
|
|
63
|
+
export declare function missingCodexResumeFields(profile: CodexCopresenceProfileFields): CodexResumeRequiredField[];
|
|
64
|
+
export declare const CODEX_COPRESENCE_RUNTIME = "codex-app-server";
|
|
65
|
+
/**
|
|
66
|
+
* Should this `anet node start` bring up the co-presence stack?
|
|
67
|
+
*
|
|
68
|
+
* The flag still works for a one-off; the profile field is what makes the
|
|
69
|
+
* second start a single command.
|
|
70
|
+
*/
|
|
71
|
+
export declare function codexCopresenceRequested(flagPassed: boolean, profile: CodexCopresenceProfileFields): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* True when a plain `anet node start` just became enough for this node — i.e.
|
|
74
|
+
* the flag was passed and the profile had not recorded it yet. Callers persist
|
|
75
|
+
* `codexCopresence: true` and tell the user they can drop the flag.
|
|
76
|
+
*/
|
|
77
|
+
export declare function shouldPersistCodexCopresence(flagPassed: boolean, profile: CodexCopresenceProfileFields): boolean;
|
|
78
|
+
export interface CodexCopresencePosture {
|
|
79
|
+
readonly sandboxMode: "danger-full-access" | "read-only";
|
|
80
|
+
readonly approvalPolicy: "never" | "on-request";
|
|
81
|
+
/** Set when the node asked for full access and is NOT getting it. */
|
|
82
|
+
readonly downgradeNotice?: string;
|
|
83
|
+
/** Set when a remembered grant (not this invocation's flag) opened it up. */
|
|
84
|
+
readonly grantedFromProfile: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resolve the sandbox the co-presence app-server runs under.
|
|
88
|
+
*
|
|
89
|
+
* Precedence: this invocation's flag → a grant already recorded on the profile
|
|
90
|
+
* → read-only. `flags.sandboxMode` alone never opens the sandbox; it only
|
|
91
|
+
* decides whether staying closed is worth telling the user about.
|
|
92
|
+
*/
|
|
93
|
+
export declare function codexCopresencePosture(dangerFlagPassed: boolean, profile: CodexCopresenceProfileFields, displayName?: string): CodexCopresencePosture;
|
|
94
|
+
/** True when an explicit grant should be written to the profile for next time. */
|
|
95
|
+
export declare function shouldPersistCodexFullAccess(dangerFlagPassed: boolean, profile: CodexCopresenceProfileFields): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* What `anet node create --runtime codex-app-server` should record, so that a
|
|
98
|
+
* later `anet node start <name>` is a single command with no flag.
|
|
99
|
+
*
|
|
100
|
+
* Shape copied from opencode, which already does exactly this at create time:
|
|
101
|
+
*
|
|
102
|
+
* ...(runtime === "opencode-cli"
|
|
103
|
+
* ? { opencodeMode: opts.mode === "copresence" || opts.copresence === "true"
|
|
104
|
+
* ? "copresence" : "headless" }
|
|
105
|
+
* : {}),
|
|
106
|
+
*
|
|
107
|
+
* Deliberately NOT keyed on which alias the operator typed. `codex-tui`,
|
|
108
|
+
* `codex-appserver` and `codex-app-server` are documented as aliases of one
|
|
109
|
+
* runtime (agent-node/src/cli.ts); giving one of them a different default would
|
|
110
|
+
* quietly break that contract, and "I typed the short name" is not a reliable
|
|
111
|
+
* statement of intent. Opting in stays explicit, exactly as it is for opencode.
|
|
112
|
+
*/
|
|
113
|
+
export declare function codexCopresenceCreateFields(normalizedRuntime: string | undefined, copresenceOpt: string | boolean | undefined): {
|
|
114
|
+
codexCopresence?: true;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* One line at create time for a node that will start headless.
|
|
118
|
+
*
|
|
119
|
+
* NOT keyed on which alias the operator typed: by the time create builds the
|
|
120
|
+
* profile, `opts.runtime` has already been normalized to `codex-app-server`, so
|
|
121
|
+
* `codex-tui` is simply not recoverable here — a hint that tried to read it
|
|
122
|
+
* would never fire. (It didn't; that is how this was found.) Keying on the
|
|
123
|
+
* runtime instead also keeps the aliases true synonyms.
|
|
124
|
+
*/
|
|
125
|
+
export declare function codexCopresenceCreateHint(normalizedRuntime: string | undefined, copresenceOpt: string | boolean | undefined, displayName: string): string | undefined;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface CodexRecoveryVerification {
|
|
2
|
+
method: "thread/start" | "thread/resume";
|
|
3
|
+
threadId: string;
|
|
4
|
+
verifiedAt: string;
|
|
5
|
+
historyTurnCount: number;
|
|
6
|
+
historyFingerprint: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CodexRecoveryBackup {
|
|
9
|
+
backupDir: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
stateFiles: string[];
|
|
12
|
+
}
|
|
13
|
+
/** Transaction boundary shared by Windows and POSIX cutovers: the snapshot
|
|
14
|
+
* cannot begin until every authoritative state writer has quiesced. */
|
|
15
|
+
export declare function quiesceThenSnapshot<T>(quiesce: () => Promise<void>, snapshot: () => T): Promise<T>;
|
|
16
|
+
/** A stored thread is never considered resumed until app-server reads the
|
|
17
|
+
* exact thread back with persisted history. This is deliberately stricter
|
|
18
|
+
* than accepting a successful thread/resume RPC response. */
|
|
19
|
+
export declare function verifyCodexThreadHistory(method: "thread/start" | "thread/resume", expectedThreadId: string, readResult: unknown, now?: Date): CodexRecoveryVerification;
|
|
20
|
+
export declare function resumeAndVerifyCodexThread(threadId: string, request: (method: string, params: Record<string, unknown>) => Promise<unknown>): Promise<CodexRecoveryVerification>;
|
|
21
|
+
/** Private, node-local recovery point. config-recovery.json is deliberately
|
|
22
|
+
* redacted non-credential audit/recovery metadata, not an identity backup.
|
|
23
|
+
* Identity recovery relies on leaving the original node config and CODEX_HOME
|
|
24
|
+
* in place. Credentials are never copied into this snapshot. */
|
|
25
|
+
export declare function backupCodexRecoveryState(opts: {
|
|
26
|
+
nodeDir: string;
|
|
27
|
+
codexHome: string;
|
|
28
|
+
now?: Date;
|
|
29
|
+
}): CodexRecoveryBackup;
|
|
30
|
+
export declare function codexTopologyAudit(profile: Record<string, any>, nodeDir: string, cwd: string): {
|
|
31
|
+
launchMode: string;
|
|
32
|
+
cwd: string;
|
|
33
|
+
codexHome: string;
|
|
34
|
+
remote: any;
|
|
35
|
+
threadId: any;
|
|
36
|
+
model: any;
|
|
37
|
+
flags: any;
|
|
38
|
+
lastRecoveryVerification: any;
|
|
39
|
+
lastRecoveryBackup: {
|
|
40
|
+
createdAt: any;
|
|
41
|
+
stateFiles: any;
|
|
42
|
+
} | null;
|
|
43
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type CopresenceThreadPlan = {
|
|
2
|
+
method: "thread/resume";
|
|
3
|
+
params: {
|
|
4
|
+
threadId: string;
|
|
5
|
+
};
|
|
6
|
+
bootstrap: false;
|
|
7
|
+
} | {
|
|
8
|
+
method: "thread/start";
|
|
9
|
+
params: Record<string, never>;
|
|
10
|
+
bootstrap: true;
|
|
11
|
+
};
|
|
12
|
+
/** Restarting a node must preserve its conversation; only a virgin node starts one. */
|
|
13
|
+
export declare function copresenceThreadPlan(storedThreadId?: string): CopresenceThreadPlan;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { ReceiptCheck } from "./codex-lifecycle-receipt.js";
|
|
2
|
+
import type { RestartOutcome } from "./codex-lifecycle-restart.js";
|
|
3
|
+
export declare const SOURCE_KIND = "codex-login-profile";
|
|
4
|
+
/** `--source` 只接受 `codex-login:<profile-id>`。路径、`env:`、`-`(stdin)、绝对/相对路径都拒绝,错误里说清为什么。 */
|
|
5
|
+
export declare function parseSourceRef(raw: string): {
|
|
6
|
+
kind: typeof SOURCE_KIND;
|
|
7
|
+
profileId: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function shortHash(value: string, length?: number): string;
|
|
10
|
+
/** host_id:machine-id(有则用)+ hostname 的不可逆摘要;registry entry 绑定它,拷到别的机器就不认。 */
|
|
11
|
+
export declare function hostIdOf(machineId: string | null, hostname: string): string;
|
|
12
|
+
export interface ChatgptAuthShape {
|
|
13
|
+
auth_mode?: unknown;
|
|
14
|
+
tokens?: {
|
|
15
|
+
account_id?: unknown;
|
|
16
|
+
} | null;
|
|
17
|
+
OPENAI_API_KEY?: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** 只认 ChatGPT 登录:auth_mode=chatgpt 且 tokens.account_id 是 36 位 uuid;指纹 = sha256(account_id) 前 16 位。 */
|
|
20
|
+
export declare function accountFingerprint(auth: ChatgptAuthShape): string;
|
|
21
|
+
export interface RegistryEntry {
|
|
22
|
+
schema_version: 1;
|
|
23
|
+
profile_id: string;
|
|
24
|
+
provider: "openai-chatgpt";
|
|
25
|
+
host_id: string;
|
|
26
|
+
/** 由 registry 目录解析的相对引用;从不是绝对路径。 */
|
|
27
|
+
credential_ref: string;
|
|
28
|
+
account_fingerprint: string;
|
|
29
|
+
created_at: string;
|
|
30
|
+
last_model_probe_at: string | null;
|
|
31
|
+
last_model_probe_status: ProbeStatus | null;
|
|
32
|
+
revoked: boolean;
|
|
33
|
+
disabled: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface Registry {
|
|
36
|
+
schema_version: 1;
|
|
37
|
+
host_id: string;
|
|
38
|
+
profiles: Record<string, RegistryEntry>;
|
|
39
|
+
}
|
|
40
|
+
export type ProbeStatus = "ok" | "auth" | "quota" | "model" | "unknown";
|
|
41
|
+
export declare function credentialRefFor(profileId: string): string;
|
|
42
|
+
export declare function credentialPath(registryDir: string, entry: RegistryEntry): string;
|
|
43
|
+
export declare function readRegistry(registryDir: string, hostId: string): Registry;
|
|
44
|
+
export declare function writeRegistry(registryDir: string, reg: Registry): void;
|
|
45
|
+
/** 解析一个 profile:必须存在、未 revoked/disabled、host_id 一致、凭据文件在且 0600。返回凭据路径(只在进程内用,不进 receipt)。 */
|
|
46
|
+
export declare function resolveProfile(registryDir: string, reg: Registry, profileId: string, hostId: string): {
|
|
47
|
+
entry: RegistryEntry;
|
|
48
|
+
credentialFile: string;
|
|
49
|
+
};
|
|
50
|
+
/** 把一次 fresh 模型请求的结果归类;归不进已知类的一律 unknown(unknown 也 STOP,不猜)。 */
|
|
51
|
+
export declare function classifyProbe(exitCode: number | null, stdout: string, stderr: string, expected?: string): ProbeStatus;
|
|
52
|
+
export declare function backupRefFor(receiptId: string): string;
|
|
53
|
+
/** rollback 只认 `receipt:<id>`,且只在该节点的 receipts/ 目录里解析;调用方不能另指文件。 */
|
|
54
|
+
export declare function backupPathFor(nodeDir: string, backupRef: string): string;
|
|
55
|
+
export interface InstallActions {
|
|
56
|
+
/** 目标节点 before 核对:返回 fail 的 key(空 = 可继续)。 */
|
|
57
|
+
preflightBlocks(): Promise<string[]>;
|
|
58
|
+
/** 目标当前 auth 指纹(没有 auth.json → null)。 */
|
|
59
|
+
currentFingerprint(): Promise<string | null>;
|
|
60
|
+
/** 在隔离 staging HOME 里用该 profile 发一次 fresh 模型请求。 */
|
|
61
|
+
probe(): Promise<{
|
|
62
|
+
status: ProbeStatus;
|
|
63
|
+
detail: string;
|
|
64
|
+
}>;
|
|
65
|
+
/** 备份目标 auth.json → backup_ref(0600)。 */
|
|
66
|
+
backup(): Promise<{
|
|
67
|
+
backupRef: string;
|
|
68
|
+
}>;
|
|
69
|
+
/** 把 profile 凭据装进目标 CODEX_HOME(0600,原子)。 */
|
|
70
|
+
install(): Promise<void>;
|
|
71
|
+
/** 完整重启(PR-B 状态机),返回其 outcome。 */
|
|
72
|
+
restart(): Promise<RestartOutcome>;
|
|
73
|
+
/** 从 backup_ref 恢复 auth.json。 */
|
|
74
|
+
restore(backupRef: string): Promise<void>;
|
|
75
|
+
/** 探针在 registry 里的回写(时间 + 状态)。 */
|
|
76
|
+
recordProbe(status: ProbeStatus): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
export interface InstallInput {
|
|
79
|
+
profileId: string;
|
|
80
|
+
sourceFingerprint: string;
|
|
81
|
+
}
|
|
82
|
+
export interface InstallOutcome {
|
|
83
|
+
checks: ReceiptCheck[];
|
|
84
|
+
stoppedAt: string;
|
|
85
|
+
rolledBack: boolean;
|
|
86
|
+
backupRef: string | null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* account install 状态机:preflight → fresh 探针(401/quota/模型不兼容/unknown 都 STOP,目标一字未动)→ 备份 → 安装 →
|
|
90
|
+
* 完整重启(含 verify)→ 目标指纹 == 源指纹。安装后任一步失败 → 恢复备份 + 再重启一次(回滚),receipt 记两段。
|
|
91
|
+
*/
|
|
92
|
+
export declare function runAccountInstall(input: InstallInput, a: InstallActions): Promise<InstallOutcome>;
|
|
93
|
+
export interface RollbackActions {
|
|
94
|
+
/** 读原 install receipt;返回它的 backup_ref 与当时的 target_previous_fingerprint。 */
|
|
95
|
+
readInstallReceipt(): Promise<{
|
|
96
|
+
backupRef: string;
|
|
97
|
+
targetPreviousFingerprint: string | null;
|
|
98
|
+
} | null>;
|
|
99
|
+
backupExists(backupRef: string): Promise<boolean>;
|
|
100
|
+
restore(backupRef: string): Promise<void>;
|
|
101
|
+
restart(): Promise<RestartOutcome>;
|
|
102
|
+
currentFingerprint(): Promise<string | null>;
|
|
103
|
+
}
|
|
104
|
+
export declare function runRollback(a: RollbackActions): Promise<InstallOutcome>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1856 PR-E — `anet node codex canary <alias>...`:批量只读体检,**顺序跑、第一个 FAIL 即停**。
|
|
3
|
+
* 批量重启 / 换账号之前先 canary;后面的节点一个都不碰,汇总里明确写"未跑"。纯逻辑,verify 由调用方注入。
|
|
4
|
+
*/
|
|
5
|
+
export interface CanaryNodeResult {
|
|
6
|
+
readonly alias: string;
|
|
7
|
+
readonly verdict: "PASS" | "FAIL";
|
|
8
|
+
readonly blocking: readonly string[];
|
|
9
|
+
readonly receiptPath: string | null;
|
|
10
|
+
readonly ms: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CanarySummary {
|
|
13
|
+
readonly verdict: "PASS" | "FAIL";
|
|
14
|
+
readonly ran: readonly CanaryNodeResult[];
|
|
15
|
+
/** 因前面 FAIL 而没跑的节点(顺序保留)。 */
|
|
16
|
+
readonly skipped: readonly string[];
|
|
17
|
+
readonly stoppedAt: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function runCanary(aliases: readonly string[], verifyOne: (alias: string) => Promise<Omit<CanaryNodeResult, "alias" | "ms">>, now?: () => number): Promise<CanarySummary>;
|
|
20
|
+
export declare function formatCanarySummary(s: CanarySummary): string;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { PreflightFacts, ProcessFact, RolloutFact } from "./codex-lifecycle-preflight";
|
|
2
|
+
export interface FactPrimitives {
|
|
3
|
+
/** tmux pane pid of a session, or null when the session is not running. */
|
|
4
|
+
tmuxPanePid(session: string): number | null;
|
|
5
|
+
/** all pids (Linux /proc); [] elsewhere */
|
|
6
|
+
listPids(): number[];
|
|
7
|
+
procStatPpid(pid: number): number | null;
|
|
8
|
+
procCwd(pid: number): string | null;
|
|
9
|
+
procArgv(pid: number): string[] | null;
|
|
10
|
+
procEnviron(pid: number): Record<string, string> | null;
|
|
11
|
+
/** pid listening on a loopback TCP port, or null (free / unknown) */
|
|
12
|
+
listeningPid(port: number): number | null;
|
|
13
|
+
/** hub roster: alias → node_id, or null when unreachable */
|
|
14
|
+
hubNodeIdFor(alias: string): Promise<string | null>;
|
|
15
|
+
}
|
|
16
|
+
export declare function realPrimitives(opts: {
|
|
17
|
+
hub: string;
|
|
18
|
+
token: string;
|
|
19
|
+
networkId?: string;
|
|
20
|
+
}): FactPrimitives;
|
|
21
|
+
export declare function envFileTokenFingerprint(codexHome: string): string | null;
|
|
22
|
+
/** rollout-*-<threadId>.jsonl under CODEX_HOME/sessions/**;精确后缀匹配,不做前缀/最近猜测。 */
|
|
23
|
+
export declare function findRollouts(codexHome: string, threadId: string | null): RolloutFact[];
|
|
24
|
+
/** 从 pane pid 往下找子孙进程(含自身),按 pid 升序。 */
|
|
25
|
+
export declare function descendants(prim: FactPrimitives, rootPid: number): number[];
|
|
26
|
+
export declare function processFact(prim: FactPrimitives, pid: number): ProcessFact;
|
|
27
|
+
export interface GatherInput {
|
|
28
|
+
alias: string;
|
|
29
|
+
nodeId: string | null;
|
|
30
|
+
nodeDir: string;
|
|
31
|
+
codexHome: string;
|
|
32
|
+
configToken: string | null;
|
|
33
|
+
codexProjectDir: string | null;
|
|
34
|
+
codexThreadId: string | null;
|
|
35
|
+
codexAppServerUrl: string | null;
|
|
36
|
+
sessions: {
|
|
37
|
+
appsrv: string;
|
|
38
|
+
bridge: string;
|
|
39
|
+
tui: string;
|
|
40
|
+
};
|
|
41
|
+
recordedPids: {
|
|
42
|
+
appsrv: number | null;
|
|
43
|
+
bridge: number | null;
|
|
44
|
+
tui: number | null;
|
|
45
|
+
};
|
|
46
|
+
markerUuid: string | null;
|
|
47
|
+
}
|
|
48
|
+
/** ⑨ goals.json → 状态摘要 + 内容指纹。没有文件 = none(没派过目标);有文件但 schema 不认识/读不到 = unknown(restart 必须 STOP)。 */
|
|
49
|
+
export declare function goalsFileState(nodeDir: string): {
|
|
50
|
+
state: "active" | "stalled" | "paused" | "achieved" | "none" | "unknown";
|
|
51
|
+
fingerprint: string | null;
|
|
52
|
+
};
|
|
53
|
+
export declare function gatherCodexFacts(prim: FactPrimitives, input: GatherInput): Promise<PreflightFacts>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ReceiptCheck } from "./codex-lifecycle-receipt.js";
|
|
2
|
+
/** Codex 的 thread id 是 UUIDv7(时间有序);fork 出的新 id 也按 v7 生成,便于按文件名/id 排序时落在源之后。 */
|
|
3
|
+
export declare function uuidV7(nowMs: number, rand: Uint8Array): string;
|
|
4
|
+
/** codex 的 rollout 路径:sessions/YYYY/MM/DD/rollout-YYYY-MM-DDTHH-MM-SS-<id>.jsonl(UTC)。 */
|
|
5
|
+
export declare function forkRolloutPath(codexHome: string, now: Date, threadId: string): string;
|
|
6
|
+
/** CODEX_HOME 里哪些文件随 fork 走。显式白名单;env 文件(含源节点 CommHub token)、历史、sqlite、缓存一律不带。 */
|
|
7
|
+
export declare const FORK_HOME_COPY: readonly {
|
|
8
|
+
name: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
mode: number;
|
|
11
|
+
}[];
|
|
12
|
+
export declare const FORK_HOME_NEVER_COPY: readonly string[];
|
|
13
|
+
export interface RolloutRewriteResult {
|
|
14
|
+
readonly lines: number;
|
|
15
|
+
readonly bytesIn: number;
|
|
16
|
+
readonly bytesOut: number;
|
|
17
|
+
/** 源 thread id 改写次数(定长,不改字节数)。 */
|
|
18
|
+
readonly replacements: number;
|
|
19
|
+
/** `"cwd":"<源目录>"` 改写次数(session_meta + 每个 turn_context 都带;改成新 workdir,字节数按长度差变化)。 */
|
|
20
|
+
readonly cwdReplacements: number;
|
|
21
|
+
/** = bytesIn + cwdReplacements × (新 cwd 编码长度 − 旧 cwd 编码长度);fork_isolation 用它核对复制没有丢字节。 */
|
|
22
|
+
readonly expectedBytesOut: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 流式复制 rollout 并把源 thread id 逐处改成新 id(两者定长 36 字符 → 字节数不变,可作 fork_isolation 的证据)。
|
|
26
|
+
* 第一行校验失败时目标文件不存在(先读第一行再开写)。
|
|
27
|
+
*/
|
|
28
|
+
export declare function rewriteRollout(src: string, dst: string, oldId: string, newId: string, cwd?: {
|
|
29
|
+
from: string;
|
|
30
|
+
to: string;
|
|
31
|
+
}): Promise<RolloutRewriteResult>;
|
|
32
|
+
export interface ForkSides {
|
|
33
|
+
readonly source: {
|
|
34
|
+
nodeId: string | null;
|
|
35
|
+
homeReal: string | null;
|
|
36
|
+
threadId: string | null;
|
|
37
|
+
alias: string;
|
|
38
|
+
rolloutInode: number | bigint | null;
|
|
39
|
+
rolloutBytes: number | null;
|
|
40
|
+
};
|
|
41
|
+
readonly target: {
|
|
42
|
+
nodeId: string | null;
|
|
43
|
+
homeReal: string | null;
|
|
44
|
+
threadId: string | null;
|
|
45
|
+
alias: string;
|
|
46
|
+
rolloutInode: number | bigint | null;
|
|
47
|
+
rolloutBytes: number | null;
|
|
48
|
+
envFilePresent: boolean;
|
|
49
|
+
};
|
|
50
|
+
readonly rewrite: RolloutRewriteResult | null;
|
|
51
|
+
}
|
|
52
|
+
/** fork_isolation:身份 / HOME / thread / rollout 文件 / tmux 名五处都不同,且 rollout 是等长复制、没带 token 文件。 */
|
|
53
|
+
export declare function checkForkIsolation(s: ForkSides): ReceiptCheck;
|
|
54
|
+
/** gap 1 — `--workdir` used to have to pre-exist. Create it (recursively) when missing; still refuse a path that exists
|
|
55
|
+
* but is not a directory. Returns whether this call created it, so the receipt can say so. */
|
|
56
|
+
export declare function ensureForkWorkdir(path: string): {
|
|
57
|
+
created: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* gap 2 — codex records trust per workspace as `[projects."<abs path>"]` tables in config.toml. A copied config still
|
|
61
|
+
* names the **source** workspace, so the target keeps trusting (and, in the TUI, offering) the wrong directory.
|
|
62
|
+
* Rewrite only the table headers whose quoted path equals `from`, to `to`; every other line is left byte-identical.
|
|
63
|
+
* If a `[projects."<to>"]` table already exists, the source table is dropped instead of duplicated (TOML forbids
|
|
64
|
+
* defining a table twice). Line-aware on purpose: no global substitution of the path string elsewhere in the file.
|
|
65
|
+
*/
|
|
66
|
+
export declare function rewriteTrustedProjects(toml: string, from: string, to: string): {
|
|
67
|
+
text: string;
|
|
68
|
+
rewritten: number;
|
|
69
|
+
dropped: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* gap 3 — the last `turn_context` in a rollout names the model (and provider) the source ran on; codex resumes with
|
|
73
|
+
* that unless the target config says otherwise. Read it from the tail of the file (rollouts reach hundreds of MB;
|
|
74
|
+
* never load the whole thing) so `fork --model` can warn when the override differs.
|
|
75
|
+
*/
|
|
76
|
+
export declare function readLastTurnContextModel(rolloutPath: string, tailBytes?: number): {
|
|
77
|
+
model: string | null;
|
|
78
|
+
provider: string | null;
|
|
79
|
+
};
|
|
80
|
+
/** What the fork receipt records for the #1951 gaps, as one informational check (never blocks; `port` is the
|
|
81
|
+
* loopback port pre-assigned for the app-server, first start uses it as its preferred port and re-probes if taken). */
|
|
82
|
+
export interface ForkGapFacts {
|
|
83
|
+
readonly workdir_created: boolean;
|
|
84
|
+
readonly trusted_rewritten: number;
|
|
85
|
+
readonly trusted_dropped: number;
|
|
86
|
+
readonly model_override: string | null;
|
|
87
|
+
readonly source_last_model: string | null;
|
|
88
|
+
readonly port: number | null;
|
|
89
|
+
readonly agents_md_carried: boolean;
|
|
90
|
+
}
|
|
91
|
+
export declare function forkGapsCheck(f: ForkGapFacts): ReceiptCheck;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ReceiptCheck } from "./codex-lifecycle-receipt";
|
|
2
|
+
export interface RolloutFact {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly inode: number | bigint;
|
|
5
|
+
readonly bytes: number;
|
|
6
|
+
readonly mtimeMs: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ProcessFact {
|
|
9
|
+
readonly pid: number;
|
|
10
|
+
readonly cwd: string | null;
|
|
11
|
+
/** 子进程实际环境里的 CODEX_HOME(不是 wrapper 继承的那份 —— wrapper 环境不能作承重证据)。 */
|
|
12
|
+
readonly codexHome: string | null;
|
|
13
|
+
/** 子进程实际环境里 CommHub token 的短指纹;null = 没读到或该进程不该持有。 */
|
|
14
|
+
readonly tokenFingerprint: string | null;
|
|
15
|
+
/** 子进程环境里的 ANET_NODE_MARKER(copresence-identity 的身份 uuid);null = 没有。 */
|
|
16
|
+
readonly markerUuid: string | null;
|
|
17
|
+
readonly argv: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export interface PreflightFacts {
|
|
20
|
+
readonly alias: string;
|
|
21
|
+
readonly configNodeId: string | null;
|
|
22
|
+
/** hub 名册按 alias 精确查到的 node_id;null = hub 不可达或没这个 alias。 */
|
|
23
|
+
readonly hubNodeId: string | null;
|
|
24
|
+
readonly home: {
|
|
25
|
+
readonly dir: string;
|
|
26
|
+
readonly dirMode: number | null;
|
|
27
|
+
readonly authMode: number | null;
|
|
28
|
+
readonly authBytes: number | null;
|
|
29
|
+
readonly configTokenFingerprint: string | null;
|
|
30
|
+
readonly envFileTokenFingerprint: string | null;
|
|
31
|
+
};
|
|
32
|
+
readonly workdir: {
|
|
33
|
+
readonly configProjectDir: string | null;
|
|
34
|
+
readonly tuiCwd: string | null;
|
|
35
|
+
readonly tuiArgvDir: string | null;
|
|
36
|
+
readonly bridgeProjectDir: string | null;
|
|
37
|
+
readonly statusBarDir: string | null;
|
|
38
|
+
};
|
|
39
|
+
readonly session: {
|
|
40
|
+
readonly threadId: string | null;
|
|
41
|
+
/** CODEX_HOME 里文件名以 <threadId>.jsonl 结尾的 rollout 全集。 */
|
|
42
|
+
readonly rolloutMatches: readonly RolloutFact[];
|
|
43
|
+
};
|
|
44
|
+
readonly port: {
|
|
45
|
+
readonly port: number | null;
|
|
46
|
+
readonly owner: ProcessFact | null;
|
|
47
|
+
};
|
|
48
|
+
readonly topology: {
|
|
49
|
+
/** copresence-identity.json 里的身份 uuid;null = 没有 marker 文件。 */
|
|
50
|
+
readonly markerUuid: string | null;
|
|
51
|
+
/** marker 里记的 pid(采集时的观测提示,**不是**身份来源)与现在 tmux pane 的 pid。 */
|
|
52
|
+
readonly recorded: Readonly<Record<"appsrv" | "bridge" | "tui", number | null>>;
|
|
53
|
+
readonly live: Readonly<Record<"appsrv" | "bridge" | "tui", number | null>>;
|
|
54
|
+
/** 每个 tmux 段下带环境的子进程各自的 ANET_NODE_MARKER。 */
|
|
55
|
+
readonly liveMarkers: Readonly<Record<"appsrv" | "bridge" | "tui", readonly (string | null)[]>>;
|
|
56
|
+
/** 每个 tmux 段下带环境的子进程各自的 CODEX_HOME(realpath)。 */
|
|
57
|
+
readonly liveHomes: Readonly<Record<"appsrv" | "bridge" | "tui", readonly (string | null)[]>>;
|
|
58
|
+
};
|
|
59
|
+
readonly goal: {
|
|
60
|
+
readonly state: "active" | "stalled" | "paused" | "achieved" | "none" | "unknown";
|
|
61
|
+
};
|
|
62
|
+
readonly children: readonly ProcessFact[];
|
|
63
|
+
readonly expectedTokenFingerprint: string | null;
|
|
64
|
+
}
|
|
65
|
+
export declare function checkIdentity(f: PreflightFacts): ReceiptCheck;
|
|
66
|
+
export declare function checkHome(f: PreflightFacts): ReceiptCheck;
|
|
67
|
+
export declare function checkWorkdir(f: PreflightFacts): ReceiptCheck;
|
|
68
|
+
export declare function checkSession(f: PreflightFacts): ReceiptCheck;
|
|
69
|
+
export declare function rolloutSnapshot(f: PreflightFacts): ReceiptCheck;
|
|
70
|
+
export declare function compareRollout(before: RolloutFact, after: RolloutFact | null): ReceiptCheck;
|
|
71
|
+
export declare function checkPortOwner(f: PreflightFacts): ReceiptCheck;
|
|
72
|
+
export declare function checkChildEnv(f: PreflightFacts): ReceiptCheck;
|
|
73
|
+
export declare function checkGoalState(f: PreflightFacts): ReceiptCheck;
|
|
74
|
+
export declare function checkTopology(f: PreflightFacts): ReceiptCheck;
|
|
75
|
+
export declare function evaluateCodexPreflight(f: PreflightFacts): ReceiptCheck[];
|
|
76
|
+
/** verify = preflight + 子进程环境 + 跨节点身份验收(identity_attested 由调用方注入;PR-A 里没有探针时给 unknown)。 */
|
|
77
|
+
export declare function evaluateCodexVerify(f: PreflightFacts, identityAttested: ReceiptCheck): ReceiptCheck[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type CheckStatus = "pass" | "fail" | "unknown";
|
|
2
|
+
export interface ReceiptCheck {
|
|
3
|
+
readonly key: string;
|
|
4
|
+
readonly status: CheckStatus;
|
|
5
|
+
/** 一句人话:pass 说核到了什么,fail 说差在哪,unknown 说为什么量不到。 */
|
|
6
|
+
readonly detail: string;
|
|
7
|
+
/** 可复核的证据(路径、inode、字节数、短指纹……);不得含凭据。 */
|
|
8
|
+
readonly evidence?: Readonly<Record<string, unknown>>;
|
|
9
|
+
}
|
|
10
|
+
export type LifecycleVerb = "preflight" | "verify" | "start" | "restart" | "resume" | "fork" | "account-install" | "rollback";
|
|
11
|
+
export interface LifecycleReceipt {
|
|
12
|
+
readonly format: "anet-codex-lifecycle-receipt/1";
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly verb: LifecycleVerb;
|
|
15
|
+
readonly alias: string;
|
|
16
|
+
readonly nodeId: string | null;
|
|
17
|
+
readonly startedAt: string;
|
|
18
|
+
readonly finishedAt: string;
|
|
19
|
+
readonly verdict: "PASS" | "FAIL";
|
|
20
|
+
/** FAIL 时阻塞的 check key(fail 与 unknown 都算)。 */
|
|
21
|
+
readonly blocking: readonly string[];
|
|
22
|
+
readonly checks: readonly ReceiptCheck[];
|
|
23
|
+
}
|
|
24
|
+
/** 每个动词要求哪些 check 必须 pass。preflight 只读,不要求 identity_attested(那是 verify 的活)。 */
|
|
25
|
+
export declare const REQUIRED_CHECKS: Readonly<Record<LifecycleVerb, readonly string[]>>;
|
|
26
|
+
export declare function shortFingerprint(value: string | undefined | null, length?: number): string | null;
|
|
27
|
+
export declare function redactReceipt<T>(value: T, key?: string): T;
|
|
28
|
+
export declare const INFORMATIONAL_PREFIXES: readonly string[];
|
|
29
|
+
export declare function receiptVerdict(verb: LifecycleVerb, checks: readonly ReceiptCheck[]): {
|
|
30
|
+
verdict: "PASS" | "FAIL";
|
|
31
|
+
blocking: string[];
|
|
32
|
+
};
|
|
33
|
+
export declare function buildReceipt(opts: {
|
|
34
|
+
verb: LifecycleVerb;
|
|
35
|
+
alias: string;
|
|
36
|
+
nodeId: string | null;
|
|
37
|
+
startedAt: Date;
|
|
38
|
+
finishedAt?: Date;
|
|
39
|
+
checks: readonly ReceiptCheck[];
|
|
40
|
+
}): LifecycleReceipt;
|
|
41
|
+
/** receipts 落在节点目录下 receipts/<id>.json,0600,先写临时文件再 rename(原子)。返回绝对路径。 */
|
|
42
|
+
export declare function writeReceipt(nodeDir: string, receipt: LifecycleReceipt): string;
|
|
43
|
+
/** 终端摘要:一行一 check,PASS/FAIL 在最后;不打印 evidence 里的长值。 */
|
|
44
|
+
export declare function formatReceiptSummary(receipt: LifecycleReceipt): string;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #1856 PR-B — `anet node codex start|restart|resume` 的确定性状态机。
|
|
3
|
+
*
|
|
4
|
+
* 零 LLM:每一步是「读事实 → 判 → 动作 → 写 receipt check」,顺序固定;所有副作用都经 `RestartActions`
|
|
5
|
+
* 注入,所以这个文件可以在纯单测里跑完整个流程(含失败与回滚分支)。
|
|
6
|
+
*
|
|
7
|
+
* 停:Bridge → TUI → App Server(反向于依赖:先断任务入口,再让 TUI 把 rollout 刷完,最后放掉端口)。
|
|
8
|
+
* 起:交给 `anet node start <alias> --copresence --tui-first`(App Server → 端口就绪 → exact-session
|
|
9
|
+
* TUI 完全恢复 → Bridge),再用 preflight/verify 复核 —— 起的顺序由启动器保证,这里只验证结果。
|
|
10
|
+
* 任一步 fail → 不再往下;若已停掉进程则尝试一次「回滚」= 按原配置再起一次;仍失败就留在已停状态,
|
|
11
|
+
* receipt 记录到哪一步、为什么,exit 2。绝不猜、绝不 fallback 到别的线程。
|
|
12
|
+
*/
|
|
13
|
+
import type { ReceiptCheck } from "./codex-lifecycle-receipt.js";
|
|
14
|
+
import type { RolloutFact } from "./codex-lifecycle-preflight.js";
|
|
15
|
+
export type RestartVerb = "start" | "restart" | "resume";
|
|
16
|
+
export type GoalState = "active" | "paused" | "stalled" | "achieved" | "none" | "unknown";
|
|
17
|
+
export type CopresenceRole = "bridge" | "tui" | "appsrv";
|
|
18
|
+
export interface GateResult {
|
|
19
|
+
/** 该阶段所有 check(preflight 或 verify 的输出)。 */
|
|
20
|
+
readonly checks: readonly ReceiptCheck[];
|
|
21
|
+
/** 该阶段 rollout 快照(session_exact 通过时才有)。 */
|
|
22
|
+
readonly rollout: RolloutFact | null;
|
|
23
|
+
/** 端口占用者(null = 空闲)。 */
|
|
24
|
+
readonly port: {
|
|
25
|
+
readonly port: number | null;
|
|
26
|
+
readonly ownerPid: number | null;
|
|
27
|
+
readonly ownerIsOurs: boolean | null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface RestartActions {
|
|
31
|
+
/** 只读核对(PR-A 的 preflight;`after` 阶段可带 identity_attested 变 verify)。 */
|
|
32
|
+
gate(phase: "before" | "after"): Promise<GateResult>;
|
|
33
|
+
/** goals.json 的状态摘要 + 内容指纹(unknown = 读不到/不认识的 schema)。 */
|
|
34
|
+
goalState(): Promise<{
|
|
35
|
+
state: GoalState;
|
|
36
|
+
fingerprint: string | null;
|
|
37
|
+
}>;
|
|
38
|
+
/** 三个 tmux 会话谁还活着。 */
|
|
39
|
+
liveSessions(): Promise<Readonly<Record<CopresenceRole, boolean>>>;
|
|
40
|
+
/** 杀掉一个角色的 tmux 会话并等它消失;ok=false 时 detail 说为什么。 */
|
|
41
|
+
stopSession(role: CopresenceRole): Promise<{
|
|
42
|
+
ok: boolean;
|
|
43
|
+
detail: string;
|
|
44
|
+
}>;
|
|
45
|
+
/** 等 rollout 文件字节数稳定(TUI 退出后大 rollout 还在刷盘);返回最终快照。 */
|
|
46
|
+
waitRolloutSettled(before: RolloutFact | null): Promise<RolloutFact | null>;
|
|
47
|
+
/** 等端口空闲;超时仍被占用时给出占用者 pid 与「是不是我们自己的 app-server」。 */
|
|
48
|
+
waitPortFree(): Promise<{
|
|
49
|
+
free: boolean;
|
|
50
|
+
ownerPid: number | null;
|
|
51
|
+
ownerIsOurs: boolean | null;
|
|
52
|
+
}>;
|
|
53
|
+
/** 对已核实属于本节点的残留 pid 发 TERM(定向,绝不 pkill -f)。 */
|
|
54
|
+
termOwnedPid(pid: number): Promise<{
|
|
55
|
+
ok: boolean;
|
|
56
|
+
detail: string;
|
|
57
|
+
}>;
|
|
58
|
+
/** 跑启动器(`anet node start --copresence --tui-first`);ok=false 时 detail 是它的尾部输出。 */
|
|
59
|
+
start(): Promise<{
|
|
60
|
+
ok: boolean;
|
|
61
|
+
detail: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** hub 上该 node_id 是否在超时内回到 online/idle。 */
|
|
64
|
+
waitHubOnline(): Promise<{
|
|
65
|
+
ok: boolean;
|
|
66
|
+
detail: string;
|
|
67
|
+
}>;
|
|
68
|
+
/** 跨节点 nonce 探针;未配置时返回 undefined(check 记 unknown)。 */
|
|
69
|
+
nonceProbe?: () => Promise<{
|
|
70
|
+
ok: boolean;
|
|
71
|
+
detail: string;
|
|
72
|
+
evidence?: Record<string, unknown>;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
export interface RestartOutcome {
|
|
76
|
+
readonly verb: RestartVerb;
|
|
77
|
+
readonly checks: readonly ReceiptCheck[];
|
|
78
|
+
/** 走到哪一步停下(PASS 时 = "done")。 */
|
|
79
|
+
readonly stoppedAt: string;
|
|
80
|
+
readonly rolledBack: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** before 阶段的门:required 里不许有 fail;unknown 允许(要重启的节点常常就是缺了一截进程)。 */
|
|
83
|
+
export declare function beforeGateBlocks(checks: readonly ReceiptCheck[]): string[];
|
|
84
|
+
/** 三个角色按依赖反向停;返回 stop_order check(顺序本身就是证据)。 */
|
|
85
|
+
export declare function orderedStop(actions: RestartActions, live: Readonly<Record<CopresenceRole, boolean>>): Promise<ReceiptCheck>;
|
|
86
|
+
export declare function runCodexRestart(verb: RestartVerb, actions: RestartActions): Promise<RestartOutcome>;
|