@neta-art/cohub-cli 8.2.0 → 8.3.1

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.
Files changed (76) hide show
  1. package/dist/commands/runtime.d.ts +0 -12
  2. package/dist/commands/runtime.js +129 -144
  3. package/dist/commands/search.js +3 -9
  4. package/dist/commands/spaces.js +5 -2
  5. package/dist/output.d.ts +6 -0
  6. package/dist/output.js +11 -0
  7. package/dist/runtime/codex-usage.d.ts +0 -2
  8. package/dist/runtime/codex-usage.js +0 -12
  9. package/dist/runtime/connection.d.ts +5 -5
  10. package/dist/runtime/connection.js +27 -16
  11. package/dist/runtime/harness.d.ts +8 -16
  12. package/dist/runtime/harness.js +1 -366
  13. package/dist/runtime/instance.d.ts +8 -1
  14. package/dist/runtime/instance.js +15 -8
  15. package/dist/runtime/launch.js +11 -5
  16. package/dist/runtime/native/adapters.d.ts +32 -0
  17. package/dist/runtime/native/adapters.js +79 -0
  18. package/dist/runtime/{native-archive.d.ts → native/archive.d.ts} +0 -3
  19. package/dist/runtime/{native-archive.js → native/archive.js} +2 -17
  20. package/dist/runtime/native/attach.d.ts +38 -0
  21. package/dist/runtime/native/attach.js +113 -0
  22. package/dist/runtime/native/codex-link.d.ts +40 -0
  23. package/dist/runtime/native/codex-link.js +249 -0
  24. package/dist/runtime/native/config.d.ts +16 -0
  25. package/dist/runtime/native/config.js +24 -0
  26. package/dist/runtime/native/daemon.d.ts +88 -0
  27. package/dist/runtime/native/daemon.js +367 -0
  28. package/dist/runtime/native/execution.d.ts +45 -0
  29. package/dist/runtime/native/execution.js +337 -0
  30. package/dist/runtime/native/identity.d.ts +9 -0
  31. package/dist/runtime/native/identity.js +15 -0
  32. package/dist/runtime/native/ingest.d.ts +241 -0
  33. package/dist/runtime/native/ingest.js +823 -0
  34. package/dist/runtime/native/install.d.ts +9 -0
  35. package/dist/runtime/native/install.js +113 -0
  36. package/dist/runtime/native/pi-extension.d.ts +35 -0
  37. package/dist/runtime/native/pi-extension.js +160 -0
  38. package/dist/runtime/native/pi-link.d.ts +67 -0
  39. package/dist/runtime/native/pi-link.js +238 -0
  40. package/dist/runtime/native/results.d.ts +41 -0
  41. package/dist/runtime/native/results.js +128 -0
  42. package/dist/runtime/native/sessions.d.ts +45 -0
  43. package/dist/runtime/native/sessions.js +92 -0
  44. package/dist/runtime/{native-transcript.d.ts → native/transcript.d.ts} +5 -5
  45. package/dist/runtime/{native-transcript.js → native/transcript.js} +37 -11
  46. package/dist/runtime/native/translate.d.ts +44 -0
  47. package/dist/runtime/native/translate.js +263 -0
  48. package/dist/runtime/native/transport.d.ts +7 -0
  49. package/dist/runtime/native/transport.js +16 -0
  50. package/dist/runtime/native/version.d.ts +5 -0
  51. package/dist/runtime/native/version.js +18 -0
  52. package/dist/runtime/presentation.d.ts +7 -10
  53. package/dist/runtime/presentation.js +35 -10
  54. package/dist/runtime/projection-store.d.ts +6 -13
  55. package/dist/runtime/projection-store.js +11 -74
  56. package/dist/runtime/supervisor.d.ts +2 -0
  57. package/dist/runtime/supervisor.js +36 -110
  58. package/dist/runtime/turn-projection.d.ts +1 -3
  59. package/dist/runtime/turn-projection.js +3 -10
  60. package/package.json +4 -5
  61. package/dist/runtime/native-attach.d.ts +0 -28
  62. package/dist/runtime/native-attach.js +0 -47
  63. package/dist/runtime/native-codex-hook.d.ts +0 -1
  64. package/dist/runtime/native-codex-hook.js +0 -28
  65. package/dist/runtime/native-install.d.ts +0 -21
  66. package/dist/runtime/native-install.js +0 -130
  67. package/dist/runtime/native-ipc.d.ts +0 -37
  68. package/dist/runtime/native-ipc.js +0 -118
  69. package/dist/runtime/native-pi-extension.d.ts +0 -20
  70. package/dist/runtime/native-pi-extension.js +0 -47
  71. package/dist/runtime/native-sync-store.d.ts +0 -116
  72. package/dist/runtime/native-sync-store.js +0 -495
  73. package/dist/runtime/native-sync.d.ts +0 -65
  74. package/dist/runtime/native-sync.js +0 -326
  75. package/dist/runtime/session-store.d.ts +0 -84
  76. package/dist/runtime/session-store.js +0 -601
