dsh-cross-memory 0.0.0-stage → 0.2.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 (152) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +253 -2
  3. package/cordis.patch.yml +27 -0
  4. package/docs/DETAIL.md +13 -0
  5. package/docs/DETAIL.zh.md +17 -0
  6. package/icon.svg +1 -0
  7. package/lib/backfill.js +273 -0
  8. package/lib/citations.js +305 -0
  9. package/lib/client.js +1660 -0
  10. package/lib/config.js +736 -0
  11. package/lib/consolidate.js +1119 -0
  12. package/lib/extract.js +570 -0
  13. package/lib/gate.js +137 -0
  14. package/lib/git-origin.js +224 -0
  15. package/lib/index.js +4482 -0
  16. package/lib/log.js +260 -0
  17. package/lib/loops.js +186 -0
  18. package/lib/notices.js +195 -0
  19. package/lib/notify.js +33 -0
  20. package/lib/persona.js +163 -0
  21. package/lib/query.js +93 -0
  22. package/lib/raw-recall.js +286 -0
  23. package/lib/reflection.js +291 -0
  24. package/lib/remote.js +490 -0
  25. package/lib/render.js +678 -0
  26. package/lib/retention.js +64 -0
  27. package/lib/schedule.js +245 -0
  28. package/lib/search.js +1068 -0
  29. package/lib/skills.js +220 -0
  30. package/lib/state.js +701 -0
  31. package/lib/storage.js +1424 -0
  32. package/lib/sync-runtime.js +268 -0
  33. package/lib/sync.js +620 -0
  34. package/lib/test/activity.test.js +74 -0
  35. package/lib/test/archive.test.js +182 -0
  36. package/lib/test/backfill.test.js +144 -0
  37. package/lib/test/citations.test.js +91 -0
  38. package/lib/test/client-wiring.test.js +134 -0
  39. package/lib/test/consolidate-job.test.js +95 -0
  40. package/lib/test/consolidate.test.js +430 -0
  41. package/lib/test/consolidation-selection.test.js +152 -0
  42. package/lib/test/dedupe-keys.test.js +230 -0
  43. package/lib/test/delta.test.js +93 -0
  44. package/lib/test/derived.test.js +110 -0
  45. package/lib/test/disputes-panel.test.js +341 -0
  46. package/lib/test/eval.test.js +171 -0
  47. package/lib/test/expand.test.js +164 -0
  48. package/lib/test/extract.test.js +1020 -0
  49. package/lib/test/git-origin.test.js +189 -0
  50. package/lib/test/injection.test.js +440 -0
  51. package/lib/test/kind-filter.test.js +49 -0
  52. package/lib/test/legacy-state.test.js +69 -0
  53. package/lib/test/log.test.js +156 -0
  54. package/lib/test/loops.test.js +86 -0
  55. package/lib/test/memory.test.js +855 -0
  56. package/lib/test/notices.test.js +142 -0
  57. package/lib/test/persona.test.js +86 -0
  58. package/lib/test/prefilter.test.js +73 -0
  59. package/lib/test/preset.test.js +77 -0
  60. package/lib/test/raw-recall.test.js +186 -0
  61. package/lib/test/recall.test.js +433 -0
  62. package/lib/test/reflection.test.js +64 -0
  63. package/lib/test/remote.test.js +238 -0
  64. package/lib/test/retention.test.js +117 -0
  65. package/lib/test/retrieval.test.js +142 -0
  66. package/lib/test/rotation.test.js +228 -0
  67. package/lib/test/schedule.test.js +112 -0
  68. package/lib/test/settings-card.test.js +58 -0
  69. package/lib/test/skills.test.js +129 -0
  70. package/lib/test/state.test.js +212 -0
  71. package/lib/test/subagent-contract.test.js +139 -0
  72. package/lib/test/sweep.test.js +159 -0
  73. package/lib/test/sync.test.js +314 -0
  74. package/lib/test/time.test.js +171 -0
  75. package/lib/time.js +303 -0
  76. package/lib/tool.js +330 -0
  77. package/lib/types/backfill.d.ts +96 -0
  78. package/lib/types/citations.d.ts +105 -0
  79. package/lib/types/config.d.ts +811 -0
  80. package/lib/types/consolidate.d.ts +742 -0
  81. package/lib/types/extract.d.ts +352 -0
  82. package/lib/types/gate.d.ts +83 -0
  83. package/lib/types/git-origin.d.ts +23 -0
  84. package/lib/types/index.d.ts +1316 -0
  85. package/lib/types/log.d.ts +144 -0
  86. package/lib/types/loops.d.ts +82 -0
  87. package/lib/types/notices.d.ts +117 -0
  88. package/lib/types/notify.d.ts +12 -0
  89. package/lib/types/persona.d.ts +76 -0
  90. package/lib/types/query.d.ts +45 -0
  91. package/lib/types/raw-recall.d.ts +84 -0
  92. package/lib/types/reflection.d.ts +122 -0
  93. package/lib/types/remote.d.ts +246 -0
  94. package/lib/types/render.d.ts +286 -0
  95. package/lib/types/retention.d.ts +66 -0
  96. package/lib/types/schedule.d.ts +116 -0
  97. package/lib/types/search.d.ts +583 -0
  98. package/lib/types/skills.d.ts +71 -0
  99. package/lib/types/state.d.ts +294 -0
  100. package/lib/types/storage.d.ts +458 -0
  101. package/lib/types/sync-runtime.d.ts +103 -0
  102. package/lib/types/sync.d.ts +222 -0
  103. package/lib/types/test/activity.test.d.ts +1 -0
  104. package/lib/types/test/archive.test.d.ts +1 -0
  105. package/lib/types/test/backfill.test.d.ts +1 -0
  106. package/lib/types/test/citations.test.d.ts +1 -0
  107. package/lib/types/test/client-wiring.test.d.ts +1 -0
  108. package/lib/types/test/consolidate-job.test.d.ts +1 -0
  109. package/lib/types/test/consolidate.test.d.ts +1 -0
  110. package/lib/types/test/consolidation-selection.test.d.ts +1 -0
  111. package/lib/types/test/dedupe-keys.test.d.ts +1 -0
  112. package/lib/types/test/delta.test.d.ts +1 -0
  113. package/lib/types/test/derived.test.d.ts +1 -0
  114. package/lib/types/test/disputes-panel.test.d.ts +1 -0
  115. package/lib/types/test/eval.test.d.ts +1 -0
  116. package/lib/types/test/expand.test.d.ts +1 -0
  117. package/lib/types/test/extract.test.d.ts +1 -0
  118. package/lib/types/test/git-origin.test.d.ts +1 -0
  119. package/lib/types/test/injection.test.d.ts +1 -0
  120. package/lib/types/test/kind-filter.test.d.ts +1 -0
  121. package/lib/types/test/legacy-state.test.d.ts +1 -0
  122. package/lib/types/test/log.test.d.ts +1 -0
  123. package/lib/types/test/loops.test.d.ts +1 -0
  124. package/lib/types/test/memory.test.d.ts +1 -0
  125. package/lib/types/test/notices.test.d.ts +1 -0
  126. package/lib/types/test/persona.test.d.ts +1 -0
  127. package/lib/types/test/prefilter.test.d.ts +1 -0
  128. package/lib/types/test/preset.test.d.ts +1 -0
  129. package/lib/types/test/raw-recall.test.d.ts +1 -0
  130. package/lib/types/test/recall.test.d.ts +1 -0
  131. package/lib/types/test/reflection.test.d.ts +1 -0
  132. package/lib/types/test/remote.test.d.ts +1 -0
  133. package/lib/types/test/retention.test.d.ts +1 -0
  134. package/lib/types/test/retrieval.test.d.ts +1 -0
  135. package/lib/types/test/rotation.test.d.ts +1 -0
  136. package/lib/types/test/schedule.test.d.ts +1 -0
  137. package/lib/types/test/settings-card.test.d.ts +1 -0
  138. package/lib/types/test/skills.test.d.ts +1 -0
  139. package/lib/types/test/state.test.d.ts +1 -0
  140. package/lib/types/test/subagent-contract.test.d.ts +1 -0
  141. package/lib/types/test/sweep.test.d.ts +1 -0
  142. package/lib/types/test/sync.test.d.ts +1 -0
  143. package/lib/types/test/time.test.d.ts +1 -0
  144. package/lib/types/time.d.ts +67 -0
  145. package/lib/types/tool.d.ts +9 -0
  146. package/lib/types/types.d.ts +374 -0
  147. package/lib/types/workspace.d.ts +20 -0
  148. package/lib/types.js +47 -0
  149. package/lib/workspace.js +65 -0
  150. package/locale/en.json +7 -0
  151. package/locale/zh.json +7 -0
  152. package/package.json +126 -4
