@h1r-ai/croche 0.0.0-stage → 0.5.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 (105) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +1184 -2
  3. package/THIRD-PARTY-NOTICES +5824 -0
  4. package/dist/archive.d.ts +47 -0
  5. package/dist/archive.js +217 -0
  6. package/dist/atomic-replace.d.ts +18 -0
  7. package/dist/atomic-replace.js +39 -0
  8. package/dist/commands.d.ts +56 -0
  9. package/dist/commands.js +1 -0
  10. package/dist/control.d.ts +62 -0
  11. package/dist/control.js +269 -0
  12. package/dist/core-abi.d.ts +110 -0
  13. package/dist/core-abi.js +1 -0
  14. package/dist/core-bindgen.d.ts +413 -0
  15. package/dist/core-bindgen.js +1533 -0
  16. package/dist/core-runtime.d.ts +214 -0
  17. package/dist/core-runtime.js +837 -0
  18. package/dist/core-wasm-bytes.d.ts +4 -0
  19. package/dist/core-wasm-bytes.js +5 -0
  20. package/dist/core-wasm.d.ts +16 -0
  21. package/dist/core-wasm.js +63 -0
  22. package/dist/debug.d.ts +26 -0
  23. package/dist/debug.js +171 -0
  24. package/dist/file-lock.d.ts +46 -0
  25. package/dist/file-lock.js +300 -0
  26. package/dist/images.d.ts +53 -0
  27. package/dist/images.js +179 -0
  28. package/dist/index.d.ts +14 -0
  29. package/dist/index.js +9 -0
  30. package/dist/markers.d.ts +1 -0
  31. package/dist/markers.js +1 -0
  32. package/dist/node.d.ts +46 -0
  33. package/dist/node.js +281 -0
  34. package/dist/project-core.d.ts +79 -0
  35. package/dist/project-core.js +261 -0
  36. package/dist/project-session.d.ts +44 -0
  37. package/dist/project-session.js +143 -0
  38. package/dist/project-types.d.ts +97 -0
  39. package/dist/project-types.js +1 -0
  40. package/dist/project-wire.d.ts +19 -0
  41. package/dist/project-wire.js +39 -0
  42. package/dist/sse.d.ts +19 -0
  43. package/dist/sse.js +53 -0
  44. package/dist/storage.d.ts +24 -0
  45. package/dist/storage.js +32 -0
  46. package/dist/stream-branch.d.ts +47 -0
  47. package/dist/stream-branch.js +107 -0
  48. package/dist/stream-hub.d.ts +207 -0
  49. package/dist/stream-hub.js +210 -0
  50. package/dist/stream.d.ts +3 -0
  51. package/dist/stream.js +5 -0
  52. package/dist/types.d.ts +928 -0
  53. package/dist/types.js +8 -0
  54. package/dist/wiki.d.ts +15 -0
  55. package/dist/wiki.js +25 -0
  56. package/docs/CODING-AGENT.md +96 -0
  57. package/docs/DEBUGGER.md +230 -0
  58. package/docs/S2-IMPLEMENTATION.md +585 -0
  59. package/docs/SKILL.md +337 -0
  60. package/docs/skills/croche/agents/openai.yaml +4 -0
  61. package/docs/skills/croche/references/agents.md +78 -0
  62. package/docs/skills/croche/references/first-turn.md +74 -0
  63. package/docs/skills/croche/references/tools.md +43 -0
  64. package/docs/skills/croche-cli/SKILL.md +158 -0
  65. package/docs/skills/croche-cli/agents/openai.yaml +4 -0
  66. package/docs/skills/croche-cli/references/powershell.md +47 -0
  67. package/docs/skills/croche-config/SKILL.md +152 -0
  68. package/docs/skills/croche-config/agents/openai.yaml +4 -0
  69. package/docs/skills/croche-config/references/models.md +12 -0
  70. package/docs/skills/croche-platforms/SKILL.md +55 -0
  71. package/docs/skills/croche-platforms/agents/openai.yaml +4 -0
  72. package/docs/skills/croche-platforms/references/android.md +185 -0
  73. package/docs/skills/croche-platforms/references/ios.md +165 -0
  74. package/docs/skills/croche-platforms/references/react-native.md +50 -0
  75. package/docs/skills/croche-platforms/references/web-backend.md +58 -0
  76. package/docs/skills/croche-troubleshoot/SKILL.md +72 -0
  77. package/docs/skills/croche-troubleshoot/agents/openai.yaml +4 -0
  78. package/docs/skills/croche-troubleshoot/references/recovery.md +31 -0
  79. package/package.json +52 -4
  80. package/src/archive.ts +188 -0
  81. package/src/atomic-replace.ts +43 -0
  82. package/src/commands.ts +62 -0
  83. package/src/control.ts +179 -0
  84. package/src/core-abi.ts +52 -0
  85. package/src/core-bindgen.ts +1557 -0
  86. package/src/core-runtime.ts +750 -0
  87. package/src/core-wasm-bytes.ts +5 -0
  88. package/src/core-wasm.ts +57 -0
  89. package/src/debug.ts +160 -0
  90. package/src/file-lock.ts +269 -0
  91. package/src/images.ts +174 -0
  92. package/src/index.ts +15 -0
  93. package/src/markers.ts +1 -0
  94. package/src/node.ts +194 -0
  95. package/src/project-core.ts +231 -0
  96. package/src/project-session.ts +118 -0
  97. package/src/project-types.ts +77 -0
  98. package/src/project-wire.ts +39 -0
  99. package/src/sse.ts +57 -0
  100. package/src/storage.ts +30 -0
  101. package/src/stream-branch.ts +112 -0
  102. package/src/stream-hub.ts +249 -0
  103. package/src/stream.ts +7 -0
  104. package/src/types.ts +838 -0
  105. package/src/wiki.ts +25 -0
