pi-better-server 0.0.0-stage → 0.1.0
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 +615 -2
- package/codex-plugin/.agents/plugins/marketplace.json +17 -0
- package/codex-plugin/plugins/pi-remote/.codex-plugin/plugin.json +20 -0
- package/codex-plugin/plugins/pi-remote/.mcp.json +13 -0
- package/codex-plugin/plugins/pi-remote/server.mjs +118 -0
- package/codex-plugin/plugins/pi-remote/skills/pi-remote/SKILL.md +19 -0
- package/package.json +60 -4
- package/scripts/bootstrap-host.sh +107 -0
- package/scripts/private-runtime/format.ts +65 -0
- package/scripts/private-runtime/installer.ts +166 -0
- package/scripts/private-runtime/package-lock.json +1491 -0
- package/scripts/private-runtime/package.json +17 -0
- package/scripts/test-on-pi.sh +34 -0
- package/src/cli-args.ts +38 -0
- package/src/cli.ts +90 -0
- package/src/client.ts +152 -0
- package/src/codex/adapter.ts +299 -0
- package/src/codex/app-server.ts +112 -0
- package/src/codex/daemon.ts +232 -0
- package/src/codex/deliver.ts +103 -0
- package/src/codex/preflight.ts +15 -0
- package/src/codex/provider.ts +55 -0
- package/src/codex/return.ts +110 -0
- package/src/codex/rollout.ts +160 -0
- package/src/codex/runtime.ts +126 -0
- package/src/codex/ws-unix.ts +112 -0
- package/src/companion.ts +96 -0
- package/src/control.ts +85 -0
- package/src/core/adapter.ts +109 -0
- package/src/core/bundle.ts +764 -0
- package/src/core/exclusions.ts +53 -0
- package/src/core/move-host.ts +268 -0
- package/src/core/ownership.ts +135 -0
- package/src/core/transfer.ts +73 -0
- package/src/daemon-owner.ts +130 -0
- package/src/detach/detach.ts +150 -0
- package/src/detach/extension.ts +244 -0
- package/src/detach/local-sink.ts +203 -0
- package/src/detach/local-source.ts +133 -0
- package/src/detach/local-state.ts +87 -0
- package/src/detach/recover.ts +53 -0
- package/src/event-log.ts +163 -0
- package/src/git.ts +35 -0
- package/src/handshake.ts +57 -0
- package/src/hosted-session.ts +576 -0
- package/src/index.ts +31 -0
- package/src/lifecycle-config.ts +29 -0
- package/src/maintenance.ts +317 -0
- package/src/move/auth.ts +16 -0
- package/src/move/orchestrate.ts +163 -0
- package/src/move/pi-adapter.ts +181 -0
- package/src/move/preflight.ts +197 -0
- package/src/move/service.ts +16 -0
- package/src/paths.ts +52 -0
- package/src/protocol.ts +212 -0
- package/src/registry.ts +559 -0
- package/src/remote/answer.ts +95 -0
- package/src/remote/attach-codex.ts +41 -0
- package/src/remote/attach.ts +41 -0
- package/src/remote/console.ts +126 -0
- package/src/remote/context.ts +75 -0
- package/src/remote/cursors.ts +36 -0
- package/src/remote/ls.ts +44 -0
- package/src/remote/move.ts +85 -0
- package/src/remote/new.ts +37 -0
- package/src/remote/process-runner.ts +51 -0
- package/src/remote/recover.ts +35 -0
- package/src/remote/return.ts +49 -0
- package/src/remote/sessions.ts +33 -0
- package/src/remote/steer.ts +40 -0
- package/src/remote/tail.ts +91 -0
- package/src/remote/target.ts +313 -0
- package/src/remote-cli.ts +73 -0
- package/src/remote-client/connection-progress.ts +62 -0
- package/src/remote-client/extension.ts +368 -0
- package/src/remote-client/folder-browser.ts +165 -0
- package/src/remote-client/host.ts +127 -0
- package/src/remote-client/local-work.ts +62 -0
- package/src/remote-client/menu.ts +68 -0
- package/src/remote-client/packages.ts +331 -0
- package/src/remote-client/pi-1.2-bridge.ts +482 -0
- package/src/remote-client/profiles.ts +38 -0
- package/src/remote-client/remote-progress.ts +39 -0
- package/src/remote-client/session-browser.ts +267 -0
- package/src/remote-client/session.ts +1205 -0
- package/src/remote-client/ssh-hosts.ts +185 -0
- package/src/remote-client/transfer-command.ts +189 -0
- package/src/remote-client/upgrade-transport.ts +105 -0
- package/src/server.ts +398 -0
- package/src/session-activity.ts +173 -0
- package/src/shared-ssh-core/index.ts +950 -0
- package/src/startup/activation.ts +621 -0
- package/src/startup/admission.ts +98 -0
- package/src/startup/artifact.ts +65 -0
- package/src/startup/commands.ts +37 -0
- package/src/startup/ensure.ts +137 -0
- package/src/startup/install.ts +115 -0
- package/src/startup/managed-types.ts +61 -0
- package/src/startup/runtime.ts +138 -0
- package/src/ui-bridge.ts +124 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an agent has to provide for the shared move core (move-host.ts) to hand one
|
|
3
|
+
* of its sessions to another daemon. The core owns the bundle, the chunked
|
|
4
|
+
* transfer, the preflight call sites and the ownership/epoch bookkeeping; an
|
|
5
|
+
* adapter owns everything that is specific to one agent: where its session files
|
|
6
|
+
* live, whether it is mid-turn, how to stop it, how to register an imported one.
|
|
7
|
+
*
|
|
8
|
+
* No agent imports here. The Pi adapter is src/move/pi-adapter.ts.
|
|
9
|
+
*/
|
|
10
|
+
import { statSync } from "node:fs";
|
|
11
|
+
import { isAbsolute } from "node:path";
|
|
12
|
+
import type { BundleManifest, CreateBundleOptions } from "./bundle.ts";
|
|
13
|
+
import type { MoveCommand } from "../protocol.ts";
|
|
14
|
+
import type { OwnershipStore } from "./ownership.ts";
|
|
15
|
+
|
|
16
|
+
/** What the adapter hands the core to bundle a session. The core adds `outFile` and `ownership`. */
|
|
17
|
+
export type SessionBundleSpec = Pick<CreateBundleOptions, "cwd" | "agent" | "session" | "sessionFiles" | "stateFiles" | "baseRef" | "includeWorkspace" | "compression">;
|
|
18
|
+
|
|
19
|
+
export interface MovePreflightContext {
|
|
20
|
+
side: "source" | "target";
|
|
21
|
+
sessionId: string;
|
|
22
|
+
moveId: string;
|
|
23
|
+
/** Target only: the requested `--to-cwd`, if any. */
|
|
24
|
+
cwd?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface ImportRequest {
|
|
28
|
+
sessionId: string;
|
|
29
|
+
/** Original logical id in the bundle; different only for an explicit copy. */
|
|
30
|
+
sourceSessionId?: string;
|
|
31
|
+
moveId: string;
|
|
32
|
+
manifest: BundleManifest;
|
|
33
|
+
/** Directory holding the verified bundle members (`session/<name>`, `state/<name>`). Removed by the core afterwards. */
|
|
34
|
+
extractedDir: string;
|
|
35
|
+
/** The rebuilt workspace. */
|
|
36
|
+
cwd: string;
|
|
37
|
+
/** Agent-specific: bind the imported session to this model provider instead of the one it had (`move_begin`'s `rebindProvider`). */
|
|
38
|
+
rebindProvider?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A `move_preflight` request and what the adapter answers; the core adds the daemon id. Nothing is changed. */
|
|
42
|
+
export type ReadinessRequest = Extract<MoveCommand, { type: "move_preflight" }>;
|
|
43
|
+
export interface ReadinessReport {
|
|
44
|
+
checks: Array<{ name: string; ok: boolean; detail: string }>;
|
|
45
|
+
/** When the request names a session: a description of it for a pull. */
|
|
46
|
+
session?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface AgentMoveAdapter {
|
|
50
|
+
/** Matches `manifest.agent.kind` of bundles this adapter can import. */
|
|
51
|
+
readonly kind: string;
|
|
52
|
+
/** This daemon's ownership ledger. */
|
|
53
|
+
readonly ownership: OwnershipStore;
|
|
54
|
+
|
|
55
|
+
// ---- source side ----
|
|
56
|
+
hasSession(sessionId: string): boolean;
|
|
57
|
+
/** True while execution, prompt preflight, bash or background work is active. Pending inputs/dialogs must also refuse transfer. */
|
|
58
|
+
isBusy(sessionId: string): boolean;
|
|
59
|
+
/** Stop serving the session without forgetting it (it is fenced). */
|
|
60
|
+
stop(sessionId: string): Promise<void>;
|
|
61
|
+
/** Describe the session for bundling. Synchronous: nothing may change between this and the fence. */
|
|
62
|
+
bundleSession(sessionId: string): SessionBundleSpec;
|
|
63
|
+
/** The move succeeded elsewhere: close the session and keep a tombstone. */
|
|
64
|
+
retire(sessionId: string): Promise<void>;
|
|
65
|
+
/** The move failed or was aborted: serve the session again if it was running. */
|
|
66
|
+
resume(sessionId: string): Promise<void>;
|
|
67
|
+
|
|
68
|
+
// ---- target side ----
|
|
69
|
+
/** Throw for any existing session except a known, safely retired tombstone. */
|
|
70
|
+
assertCanImport(sessionId: string): void;
|
|
71
|
+
/** Throw if this bundle cannot be read by this daemon (agent kind, version). */
|
|
72
|
+
checkBundle(manifest: BundleManifest): void;
|
|
73
|
+
/** Capture what `restore` needs to undo `importSession`. */
|
|
74
|
+
snapshot(sessionId: string): unknown;
|
|
75
|
+
/** Register the session on this daemon, running. May throw; the core then calls `restore` if ownership was acquired. */
|
|
76
|
+
importSession(request: ImportRequest): Promise<void | { sessionFile?: string }>;
|
|
77
|
+
/** Undo a failed `importSession`. */
|
|
78
|
+
restore(sessionId: string, snapshot: unknown): Promise<void>;
|
|
79
|
+
|
|
80
|
+
/** Answer a `move_preflight` command (receiver checks, plus a session description for `pi-remote return`). */
|
|
81
|
+
readiness?(request: ReadinessRequest): Promise<ReadinessReport>;
|
|
82
|
+
|
|
83
|
+
/** Optional checks run before the source fences and before the target accepts a bundle. #477 supplies the Pi checks. */
|
|
84
|
+
preflight?(context: MovePreflightContext): void | Promise<void>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Session-only transfers may use a populated workspace, but never create one. */
|
|
88
|
+
export function assertExistingDirectory(cwd: string | undefined): asserts cwd is string {
|
|
89
|
+
if (!cwd || !isAbsolute(cwd)) throw new Error("Session-only transfer requires an existing absolute destination directory (toCwd)");
|
|
90
|
+
if (!statSync(cwd, { throwIfNoEntry: false })?.isDirectory()) throw new Error(`Session-only destination ${cwd} must be an existing directory`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Only the parsed header changes. Conversation entries and their parent ids stay intact. */
|
|
94
|
+
export function rewriteSessionTranscript(transcript: string, sourceId: string, destinationId: string, cwd: string): string {
|
|
95
|
+
const newline = transcript.indexOf("\n");
|
|
96
|
+
const first = newline === -1 ? transcript : transcript.slice(0, newline);
|
|
97
|
+
let header: Record<string, unknown>;
|
|
98
|
+
try {
|
|
99
|
+
header = JSON.parse(first);
|
|
100
|
+
} catch {
|
|
101
|
+
throw new Error("Invalid session transcript header");
|
|
102
|
+
}
|
|
103
|
+
if (!header || header.type !== "session" || (header.id !== sourceId && !(header.id === undefined && sourceId === destinationId))) {
|
|
104
|
+
throw new Error(`Transcript header must identify source session ${sourceId}`);
|
|
105
|
+
}
|
|
106
|
+
// A transferred transcript is self-contained; a source-host parent path would dangle.
|
|
107
|
+
const { parentSessionFile: _parentFile, parentSession: _parent, ...rest } = header;
|
|
108
|
+
return `${JSON.stringify({ ...rest, id: destinationId, cwd })}${newline === -1 ? "" : transcript.slice(newline)}`;
|
|
109
|
+
}
|