@@ -1,118 +0,0 @@
1
- import { createConnection, createServer } from "node:net";
2
- import { mkdir, rm } from "node:fs/promises";
3
- import { dirname, join } from "node:path";
4
- import { nativeRuntimeRoot } from "./native-sync.js";
5
- import { currentIdentityKey } from "../space.js";
6
- import { canonicalRuntimeRoot, getRuntimeSpaceBinding } from "./space-binding.js";
7
- const MAX_LINE_BYTES = 4 * 1024 * 1024;
8
- const socketPath = (runtimeRoot) => join(runtimeRoot, "native", "daemon.sock");
9
- /**
10
- * `store: null` means the request was valid but nothing was applicable yet (an unbound
11
- * workspace, or a transcript a harness has not written). That is not a sync failure, so
12
- * clients stay silent instead of warning about it.
13
- */
14
- export async function nativeCaptureResponse(result) {
15
- if (!result.store)
16
- return { ok: false, skipped: true, message: "No native capture is pending" };
17
- return { ok: true, pendingTurns: (await result.store.status()).pendingTurns };
18
- }
19
- const parse = (raw) => {
20
- const value = JSON.parse(raw);
21
- if (value?.type !== "native.capture" || !["pi", "codex"].includes(value.harness)
22
- || typeof value.cwd !== "string" || typeof value.path !== "string" || typeof value.nativeSessionId !== "string"
23
- || value.origin !== undefined && value.origin !== "local_import"
24
- || value.sessionStartedAt !== undefined && typeof value.sessionStartedAt !== "string") {
25
- throw new Error("Invalid native daemon request");
26
- }
27
- return value;
28
- };
29
- export async function nativeDaemonSocketFor(cwd) {
30
- const identity = currentIdentityKey();
31
- if (!identity)
32
- return null;
33
- // A vanished workspace is unbound, not an error; the terminal has nothing left to sync.
34
- const root = await canonicalRuntimeRoot(cwd).catch((error) => { if (error.code === "ENOENT")
35
- return null; throw error; });
36
- if (!root)
37
- return null;
38
- const binding = await getRuntimeSpaceBinding(root, identity);
39
- return binding ? socketPath(nativeRuntimeRoot(binding.spaceId)) : null;
40
- }
41
- export async function requestNativeDaemon(input) {
42
- const path = await nativeDaemonSocketFor(input.cwd);
43
- // An unbound workspace is a normal state, not an error the terminal should surface.
44
- if (!path)
45
- return { ok: false, skipped: true, message: "Native Runtime is not bound" };
46
- return new Promise((resolve, reject) => {
47
- const socket = createConnection(path);
48
- let buffer = "";
49
- const timer = setTimeout(() => { socket.destroy(); reject(new Error("Native Runtime daemon timed out")); }, 15_000);
50
- const finish = (error, result) => {
51
- clearTimeout(timer);
52
- socket.destroy();
53
- if (error)
54
- reject(error);
55
- else
56
- resolve(result ?? { ok: false, message: "Empty daemon response" });
57
- };
58
- socket.once("error", (error) => finish(error));
59
- socket.on("data", (chunk) => {
60
- buffer += chunk.toString();
61
- if (Buffer.byteLength(buffer) > MAX_LINE_BYTES) {
62
- finish(new Error("Native daemon response too large"));
63
- return;
64
- }
65
- const newline = buffer.indexOf("\n");
66
- if (newline < 0)
67
- return;
68
- try {
69
- finish(undefined, JSON.parse(buffer.slice(0, newline)));
70
- }
71
- catch (error) {
72
- finish(error instanceof Error ? error : new Error(String(error)));
73
- }
74
- });
75
- socket.once("connect", () => socket.write(`${JSON.stringify({ type: "native.capture", ...input })}\n`));
76
- });
77
- }
78
- export async function serveNativeDaemon(input) {
79
- const path = socketPath(input.runtimeRoot);
80
- await mkdir(dirname(path), { recursive: true, mode: 0o700 });
81
- await rm(path, { force: true });
82
- const server = createServer((socket) => {
83
- let buffer = "";
84
- let closed = false;
85
- const respond = (value) => {
86
- if (closed)
87
- return;
88
- closed = true;
89
- socket.end(`${JSON.stringify(value)}\n`);
90
- };
91
- socket.setTimeout(20_000, () => socket.destroy());
92
- socket.once("error", () => { closed = true; });
93
- socket.on("data", (chunk) => {
94
- buffer += chunk.toString();
95
- if (Buffer.byteLength(buffer) > MAX_LINE_BYTES) {
96
- socket.destroy();
97
- return;
98
- }
99
- const newline = buffer.indexOf("\n");
100
- if (newline < 0)
101
- return;
102
- socket.removeAllListeners("data");
103
- void (async () => {
104
- const request = parse(buffer.slice(0, newline));
105
- const result = await input.handle(request);
106
- respond(await nativeCaptureResponse(result));
107
- })().catch((error) => respond({ ok: false, message: error instanceof Error ? error.message : String(error) }));
108
- });
109
- });
110
- await new Promise((resolve, reject) => {
111
- server.once("error", reject);
112
- server.listen(path, () => { server.removeListener("error", reject); resolve(); });
113
- });
114
- return async () => {
115
- await new Promise((resolve) => server.close(() => resolve()));
116
- await rm(path, { force: true });
117
- };
118
- }
@@ -1,20 +0,0 @@
1
- type PiContext = {
2
- cwd: string;
3
- sessionManager: {
4
- getSessionFile(): string | undefined;
5
- getSessionId(): string;
6
- getLeafId(): string | null;
7
- };
8
- abort(): void;
9
- isIdle(): boolean;
10
- ui: {
11
- notify(message: string, level: "info" | "warning" | "error"): void;
12
- setStatus(key: string, value: string | undefined): void;
13
- };
14
- };
15
- type PiExtension = {
16
- on(event: string, handler: (event: unknown, context: PiContext) => Promise<void> | void): void;
17
- };
18
- /** Thin native adapter. The Runtime Daemon owns Cohub auth, WS, retries and archives. */
19
- export default function cohubNativeExtension(pi: PiExtension): void;
20
- export {};
@@ -1,47 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { requestNativeDaemon } from "./native-ipc.js";
3
- /** Thin native adapter. The Runtime Daemon owns Cohub auth, WS, retries and archives. */
4
- export default function cohubNativeExtension(pi) {
5
- if (process.env.COHUB_TURN_ID || process.env.COHUB_EXECUTION_TOKEN)
6
- return;
7
- let context = null;
8
- let captures = Promise.resolve();
9
- let lastError = "";
10
- const report = (error) => {
11
- const message = error instanceof Error ? error.message : String(error);
12
- if (message !== lastError)
13
- context?.ui.notify(`Cohub sync pending: ${message}`, "warning");
14
- lastError = message;
15
- };
16
- const capture = (ctx, settled = false) => {
17
- context = ctx;
18
- const path = ctx.sessionManager.getSessionFile();
19
- if (!path)
20
- return Promise.resolve();
21
- captures = captures.then(async () => {
22
- // Pi persists the transcript lazily; a not-yet-created file is not a sync failure.
23
- if (!existsSync(path))
24
- return;
25
- const result = await requestNativeDaemon({ harness: "pi", cwd: ctx.cwd, path, nativeSessionId: ctx.sessionManager.getSessionId(), leafId: ctx.sessionManager.getLeafId(), settled });
26
- // Nothing to sync yet (unbound workspace, or config not installed) is silence, not a warning.
27
- if (!result.ok) {
28
- if (result.skipped)
29
- return;
30
- throw new Error(result.message);
31
- }
32
- ctx.ui.setStatus("cohub", "Cohub");
33
- lastError = "";
34
- }).catch(report);
35
- return captures;
36
- };
37
- pi.on("session_start", async (_event, ctx) => {
38
- await capture(ctx, ctx.isIdle());
39
- });
40
- pi.on("message_end", (_event, ctx) => capture(ctx));
41
- pi.on("agent_settled", (_event, ctx) => capture(ctx, true));
42
- pi.on("session_shutdown", async (_event, ctx) => {
43
- await captures;
44
- ctx.ui.setStatus("cohub", undefined);
45
- context = null;
46
- });
47
- }
@@ -1,116 +0,0 @@
1
- import type { NativeTurnBinding, NativeTurnComplete, NativeTurnStart, NativeTurnProgress } from "@neta-art/cohub";
2
- import { RuntimeArchiveStore, type ArchiveTransport } from "./archive-store.js";
3
- import type { NativeTranscript } from "./native-transcript.js";
4
- export declare const nativeIdentityHash: (identity: string) => string;
5
- export declare function nativeStableId(value: string): string;
6
- type NativeBinding = {
7
- version: 1;
8
- identity: string;
9
- spaceId: string;
10
- harness: "pi" | "codex";
11
- nativeSessionId: string;
12
- instanceKey?: string;
13
- path: string;
14
- originSessionId: string;
15
- sessionId: string | null;
16
- throughTurnId: string | null;
17
- throughBytes: number;
18
- anchors: Array<{
19
- turnId: string;
20
- sizeBytes: number;
21
- sha256: string;
22
- }>;
23
- /** After a Codex rollover: the superseded rollout's settled boundary, addressed by rollout id. */
24
- ancestor?: {
25
- rolloutId: string;
26
- throughBytes: number;
27
- anchors: Array<{
28
- turnId: string;
29
- sizeBytes: number;
30
- sha256: string;
31
- }>;
32
- };
33
- };
34
- export type NativeTurnReceipt = {
35
- version: 1;
36
- turnId: string;
37
- key: string;
38
- parentKey: string | null;
39
- parentCloudTurnId: string | null;
40
- userContent: NativeTurnStart["userContent"];
41
- startedAt: string;
42
- endBytes: number;
43
- contentEndBytes?: number;
44
- result: NativeTurnComplete | null;
45
- sessionStartedAt?: string;
46
- origin?: "local_import";
47
- progress?: NativeTurnProgress;
48
- /** Merged lineage order across Codex rollout files. */
49
- sequence?: number;
50
- };
51
- export type NativeSyncTransport = ArchiveTransport & {
52
- startNativeTurn?(input: NativeTurnStart, options?: {
53
- signal?: AbortSignal;
54
- }): Promise<NativeTurnBinding>;
55
- completeNativeTurn?(sessionId: string, turnId: string, input: NativeTurnComplete, options?: {
56
- signal?: AbortSignal;
57
- }): Promise<{
58
- completed: true;
59
- artifactsPending?: boolean;
60
- }>;
61
- heartbeatNativeTurn?(sessionId: string, turnId: string, options?: {
62
- signal?: AbortSignal;
63
- }): Promise<{
64
- abortRequested: boolean;
65
- status: string;
66
- }>;
67
- updateNativeTurn?(sessionId: string, turnId: string, input: NativeTurnProgress, options?: {
68
- signal?: AbortSignal;
69
- }): Promise<{
70
- accepted: boolean;
71
- }>;
72
- };
73
- export type NativeSyncOptions = {
74
- runtimeRoot: string;
75
- spaceId: string;
76
- identity: string;
77
- harness: "pi" | "codex";
78
- nativeSessionId: string;
79
- instanceKey?: string;
80
- transport?: NativeSyncTransport;
81
- };
82
- /** Turn receipts are append-only. Capture never waits for the network; network ACKs live in separate files. */
83
- export declare class NativeSyncStore {
84
- readonly options: NativeSyncOptions;
85
- readonly root: string;
86
- readonly archives: RuntimeArchiveStore;
87
- private archiveFailure;
88
- constructor(options: NativeSyncOptions);
89
- private bindingPath;
90
- private turnId;
91
- private receiptPath;
92
- private acknowledgementPath;
93
- private pendingPath;
94
- private requestPath;
95
- private retryPath;
96
- private cloudBindingPath;
97
- binding(): Promise<NativeBinding>;
98
- private initialize;
99
- capture(path: string, transcript: NativeTranscript, context?: {
100
- sessionStartedAt?: string;
101
- origin?: "local_import";
102
- signal?: AbortSignal;
103
- }): Promise<void>;
104
- receipts(pendingOnly?: boolean): Promise<NativeTurnReceipt[]>;
105
- status(): Promise<{
106
- harness: "codex" | "pi";
107
- nativeSessionId: string;
108
- sessionId: string | null;
109
- pendingTurns: number;
110
- pendingArchives: number;
111
- }>;
112
- flush(signal: AbortSignal, onAbort?: () => void): Promise<void>;
113
- private cloudArchive;
114
- }
115
- export declare function listNativeSyncStores(runtimeRoot: string, spaceId: string, identity: string, transport?: NativeSyncTransport): Promise<NativeSyncStore[]>;
116
- export {};