@@ -0,0 +1,47 @@
1
+ import type { ArchiveRuntimeStorage } from './types.js';
2
+ export declare function segmentEntry(n: number): string;
3
+ export declare function archiveAppend(storage: ArchiveRuntimeStorage, key: string, n: number, record: string, maxBytes: number): Promise<void>;
4
+ export declare function archiveRead(storage: ArchiveRuntimeStorage, key: string, from: number, to: number): Promise<Array<Record<string, unknown>>>;
5
+ /**
6
+ * A real delete. Without a range, every segment. With one, each segment that holds a record of
7
+ * those turns is replaced, atomically, by its other lines (`replaceLines`): a crash leaves the
8
+ * segment as it was or as it should be, and the other turns are never lost. This is the
9
+ * mechanism forget-scrubbing will use (F20.5.1a).
10
+ */
11
+ export declare function archiveClear(storage: ArchiveRuntimeStorage, key: string, from: number | null, to: number | null): Promise<void>;
12
+ /** Archive entries in memory: `MemoryStorage`'s, for tests and one-shot prototypes. */
13
+ export declare class MemoryArchive implements ArchiveRuntimeStorage {
14
+ private readonly lines;
15
+ appendLine(key: string, entry: string, line: string): Promise<void>;
16
+ readLines(key: string, entry: string): Promise<string[]>;
17
+ replaceLines(key: string, entry: string, lines: string[]): Promise<void>;
18
+ remove(key: string, entry: string): Promise<void>;
19
+ entries(key: string, prefix: string): Promise<{
20
+ entry: string;
21
+ bytes: number;
22
+ }[]>;
23
+ }
24
+ /**
25
+ * Archive entries in IndexedDB (F20: the web default). One object store of lines, each
26
+ * `{key, entry, line, bytes}` under an increasing id, so an entry's lines read back in append
27
+ * order. Every call is one transaction: a line is in or out, never torn.
28
+ */
29
+ export declare class IndexedDbArchive implements ArchiveRuntimeStorage {
30
+ private readonly name;
31
+ private readonly factory;
32
+ private db?;
33
+ constructor(name?: string, factory?: IDBFactory);
34
+ private open;
35
+ private run;
36
+ appendLine(key: string, entry: string, line: string): Promise<void>;
37
+ readLines(key: string, entry: string): Promise<string[]>;
38
+ /** The row stored for one line (a seam for tests that fail a rewrite midway). */
39
+ protected row(key: string, entry: string, line: string): unknown;
40
+ /** One readwrite transaction: the old rows are deleted and the new ones put, or neither. */
41
+ replaceLines(key: string, entry: string, replacement: string[]): Promise<void>;
42
+ remove(key: string, entry: string): Promise<void>;
43
+ entries(key: string, prefix: string): Promise<{
44
+ entry: string;
45
+ bytes: number;
46
+ }[]>;
47
+ }
@@ -0,0 +1,217 @@
1
+ import { CrocheError } from './types.js';
2
+ /**
3
+ * The turn archive's rules (F20), the SDK's default implementation of the Core's three archive
4
+ * calls over any `ArchiveRuntimeStorage`:
5
+ * - one segment per 100 turns, the entry `archive<NNNN>` with NNNN = ⌊n/100⌋ (F20.4);
6
+ * - past the byte bound, the oldest whole segment is deleted, never the one just written;
7
+ * - on read, the last record per turn number wins (F20.3), and a turn no longer held is absent;
8
+ * - clear is a real delete: everything, or the records of a range of turns.
9
+ * Torn lines are the line storage's (a file's) concern: `readLines` never returns one.
10
+ */
11
+ const SEGMENT_TURNS = 100;
12
+ const SEGMENT = /^archive\d{4}$/;
13
+ export function segmentEntry(n) {
14
+ if (!Number.isSafeInteger(n) || n < 1 || n > 999_999)
15
+ throw new CrocheError('invalid_input', 'A turn number is 1 to 999999.');
16
+ return `archive${String(Math.floor(n / SEGMENT_TURNS)).padStart(4, '0')}`;
17
+ }
18
+ function segments(from, to) {
19
+ const out = [];
20
+ for (let s = Math.floor(from / SEGMENT_TURNS); s <= Math.floor(to / SEGMENT_TURNS); s++)
21
+ out.push(`archive${String(s).padStart(4, '0')}`);
22
+ return out;
23
+ }
24
+ /** A line's record and its turn number, or null for anything that is not one. */
25
+ function parse(line) {
26
+ try {
27
+ const record = JSON.parse(line);
28
+ const n = record?.n;
29
+ return record && typeof record === 'object' && !Array.isArray(record) && typeof n === 'number' && Number.isSafeInteger(n) ? { n, record } : null;
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ }
35
+ export async function archiveAppend(storage, key, n, record, maxBytes) {
36
+ if (record.includes('\n'))
37
+ throw new CrocheError('invalid_input', 'An archive record is one line.');
38
+ const entry = segmentEntry(n);
39
+ await storage.appendLine(key, entry, record);
40
+ const held = (await storage.entries(key, 'archive')).filter(e => SEGMENT.test(e.entry)).sort((a, b) => (a.entry < b.entry ? -1 : 1));
41
+ let total = held.reduce((sum, e) => sum + e.bytes, 0);
42
+ for (const oldest of held) {
43
+ if (total <= maxBytes || oldest.entry >= entry)
44
+ break;
45
+ await storage.remove(key, oldest.entry);
46
+ total -= oldest.bytes;
47
+ }
48
+ }
49
+ export async function archiveRead(storage, key, from, to) {
50
+ const byN = new Map();
51
+ for (const entry of segments(from, to)) {
52
+ for (const line of await storage.readLines(key, entry)) {
53
+ const parsed = parse(line);
54
+ if (parsed && parsed.n >= from && parsed.n <= to)
55
+ byN.set(parsed.n, parsed.record);
56
+ }
57
+ }
58
+ return [...byN.keys()].sort((a, b) => a - b).map(n => byN.get(n));
59
+ }
60
+ /**
61
+ * A real delete. Without a range, every segment. With one, each segment that holds a record of
62
+ * those turns is replaced, atomically, by its other lines (`replaceLines`): a crash leaves the
63
+ * segment as it was or as it should be, and the other turns are never lost. This is the
64
+ * mechanism forget-scrubbing will use (F20.5.1a).
65
+ */
66
+ export async function archiveClear(storage, key, from, to) {
67
+ if (from === null || to === null) {
68
+ for (const e of await storage.entries(key, 'archive'))
69
+ if (SEGMENT.test(e.entry))
70
+ await storage.remove(key, e.entry);
71
+ return;
72
+ }
73
+ for (const entry of segments(from, to)) {
74
+ const lines = await storage.readLines(key, entry);
75
+ const keep = lines.filter(line => { const p = parse(line); return p !== null && (p.n < from || p.n > to); });
76
+ if (keep.length === lines.length)
77
+ continue;
78
+ await storage.replaceLines(key, entry, keep);
79
+ }
80
+ }
81
+ const utf8 = (text) => new TextEncoder().encode(text).length;
82
+ const ENTRY = /^[a-z0-9]+$/;
83
+ function checkEntry(entry) {
84
+ if (!ENTRY.test(entry))
85
+ throw new CrocheError('invalid_input', 'An archive entry name is [a-z0-9]+.');
86
+ }
87
+ /** Archive entries in memory: `MemoryStorage`'s, for tests and one-shot prototypes. */
88
+ export class MemoryArchive {
89
+ lines = new Map();
90
+ async appendLine(key, entry, line) {
91
+ checkEntry(entry);
92
+ const id = JSON.stringify([key, entry]);
93
+ this.lines.set(id, [...(this.lines.get(id) ?? []), line]);
94
+ }
95
+ async readLines(key, entry) { return [...(this.lines.get(JSON.stringify([key, entry])) ?? [])]; }
96
+ async replaceLines(key, entry, lines) {
97
+ checkEntry(entry);
98
+ if (lines.length)
99
+ this.lines.set(JSON.stringify([key, entry]), [...lines]);
100
+ else
101
+ this.lines.delete(JSON.stringify([key, entry]));
102
+ }
103
+ async remove(key, entry) { this.lines.delete(JSON.stringify([key, entry])); }
104
+ async entries(key, prefix) {
105
+ const out = [];
106
+ for (const [id, lines] of this.lines) {
107
+ const [k, entry] = JSON.parse(id);
108
+ if (k === key && entry.startsWith(prefix))
109
+ out.push({ entry, bytes: lines.reduce((sum, l) => sum + utf8(l) + 1, 0) });
110
+ }
111
+ return out;
112
+ }
113
+ }
114
+ /**
115
+ * Archive entries in IndexedDB (F20: the web default). One object store of lines, each
116
+ * `{key, entry, line, bytes}` under an increasing id, so an entry's lines read back in append
117
+ * order. Every call is one transaction: a line is in or out, never torn.
118
+ */
119
+ export class IndexedDbArchive {
120
+ name;
121
+ factory;
122
+ db;
123
+ constructor(name = 'croche-archive', factory = globalThis.indexedDB) {
124
+ this.name = name;
125
+ this.factory = factory;
126
+ if (!factory)
127
+ throw new CrocheError('host_unavailable', 'IndexedDbArchive needs IndexedDB.');
128
+ }
129
+ open() {
130
+ this.db ??= new Promise((resolve, reject) => {
131
+ const request = this.factory.open(this.name, 1);
132
+ request.onupgradeneeded = () => {
133
+ const lines = request.result.createObjectStore('lines', { autoIncrement: true });
134
+ lines.createIndex('entry', ['key', 'entry']);
135
+ };
136
+ request.onsuccess = () => resolve(request.result);
137
+ request.onerror = () => reject(new CrocheError('storage_error', 'The archive database could not be opened.'));
138
+ });
139
+ return this.db;
140
+ }
141
+ async run(mode, work) {
142
+ const db = await this.open();
143
+ return new Promise((resolve, reject) => {
144
+ const tx = db.transaction('lines', mode);
145
+ let request;
146
+ try {
147
+ request = work(tx.objectStore('lines'), tx);
148
+ }
149
+ catch {
150
+ try {
151
+ tx.abort();
152
+ }
153
+ catch { /* already finished */ }
154
+ }
155
+ tx.oncomplete = () => resolve(request ? request.result : undefined);
156
+ tx.onerror = tx.onabort = () => reject(new CrocheError('storage_error', 'The archive could not be read or written.'));
157
+ });
158
+ }
159
+ async appendLine(key, entry, line) {
160
+ checkEntry(entry);
161
+ await this.run('readwrite', lines => lines.add(this.row(key, entry, line)));
162
+ }
163
+ async readLines(key, entry) {
164
+ const rows = await this.run('readonly', lines => lines.index('entry').getAll(IDBKeyRange.only([key, entry])));
165
+ return (rows ?? []).map(r => r.line);
166
+ }
167
+ /** The row stored for one line (a seam for tests that fail a rewrite midway). */
168
+ row(key, entry, line) {
169
+ return { key, entry, line, bytes: utf8(line) + 1 };
170
+ }
171
+ /** One readwrite transaction: the old rows are deleted and the new ones put, or neither. */
172
+ async replaceLines(key, entry, replacement) {
173
+ checkEntry(entry);
174
+ await this.run('readwrite', (lines, tx) => {
175
+ const cursor = lines.index('entry').openKeyCursor(IDBKeyRange.only([key, entry]));
176
+ cursor.onsuccess = () => {
177
+ const c = cursor.result;
178
+ if (c) {
179
+ lines.delete(c.primaryKey);
180
+ c.continue();
181
+ return;
182
+ }
183
+ try {
184
+ for (const line of replacement)
185
+ lines.add(this.row(key, entry, line));
186
+ }
187
+ catch {
188
+ tx.abort();
189
+ }
190
+ };
191
+ });
192
+ }
193
+ async remove(key, entry) {
194
+ await this.run('readwrite', lines => {
195
+ const cursor = lines.index('entry').openKeyCursor(IDBKeyRange.only([key, entry]));
196
+ cursor.onsuccess = () => { const c = cursor.result; if (c) {
197
+ lines.delete(c.primaryKey);
198
+ c.continue();
199
+ } };
200
+ });
201
+ }
202
+ async entries(key, prefix) {
203
+ const sizes = new Map();
204
+ await this.run('readonly', lines => {
205
+ const cursor = lines.index('entry').openCursor(IDBKeyRange.bound([key, prefix], [key, `${prefix}￿`]));
206
+ cursor.onsuccess = () => {
207
+ const c = cursor.result;
208
+ if (!c)
209
+ return;
210
+ const row = c.value;
211
+ sizes.set(row.entry, (sizes.get(row.entry) ?? 0) + row.bytes);
212
+ c.continue();
213
+ };
214
+ });
215
+ return [...sizes].map(([entry, bytes]) => ({ entry, bytes }));
216
+ }
217
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Waits between attempts to replace a file on Windows. There, another process (antivirus, the
3
+ * search indexer, a backup or sync agent) can hold the target or the temporary file open for a
4
+ * moment, and rename then fails with EPERM, EBUSY or EACCES although nothing is wrong. About
5
+ * 0.8 s in all, then the failure is reported.
6
+ */
7
+ export declare const REPLACE_RETRY_DELAYS_MS: readonly number[];
8
+ export interface ReplaceIo {
9
+ rename(from: string, to: string): Promise<void>;
10
+ platform(): NodeJS.Platform;
11
+ sleep(ms: number): Promise<void>;
12
+ }
13
+ /**
14
+ * Atomically replaces `to` with `from` (rename). On win32 only, a transient sharing failure is
15
+ * retried with bounded backoff; past the bound it is `storage_error`, its cause the last
16
+ * failure. Every other failure, and every failure on other platforms, is thrown as it is.
17
+ */
18
+ export declare function replaceFile(from: string, to: string, override?: Partial<ReplaceIo>): Promise<void>;
@@ -0,0 +1,39 @@
1
+ import { rename } from 'node:fs/promises';
2
+ import { CrocheError } from './types.js';
3
+ /**
4
+ * Waits between attempts to replace a file on Windows. There, another process (antivirus, the
5
+ * search indexer, a backup or sync agent) can hold the target or the temporary file open for a
6
+ * moment, and rename then fails with EPERM, EBUSY or EACCES although nothing is wrong. About
7
+ * 0.8 s in all, then the failure is reported.
8
+ */
9
+ export const REPLACE_RETRY_DELAYS_MS = [10, 25, 50, 100, 200, 400];
10
+ const TRANSIENT = new Set(['EPERM', 'EBUSY', 'EACCES']);
11
+ const io = {
12
+ rename,
13
+ platform: () => process.platform,
14
+ sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
15
+ };
16
+ /**
17
+ * Atomically replaces `to` with `from` (rename). On win32 only, a transient sharing failure is
18
+ * retried with bounded backoff; past the bound it is `storage_error`, its cause the last
19
+ * failure. Every other failure, and every failure on other platforms, is thrown as it is.
20
+ */
21
+ export async function replaceFile(from, to, override = {}) {
22
+ const { rename: move, platform, sleep } = { ...io, ...override };
23
+ for (let attempt = 0;; attempt++) {
24
+ try {
25
+ await move(from, to);
26
+ return;
27
+ }
28
+ catch (error) {
29
+ const code = error.code ?? '';
30
+ if (platform() !== 'win32' || !TRANSIENT.has(code))
31
+ throw error;
32
+ if (attempt >= REPLACE_RETRY_DELAYS_MS.length) {
33
+ const failure = new CrocheError('storage_error', `The stored value could not be replaced: ${code} on each of ${attempt + 1} attempts. Another program (often antivirus or a sync agent) is holding the file open.`);
34
+ throw Object.assign(failure, { cause: error });
35
+ }
36
+ await sleep(REPLACE_RETRY_DELAYS_MS[attempt]);
37
+ }
38
+ }
39
+ }
@@ -0,0 +1,56 @@
1
+ import type { JsonValue, RuntimeOptions, ToolContext } from './types.js';
2
+ import type { ToolResult } from './images.js';
3
+ /** A typed CLI argument interpreted by the shared Core, without executing a shell. */
4
+ export interface CommandArgument {
5
+ name: string;
6
+ /** Callback argument name; defaults to name. */
7
+ arg?: string;
8
+ type: 'string' | 'integer' | 'number' | 'boolean' | 'duration';
9
+ description?: string;
10
+ required?: boolean;
11
+ default?: JsonValue;
12
+ enum?: JsonValue[];
13
+ minimum?: number;
14
+ maximum?: number;
15
+ minLength?: number;
16
+ maxLength?: number;
17
+ /** Other flag names accepted for this one (e.g. `id` for `task-id`); shown only in help. */
18
+ aliases?: string[];
19
+ /** Flags only: several values, written `--tags work,home` or `--tags work --tags home`; the
20
+ * handler receives an array. */
21
+ list?: boolean;
22
+ }
23
+ export interface RuntimeCommand {
24
+ /** Stable application receipt/telemetry identifier, independent of CLI spelling. */
25
+ key: string;
26
+ /** One CLI segment; omit for a command at the Tool root. */
27
+ name?: string;
28
+ summary: string;
29
+ /** Other names accepted for this command (e.g. `edit`, `upgrade` for `update`), for verbs a
30
+ * model may mix up; shown only in help. */
31
+ aliases?: string[];
32
+ timeoutMs?: number;
33
+ /** A read: its result is the answer (a lookup, a list, a status). With replyWithCommands, a
34
+ * round that runs a read always gets a reply written after the result. */
35
+ reads?: boolean;
36
+ flags?: CommandArgument[];
37
+ positionals?: CommandArgument[];
38
+ }
39
+ export interface CommandInvocation {
40
+ tool: string;
41
+ command?: string;
42
+ key: string;
43
+ args: Record<string, JsonValue>;
44
+ }
45
+ /** A grouped application capability. The model still sees only run_tool({cmd}). */
46
+ export interface RuntimeTool {
47
+ name: string;
48
+ summary: string;
49
+ commands: RuntimeCommand[];
50
+ /** Return structured rejection JSON for an action the model can correct.
51
+ * A throw after dispatch ends the turn because its effects may be unknown. */
52
+ execute(invocation: CommandInvocation, context: ToolContext): JsonValue | ToolResult | Promise<JsonValue | ToolResult>;
53
+ }
54
+ export type RuntimeToolMetadata = Omit<RuntimeTool, 'execute'>;
55
+ /** Options consumed by the shared Core host. */
56
+ export type CoreRuntimeOptions = RuntimeOptions;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,62 @@
1
+ import type { RuntimeStatus, SendInput, SendOptions } from './types.js';
2
+ /** External host control is separate from the model-facing run_tool command. */
3
+ export interface ControllableRuntime {
4
+ status(): RuntimeStatus;
5
+ history?(): unknown[];
6
+ send?(input: SendInput, options?: SendOptions): Promise<unknown>;
7
+ sync?(): Promise<unknown>;
8
+ userBudget?: {
9
+ get(): unknown;
10
+ set?(input: {
11
+ amount: number;
12
+ }): Promise<unknown>;
13
+ };
14
+ }
15
+ export interface RuntimeControlOptions {
16
+ runtime: ControllableRuntime;
17
+ url?: string;
18
+ token?: string;
19
+ /** An explicitly supplied app-origin fetch adapter authenticates on the server.
20
+ * No broker credential is sent to the browser. Requires fetch and no token. */
21
+ relayAuthentication?: boolean;
22
+ /** Supply an app-origin relay adapter for HTTPS development pages. */
23
+ fetch?: typeof fetch;
24
+ /** Current permitted metadata only. Functions and private stores are never exposed. */
25
+ tools?: () => unknown;
26
+ /** App adapters own transcript, context, source IDs and input receipt handling. */
27
+ send?: (input: {
28
+ id: string;
29
+ text: string;
30
+ }, options: {
31
+ signal: AbortSignal;
32
+ }) => Promise<unknown>;
33
+ /** Return false if there is no active app turn; no result claims rollback. */
34
+ cancel?: () => void | boolean | Promise<void | boolean>;
35
+ /** Opt-in debugger control of this existing handle; never creates a Runtime. */
36
+ debug?: {
37
+ attach: (options: {
38
+ url: string;
39
+ token: string;
40
+ visibility: 'runtime' | 'full';
41
+ }) => Promise<unknown>;
42
+ detach: () => Promise<unknown>;
43
+ };
44
+ onError?: (error: {
45
+ code: string;
46
+ message: string;
47
+ }) => void;
48
+ pollIntervalMs?: number;
49
+ /** Wait for a previous attachment's lease to expire (for example after reload).
50
+ * Default 0 fails immediately; maximum 60 seconds. Never retries commands. */
51
+ registrationTimeoutMs?: number;
52
+ }
53
+ export interface RuntimeControlConnection {
54
+ readonly runtimeInstanceId: string;
55
+ readonly capabilities: readonly string[];
56
+ close(): Promise<void>;
57
+ }
58
+ /** Attach an existing Runtime to an explicitly authenticated local broker.
59
+ * Does not open stores, create Runtime identities, or run a provider loop.
60
+ * The broker never automatically resubmits a dispatched command after loss.
61
+ */
62
+ export declare function attachRuntimeControl(options: RuntimeControlOptions): Promise<RuntimeControlConnection>;