@h1r-ai/croche 0.0.0-stage → 0.5.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.
Files changed (86) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +1176 -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 +930 -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 +92 -0
  57. package/docs/DEBUGGER.md +230 -0
  58. package/docs/S2-IMPLEMENTATION.md +585 -0
  59. package/docs/SKILL.md +295 -0
  60. package/package.json +52 -4
  61. package/src/archive.ts +188 -0
  62. package/src/atomic-replace.ts +43 -0
  63. package/src/commands.ts +62 -0
  64. package/src/control.ts +179 -0
  65. package/src/core-abi.ts +52 -0
  66. package/src/core-bindgen.ts +1557 -0
  67. package/src/core-runtime.ts +750 -0
  68. package/src/core-wasm-bytes.ts +5 -0
  69. package/src/core-wasm.ts +57 -0
  70. package/src/debug.ts +160 -0
  71. package/src/file-lock.ts +269 -0
  72. package/src/images.ts +174 -0
  73. package/src/index.ts +15 -0
  74. package/src/markers.ts +1 -0
  75. package/src/node.ts +194 -0
  76. package/src/project-core.ts +231 -0
  77. package/src/project-session.ts +118 -0
  78. package/src/project-types.ts +77 -0
  79. package/src/project-wire.ts +39 -0
  80. package/src/sse.ts +57 -0
  81. package/src/storage.ts +30 -0
  82. package/src/stream-branch.ts +112 -0
  83. package/src/stream-hub.ts +249 -0
  84. package/src/stream.ts +7 -0
  85. package/src/types.ts +840 -0
  86. package/src/wiki.ts +25 -0