@@ -0,0 +1,352 @@
1
+ import type { LlmRuntime } from '@deepseek-ai/dsh-llm';
2
+ import type { Session } from '@deepseek-ai/dsh-session';
3
+ import type { MemoryDraft } from './types.js';
4
+ /** Model-facing transcript line budget for one extraction window. */
5
+ export interface ExtractWindow {
6
+ /** Rendered transcript, oldest first. */
7
+ readonly text: string;
8
+ /** Highest surface seq included, or `undefined` when nothing was new. */
9
+ readonly lastSeq: number | undefined;
10
+ /** Number of messages included. */
11
+ readonly messages: number;
12
+ /**
13
+ * The messages behind {@link ExtractWindow.text}, with their surface seq.
14
+ *
15
+ * The extractor answers with a verbatim quote, and this is what the quote is
16
+ * checked against: a candidate whose quote is not a substring of one of these
17
+ * messages is dropped before it reaches the store. `text` is not enough
18
+ * because it carries the `USER:`/`ASSISTANT:` prefixes and the quote comes from
19
+ * the message body.
20
+ */
21
+ readonly sources: readonly {
22
+ readonly seq: number;
23
+ readonly text: string;
24
+ }[];
25
+ }
26
+ /**
27
+ * The system instruction for the extraction call.
28
+ *
29
+ * The reply's key order is load-bearing, not cosmetic. `maxOutputTokens` is a
30
+ * ceiling on the *whole* completion, reasoning included, and the reply's only
31
+ * recoverable part is the sequence of COMPLETE memory objects: when the ceiling
32
+ * bites mid-reply, `repairTruncatedJson` can close the array after the last
33
+ * finished object, but it can never resurrect one that was not written yet.
34
+ * With `summary` first, a model that spends the budget on the summary paragraph
35
+ * loses every memory at once — measured on this store, 2026-09-23/24, five
36
+ * extraction calls came back capped with nothing usable (`[5766 in / 4096 out]`
37
+ * … `[24490 in / 4096 out]`, `raise extractMaxOutputTokens`), four of them on
38
+ * `deepseek-flash` at `reasoningEffort: high` and one on `gpt-6-astra`, where
39
+ * the thinking tokens alone can consume the cap. Memories first makes the same
40
+ * truncation keep everything that finished.
41
+ */
42
+ export declare const EXTRACT_SYSTEM: string;
43
+ /**
44
+ * JSON output contract for one extraction call.
45
+ *
46
+ * `memories` is declared (and required) before `summary` on purpose: property
47
+ * declaration order guides generation, and the array is the part a truncated
48
+ * reply can still salvage. See {@link EXTRACT_SYSTEM}.
49
+ */
50
+ export declare const EXTRACT_JSON_SCHEMA: {
51
+ readonly type: 'object';
52
+ readonly additionalProperties: false;
53
+ readonly required: readonly ['memories', 'summary'];
54
+ readonly properties: {
55
+ readonly memories: {
56
+ readonly type: 'array';
57
+ readonly items: {
58
+ readonly type: 'object';
59
+ readonly additionalProperties: false;
60
+ readonly required: readonly ['scope', 'title', 'body', 'appliesTo', 'quote'];
61
+ readonly properties: {
62
+ readonly scope: {
63
+ readonly type: 'string';
64
+ readonly enum: readonly ['global', 'project'];
65
+ };
66
+ readonly kind: {
67
+ readonly type: 'string';
68
+ readonly enum: readonly ['fact', 'preference', 'knowledge', 'failure', 'procedure'];
69
+ };
70
+ readonly title: {
71
+ readonly type: 'string';
72
+ };
73
+ readonly body: {
74
+ readonly type: 'string';
75
+ };
76
+ readonly tags: {
77
+ readonly type: 'array';
78
+ readonly items: {
79
+ readonly type: 'string';
80
+ };
81
+ };
82
+ readonly keys: {
83
+ readonly type: 'array';
84
+ readonly items: {
85
+ readonly type: 'string';
86
+ };
87
+ };
88
+ readonly appliesTo: {
89
+ readonly type: 'string';
90
+ };
91
+ readonly quote: {
92
+ readonly type: 'string';
93
+ };
94
+ readonly voice: {
95
+ readonly type: 'string';
96
+ readonly enum: readonly ['user', 'assistant'];
97
+ };
98
+ readonly durability: {
99
+ readonly type: 'string';
100
+ readonly enum: readonly ['durable', 'snapshot'];
101
+ };
102
+ readonly asOf: {
103
+ readonly type: 'string';
104
+ };
105
+ };
106
+ };
107
+ };
108
+ readonly loops: {
109
+ readonly type: 'array';
110
+ readonly items: {
111
+ readonly type: 'object';
112
+ readonly additionalProperties: false;
113
+ readonly required: readonly ['text'];
114
+ readonly properties: {
115
+ readonly text: {
116
+ readonly type: 'string';
117
+ };
118
+ readonly dueAt: {
119
+ readonly type: 'string';
120
+ };
121
+ };
122
+ };
123
+ };
124
+ readonly summary: {
125
+ readonly type: 'string';
126
+ };
127
+ };
128
+ };
129
+ /**
130
+ * Redact credential-shaped text. Deliberately conservative and applied before
131
+ * anything is written, because a memory store outlives the session it came from.
132
+ * @param text - candidate memory text.
133
+ * @returns the text with credential-shaped spans replaced.
134
+ */
135
+ export declare function redactSecrets(text: string): string;
136
+ /**
137
+ * Collect the conversation tail a session has produced since `afterSeq`.
138
+ *
139
+ * Only user and assistant prose is taken: tool results are dropped because
140
+ * they are bulky and rarely the durable lesson, and plugin-injected context is
141
+ * dropped so memory never feeds on its own summaries.
142
+ *
143
+ * @param session - session to read.
144
+ * @param afterSeq - last surface seq already mined (exclusive).
145
+ * @param maxMessages - message cap.
146
+ * @param maxChars - transcript character cap; the newest messages win.
147
+ * @returns the rendered window and the highest included seq.
148
+ */
149
+ export declare function collectWindow(session: Session, afterSeq: number, maxMessages: number, maxChars: number): ExtractWindow;
150
+ /**
151
+ * Resolve the provider/model route for a model call.
152
+ *
153
+ * The session's own route is inherited deliberately — a background call should
154
+ * not silently run on a model nobody chose — but the reasoning level comes with
155
+ * it, and that level is what the output cap has to pay for: a thinking model
156
+ * bills its reasoning against `maxOutputTokens` before the first visible token.
157
+ * Carrying the level out with the route is what lets the caller's log line name
158
+ * the reason a capped call produced nothing, instead of only naming the knob.
159
+ *
160
+ * @param session - the session whose logged route is the fallback.
161
+ * @param provider - an explicit provider, if the caller names one.
162
+ * @param model - an explicit model, if the caller names one.
163
+ * @param fallback - the route to use when the session has none.
164
+ * @returns the route, or `undefined` when no route can be resolved.
165
+ */
166
+ export declare function resolveLlmRoute(session: Session, provider: string | undefined, model: string | undefined, fallback: {
167
+ provider?: string;
168
+ model?: string;
169
+ }): ExtractionRoute | undefined;
170
+ /**
171
+ * Parse the model's JSON reply into the session summary and its drafts,
172
+ * tolerating a code fence.
173
+ *
174
+ * Every usable draft in the reply is validated even once the cap is reached, so
175
+ * the caller can report how many were dropped. A pass that always lands exactly
176
+ * on the cap looks identical to a pass that found exactly that many facts, and
177
+ * the difference is the only signal that `extractMaxMemories` is the knob
178
+ * limiting what the plugin remembers.
179
+ *
180
+ * @param text - the model's reply.
181
+ * @param maxMemories - how many drafts to keep.
182
+ * @param sessionId - session the drafts came from, recorded as provenance.
183
+ * @returns the drafts, the evidence summary, and how many were over the cap.
184
+ */
185
+ export declare function parseExtraction(text: string, maxMemories: number, sessionId: string): {
186
+ drafts: MemoryDraft[];
187
+ loops: {
188
+ text: string;
189
+ dueAt?: number;
190
+ }[];
191
+ summary: string;
192
+ dropped: number;
193
+ };
194
+ /** What {@link bindEvidence} made of one reply. */
195
+ export interface EvidenceBinding {
196
+ /** Drafts that carry a quote found verbatim in the window's messages. */
197
+ readonly drafts: readonly MemoryDraft[];
198
+ /** Drafts dropped because the quote was missing, too short, or not in the transcript. */
199
+ readonly unsupported: number;
200
+ }
201
+ /**
202
+ * Check every draft's quote against the transcript it claims to come from.
203
+ *
204
+ * This is the mechanical half of the evidence contract: the extractor is asked
205
+ * to copy a verbatim passage, and nothing else in the pipeline can tell a copied
206
+ * passage from a plausible one. A draft without a usable quote is dropped rather
207
+ * than stored unverified — the whole point of the field is that a memory the
208
+ * transcript does not support must not enter the store silently. The message the
209
+ * quote matched supplies an `evidenceSeq`, so `memory action=evidence` can point
210
+ * at the exact turn.
211
+ *
212
+ * @param drafts - drafts parsed from the reply.
213
+ * @param sources - messages in the window the reply was shown.
214
+ * @returns the verified drafts and how many were rejected.
215
+ */
216
+ export declare function bindEvidence(drafts: readonly MemoryDraft[], sources: readonly {
217
+ readonly seq: number;
218
+ readonly text: string;
219
+ }[]): EvidenceBinding;
220
+ /** Everything one extraction call needs. */
221
+ export interface ExtractionRequest {
222
+ /** Session being mined. */
223
+ readonly session: Session;
224
+ /** Transcript window. */
225
+ readonly window: ExtractWindow;
226
+ /** Model-facing label of the project scope, for the prompt. */
227
+ readonly projectLabel: string;
228
+ /**
229
+ * Titles already stored in the scopes this pass may write to.
230
+ *
231
+ * The extractor is otherwise blind to what is already known, so it re-derives
232
+ * the same lesson from overlapping windows and stores it under a new title.
233
+ * Measured on a real store, one session's handwriting-extraction lesson was
234
+ * stored twice — once in Chinese, once in English — because each pass phrased
235
+ * the title differently and ids come from titles.
236
+ */
237
+ readonly knownTitles?: readonly string[];
238
+ /** Explicit route override. */
239
+ readonly provider?: string;
240
+ readonly model?: string;
241
+ /** Route used when the session has logged no request header yet. */
242
+ readonly fallbackRoute?: {
243
+ readonly provider?: string;
244
+ readonly model?: string;
245
+ };
246
+ /** Caps and deadline. */
247
+ readonly maxOutputTokens: number;
248
+ readonly maxMemories: number;
249
+ readonly timeoutMs: number;
250
+ /** Cancellation. */
251
+ readonly signal: AbortSignal;
252
+ }
253
+ /** Token cost of one extraction call, as the provider reported it. */
254
+ export interface ExtractionUsage {
255
+ /** Prompt tokens the call was billed for. */
256
+ readonly inputTokens: number;
257
+ /** Completion tokens the call produced. */
258
+ readonly outputTokens: number;
259
+ }
260
+ /**
261
+ * The provider/model an extraction call actually ran on.
262
+ *
263
+ * `reasoningEffort` is present only when the inherited session route declared
264
+ * one, and it is the field that explains a capped call: a thinking model spends
265
+ * the output ceiling on reasoning before it writes any JSON.
266
+ */
267
+ export interface ExtractionRoute {
268
+ readonly provider: string;
269
+ readonly model: string;
270
+ readonly reasoningEffort?: string;
271
+ }
272
+ /** Outcome of one extraction call. */
273
+ export type ExtractionOutcome = {
274
+ readonly kind: 'memories';
275
+ readonly drafts: readonly MemoryDraft[];
276
+ /** Promises the user made that are still open. */
277
+ readonly loops: readonly {
278
+ text: string;
279
+ dueAt?: number;
280
+ }[];
281
+ /** What the session was about, stored as the evidence behind the drafts. */
282
+ readonly summary: string;
283
+ /** Usable drafts the reply offered beyond `maxMemories`, reported to the caller. */
284
+ readonly dropped: number;
285
+ /**
286
+ * Drafts rejected because their evidence quote did not appear verbatim in
287
+ * the window. Reported so a rising count is visible instead of reading as
288
+ * an unusually quiet extractor.
289
+ */
290
+ readonly unsupported: number;
291
+ readonly route: ExtractionRoute;
292
+ /**
293
+ * Whether the reply was cut short by the output cap and salvaged.
294
+ *
295
+ * A caller must be able to tell "the extractor found three facts" from "the
296
+ * extractor found three facts and was cut off before it finished", because
297
+ * only the second one means `extractMaxOutputTokens` is the binding knob.
298
+ */
299
+ readonly truncated?: boolean;
300
+ /**
301
+ * What the call cost, when the adapter reported it.
302
+ *
303
+ * Carried out of here because background extraction runs outside any
304
+ * session, so this is the only place the spend can be observed at all: the
305
+ * cost dashboards read session logs, and this call writes none.
306
+ */
307
+ readonly usage?: ExtractionUsage;
308
+ } | {
309
+ readonly kind: 'none';
310
+ /**
311
+ * Why the call produced no memory.
312
+ *
313
+ * `max-tokens` and `incomplete` are capped/failed finishes rather than an
314
+ * empty answer: they are reported, never thrown, and `max-tokens` is the
315
+ * one that tells a reader which configuration knob to raise.
316
+ */
317
+ readonly reason: 'empty-window' | 'no-route' | 'empty-reply' | 'unsupported-evidence' | 'max-tokens' | 'incomplete';
318
+ /**
319
+ * The route the call ran on, when one was resolved.
320
+ *
321
+ * Absent for `empty-window` and `no-route`, which fail before a route
322
+ * exists. Present otherwise so the caller can name the model — and its
323
+ * reasoning level — in the line that reports the cap.
324
+ */
325
+ readonly route?: ExtractionRoute;
326
+ readonly usage?: ExtractionUsage;
327
+ };
328
+ /**
329
+ * Run one extraction call and return the drafts it produced.
330
+ *
331
+ * Failures are the caller's to contain: this function throws only on transport
332
+ * or protocol errors, and never mutates the session.
333
+ *
334
+ * @param llm - the LLM runtime.
335
+ * @param request - session, window, route, and budget.
336
+ * @returns the parsed drafts, or a reason there are none.
337
+ */
338
+ export declare function runExtraction(llm: LlmRuntime, request: ExtractionRequest): Promise<ExtractionOutcome>;
339
+ /**
340
+ * Close a JSON reply the output cap cut in half.
341
+ *
342
+ * The reply is one object whose `memories` array is written first, so a
343
+ * truncated reply is an unterminated array whose earlier elements are complete.
344
+ * Candidate cut points are tried from the end backwards — the first one that
345
+ * parses wins — which keeps every memory that was fully written. A reply cut
346
+ * inside a string, or before the first object, yields `''` so the caller can
347
+ * report the cap instead of pretending it salvaged something.
348
+ *
349
+ * @param text - the truncated reply.
350
+ * @returns parseable JSON, or an empty string when no cut point parses.
351
+ */
352
+ export declare function repairTruncatedJson(text: string): string;
@@ -0,0 +1,83 @@
1
+ import type { LlmRuntime } from '@deepseek-ai/dsh-llm';
2
+ import type { Session } from '@deepseek-ai/dsh-session';
3
+ /** One thing the assistant could say, for the gate to judge. */
4
+ export interface GateCandidate {
5
+ /** Stable id, so the reply can name what it chose. */
6
+ readonly id: string;
7
+ /** One line the user would see. */
8
+ readonly title: string;
9
+ /** Enough context to judge: what it is, how old, where it came from. */
10
+ readonly detail: string;
11
+ }
12
+ /** What the gate decided. */
13
+ export interface GateOutcome {
14
+ /** Ids allowed to be raised; empty means silence. */
15
+ readonly deliver: ReadonlySet<string>;
16
+ /** Why, for the log — including why it stayed silent. */
17
+ readonly reason: string;
18
+ /** Set when the gate could not run at all. */
19
+ readonly skipped?: 'no-route' | 'no-llm' | 'failed';
20
+ }
21
+ /** The instruction. Its tone is the design: the model's job is to say no. */
22
+ export declare const GATE_SYSTEM: string;
23
+ /** Output contract. */
24
+ export declare const GATE_JSON_SCHEMA: {
25
+ readonly type: 'object';
26
+ readonly additionalProperties: false;
27
+ readonly required: readonly ['deliver', 'reason'];
28
+ readonly properties: {
29
+ readonly deliver: {
30
+ readonly type: 'array';
31
+ readonly items: {
32
+ readonly type: 'string';
33
+ };
34
+ };
35
+ readonly reason: {
36
+ readonly type: 'string';
37
+ };
38
+ };
39
+ };
40
+ /** Everything one gate call needs. */
41
+ export interface GateRequest {
42
+ /** LLM runtime. */
43
+ readonly llm: LlmRuntime | undefined;
44
+ /** Session that supplies the route and its request header. */
45
+ readonly session: Session | undefined;
46
+ /** What could be said. */
47
+ readonly candidates: readonly GateCandidate[];
48
+ /** The user profile, as background. */
49
+ readonly persona?: string;
50
+ /** Explicit route override. */
51
+ readonly provider?: string;
52
+ readonly model?: string;
53
+ /** Deadline for the call. */
54
+ readonly timeoutMs: number;
55
+ /** Plugin lifecycle signal. */
56
+ readonly signal: AbortSignal;
57
+ }
58
+ /**
59
+ * Ask whether any of these is worth saying now.
60
+ *
61
+ * Every failure path returns an empty set: a gate that cannot run must not
62
+ * invent permission. The caller logs the reason either way, because "why did it
63
+ * stay quiet?" is a question that must be answerable months later.
64
+ *
65
+ * @param request - candidates, route, profile, budget.
66
+ * @returns the ids allowed to be raised.
67
+ */
68
+ export declare function gateNotices(request: GateRequest): Promise<GateOutcome>;
69
+ /**
70
+ * Parse a gate reply, keeping only ids it was actually shown.
71
+ *
72
+ * An id the model invented is dropped rather than trusted: the reply is a
73
+ * permission slip, and it can only ever authorise something that was on the list.
74
+ *
75
+ * @param text - the raw reply.
76
+ * @param candidates - what the model was shown.
77
+ * @returns the allowed ids and the reason.
78
+ */
79
+ export declare function parseGateReply(text: string, candidates: readonly GateCandidate[]): {
80
+ deliver: Set<string>;
81
+ reason: string;
82
+ failed: boolean;
83
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Normalize one remote URL into `<host>/<owner>/<repo>`.
3
+ *
4
+ * Two machines that cloned the same repository with different transports must
5
+ * agree here, or the origin adds no identity at all: `git@host:o/r.git`,
6
+ * `ssh://git@host/o/r.git` and `https://token@host/o/r` are one repository.
7
+ * Credentials, scheme, host case, a trailing slash and the `.git` suffix are
8
+ * therefore dropped; the owner/repo path keeps its case because forges (and
9
+ * self-hosted servers) treat paths case-sensitively.
10
+ *
11
+ * @param value - a `url` value from a git config, or anything else.
12
+ * @returns the normalized origin, or `undefined` when it names no repository.
13
+ */
14
+ export declare function normalizeGitUrl(value: string): string | undefined;
15
+ /**
16
+ * Read one checkout's `origin` remote as a normalized project origin.
17
+ *
18
+ * @param root - absolute workspace root, which must be a checkout for any
19
+ * origin to exist.
20
+ * @returns the normalized origin, or `undefined` when the directory is not a
21
+ * git checkout, has no `origin` remote, or its git files cannot be read.
22
+ */
23
+ export declare function gitOrigin(root: string): Promise<string | undefined>;