@@ -0,0 +1,214 @@
1
+ import { core } from './core-wasm.js';
2
+ import type { CoreRuntimeOptions, RuntimeTool, RuntimeToolMetadata } from './commands.js';
3
+ import type { OpenOptions as ProjectOpenOptions } from './project-types.js';
4
+ import { type BudgetAdjustment, type BudgetSnapshot, type DeferredWrite, type DisplayMessage, type RuntimeDebugObserverOptions, type RuntimeStatus, type SendInput, type SendOptions, type TurnResult, type RuntimeMemoryApi, type RuntimeWiki, type UserWikiResult, type WikiDocument } from './types.js';
5
+ export declare const DEFAULT_MODEL = "deepseek/deepseek-v4.1-flash";
6
+ export declare const SDK_VERSION = "0.5.0";
7
+ /** What one round of background upkeep did. */
8
+ export interface MaintenanceResult {
9
+ ran: boolean;
10
+ ok?: boolean;
11
+ preempted?: boolean;
12
+ pendingEvents?: number;
13
+ error?: {
14
+ code: string;
15
+ message: string;
16
+ };
17
+ }
18
+ /** What `deliverDue()` did: nothing due (or a delivery already running: `inFlight`), or one turn
19
+ * that carried the notes `ids` (`"heartbeat"` among them for the app's heartbeat).
20
+ * `delivered: true` means they are spent: never delivered again, and the heartbeat's next period
21
+ * counts from now. Spent is not answered: a spent note's turn may have failed (`error`, also on
22
+ * `turn.error`), and then the note says so (`failed: <code>`, plus `retry`: `permanent` for the
23
+ * code, `dispatched` when the turn had dispatched a command, so a retry could run it twice,
24
+ * `expired` a day after the note's time).
25
+ * `delivered: false` means something stays pending: the turn was cancelled, or it failed
26
+ * transiently before dispatching any command, and the notes and the heartbeat are tried again
27
+ * from `retryAt` (`error` says why).
28
+ * `error` without a turn: refused before any turn began (spent, or retried, by the same rule). */
29
+ export interface DeliverDueResult {
30
+ ran: boolean;
31
+ inFlight?: boolean;
32
+ ids?: string[];
33
+ delivered?: boolean;
34
+ turn?: TurnResult;
35
+ retryAt?: string;
36
+ error?: {
37
+ code: string;
38
+ message: string;
39
+ };
40
+ }
41
+ /** The agent's pending scheduled notes, earliest first, and how many are due now; with the
42
+ * `heartbeat` option, also its next time and whether it is due (not in `pending` or `due`).
43
+ * A note or heartbeat whose delivery failed transiently carries `attempts` and is not due
44
+ * before `retryAt`; for the heartbeat these are retry attempts, not heartbeat periods. */
45
+ export interface ScheduleList {
46
+ pending: Array<{
47
+ id: string;
48
+ at: string;
49
+ note: string;
50
+ attempts?: number;
51
+ retryAt?: string;
52
+ }>;
53
+ due: number;
54
+ heartbeat?: {
55
+ at: string;
56
+ due: boolean;
57
+ attempts?: number;
58
+ retryAt?: string;
59
+ };
60
+ }
61
+ /** The longest delay a JS timer holds (2^31 - 1 ms, about 24.8 days); a longer one fires at once.
62
+ * A note further away is reached in steps, each re-checked against its time. */
63
+ export declare const SCHEDULE_TIMER_MAX_MS = 2147483647;
64
+ type WasmRuntime = InstanceType<ReturnType<typeof core>['WasmRuntime']>;
65
+ /** Internal PAL reuse; not exported by the package or a public Runtime API name. */
66
+ type ProjectPal = {
67
+ host: ReturnType<CrocheRuntime['host']>;
68
+ attach(handle: WasmRuntime): CrocheRuntime;
69
+ };
70
+ export declare let projectPal: (options: ProjectOpenOptions, user: () => string | null) => ProjectPal;
71
+ /** Internal receipt-send reuse; not exported by the package. */
72
+ export declare const receiptSend: unique symbol;
73
+ /**
74
+ * Web/Node SDK. The Runtime (its state, its turn loop, upkeep, cancellation, persistence order)
75
+ * is the shared Rust Core; this class is its PAL for web and Node (fetch, storage, locks, timers,
76
+ * the app's tool callbacks) and the typed API over it.
77
+ */
78
+ export declare class CrocheRuntime {
79
+ private readonly options;
80
+ private core;
81
+ private bindings;
82
+ private debugObserver?;
83
+ private usageObserver?;
84
+ private readonly transport;
85
+ private wakeTimer?;
86
+ private releaseLock?;
87
+ /** Whether this instance holds an exclusive lock on its store (the storage's own, or a Web Lock).
88
+ * Only such an instance arms schedule timers: without one, two tabs or processes on one store
89
+ * would each deliver. */
90
+ private lockHeld;
91
+ private ready;
92
+ private scheduleEntries;
93
+ private scheduleTimer?;
94
+ private removeForegroundListener?;
95
+ private lastForegroundAt?;
96
+ private foregroundMaintaining;
97
+ readonly userBudget: {
98
+ get: () => BudgetSnapshot;
99
+ /** Cloud applies the developer's ceilings and answers. Pass `id` to make a retry safe. */
100
+ add: ({ amount, id }: {
101
+ amount: number;
102
+ id?: string;
103
+ }) => Promise<BudgetAdjustment | DeferredWrite>;
104
+ set: ({ amount, id }: {
105
+ amount: number;
106
+ id?: string;
107
+ }) => Promise<BudgetAdjustment | DeferredWrite>;
108
+ };
109
+ /**
110
+ * The app's knowledge documents, held by the Rust Core in memory (never stored: load them on
111
+ * each open). The agent never sees a document unless it searches or reads it with the built-in
112
+ * `wiki` command; `list`, `read` and `search` here are that same view.
113
+ */
114
+ readonly wiki: RuntimeWiki;
115
+ private readonly secretStorage;
116
+ private readonly codec;
117
+ /** Ordered calls still waiting to be admitted (`ordered`), and the last one's admission. */
118
+ private waiting;
119
+ private admitted;
120
+ private constructor();
121
+ static create(options: CoreRuntimeOptions): Promise<CrocheRuntime>;
122
+ /**
123
+ * Shares documents of the user's own with several characters. Each agent's Runtime has its
124
+ * own store, so this puts them (as `scope: 'user'`) to every Runtime given, each with its own
125
+ * `agents` filter applied. A put replaces by path, so retrying after a failure is safe.
126
+ */
127
+ static shareWiki(runtimes: CrocheRuntime[], docs: WikiDocument | WikiDocument[]): Promise<(UserWikiResult | DeferredWrite)[]>;
128
+ private toolMetadata;
129
+ /** Registry validation is atomic and performed by Rust; a refusal changes nothing here
130
+ * or in the Core. The model learns of the change from the next turn: in that message, so the
131
+ * cached prompt stays warm, until a new conversation or a pause rebuilds the list itself
132
+ * (internal#2). Revocation applies at
133
+ * once: an announced callback that has not started is not run, and a removed or changed
134
+ * command answers `withdrawn` for the rest of the turn. */
135
+ setTools(tools: RuntimeTool[]): void;
136
+ /** Attach, replace or detach local diagnostics without reopening the Runtime.
137
+ * Only future observations are delivered; attaching during work may capture a
138
+ * response without its earlier request. This never replays past model bodies.
139
+ * Observer exceptions and mutations cannot affect execution or durable state. */
140
+ setDebugObserver(options?: RuntimeDebugObserverOptions): void;
141
+ history(): DisplayMessage[];
142
+ status(): RuntimeStatus;
143
+ tools(): RuntimeToolMetadata[];
144
+ /** Long-term memory: call it for a read-only snapshot, use its methods to manage it. */
145
+ readonly memory: RuntimeMemoryApi;
146
+ send(input: SendInput, options?: SendOptions): Promise<TurnResult>;
147
+ [receiptSend](input: SendInput, options?: Pick<SendOptions, 'signal' | 'responseFormat' | 'imageResolution'>): Promise<import('./stream-hub.js').StreamReceipt>;
148
+ private prepareSend;
149
+ /**
150
+ * Admits calls to the Core in the order they were made (Atlas, #351 P1-4): a send waiting on
151
+ * its images holds back every ordered call after it (sends, clearHistory, clearQueued), never
152
+ * one before it. Only admission waits, never a turn. A preparation that fails rejects its own
153
+ * call alone; the next is admitted as usual. With nothing waiting, `admit` runs at once.
154
+ */
155
+ private ordered;
156
+ private reserve;
157
+ sync(): Promise<void>;
158
+ /**
159
+ * One round of background upkeep: deliver the outbox of call reports, then sync balances,
160
+ * policy and the model key. The Core does work only when some is due and backs off after a
161
+ * failure. It runs by itself after each turn and on a timer (backgroundSync, default on);
162
+ * browsers also call it on a visible foreground return unless backgroundSync is false.
163
+ * Node has no foreground hook. It never delays a turn: a send takes over
164
+ * while it waits on Cloud.
165
+ */
166
+ maintain(options?: {
167
+ force?: boolean;
168
+ }): Promise<MaintenanceResult>;
169
+ /**
170
+ * Delivers the agent's scheduled notes that are due (`crocheTools.schedule`), as one turn whose
171
+ * message holds one schedule channel per note. Never before a note's time, best effort after
172
+ * it: call it when the app returns to the foreground. Nothing due: no turn and no cost.
173
+ * While the Runtime is open and holds its store's lock, a timer calls it at the earliest
174
+ * note's time, and at open for notes already due.
175
+ */
176
+ deliverDue(): Promise<DeliverDueResult>;
177
+ /** The agent's pending scheduled notes. */
178
+ schedules(): ScheduleList;
179
+ flush(): Promise<void>;
180
+ clearHistory(): Promise<void>;
181
+ /** Stops the running turn only: messages sent while it ran still go, together, as the next turn
182
+ * (a send's own `signal` drops just that send while it is held; once its turn has started, the
183
+ * turn stops, for every send it carries). */
184
+ cancel(): void;
185
+ /** Drops the messages held behind the running turn (each send ends `cancelled`); returns how many. */
186
+ clearQueued(): Promise<number>;
187
+ /** When the Runtime next wants upkeep, in epoch ms (the same unit as the `clock` option), or null.
188
+ * With an injected clock, call maintain() once clock() reaches it. */
189
+ wakeAt(): number | null;
190
+ /** The Core projection fence joins its synchronous listener, not buffered SDK/UI consumers.
191
+ * An app callback that waits for work on the closer's thread deadlocks under any
192
+ * wait-for-callback fence. A synchronous Core-listener self-close does not wait on itself. */
193
+ close(): Promise<void>;
194
+ private now;
195
+ /** Browsers have foreground transitions; Node has none. Core owns due/backoff decisions. */
196
+ private watchForeground;
197
+ private clearScheduleTimer;
198
+ /** One timer, at the earliest pending note: never before its time (a clamped step that ends
199
+ * early re-arms instead of delivering), best effort after. Re-armed at each schedule effect. */
200
+ private armSchedule;
201
+ private run;
202
+ private adjust;
203
+ private memoryRead;
204
+ private inspect;
205
+ private checkOpen;
206
+ private cancelFor;
207
+ private signalFor;
208
+ /** The PAL for web and Node. Everything else is the Core's. */
209
+ private host;
210
+ private http;
211
+ private tool;
212
+ private acquireLock;
213
+ }
214
+ export {};