@plurnk/plurnk-grammar 0.1.0 → 0.2.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.
@@ -0,0 +1,491 @@
1
+ // @generated by scriptify/generate-types.ts from schema/*.json
2
+ // DO NOT EDIT — run `npm run build:types` to regenerate.
3
+
4
+ export interface Agent {
5
+ version: number
6
+ provider: ProviderDeclaration
7
+ /**
8
+ * Agent-wide default scheme registrations. The v0 inventory ships with `plurnk`, `known`, `unknown`; everything else is plugin-registered.
9
+ */
10
+ scheme_registry: SchemeRegistration[]
11
+ }
12
+ /**
13
+ * Declaration of the active provider for an agent. The grammar package owns these four fields; auth/connection config lives in the agent repo.
14
+ */
15
+
16
+ export interface ProviderDeclaration {
17
+ /**
18
+ * API vendor identifier (e.g. "anthropic", "openai", "google", "local").
19
+ */
20
+ provider: string
21
+ /**
22
+ * Model family (e.g. "claude", "gpt", "gemini", "llama").
23
+ */
24
+ family: string
25
+ /**
26
+ * Specific model id (e.g. "claude-opus-4-7").
27
+ */
28
+ model: string
29
+ /**
30
+ * Total context window in tokens.
31
+ */
32
+ contextSize: number
33
+ /**
34
+ * ISO 4217 code; the unit `cost_pico` is denominated in.
35
+ */
36
+ currency: string
37
+ }
38
+ /**
39
+ * A scheme entry in the agent's scheme registry. Defines what `<name>://` resolves to and how it's accessible.
40
+ */
41
+
42
+ export interface SchemeRegistration {
43
+ /**
44
+ * Scheme name without `://`. Matches the URL scheme character class.
45
+ */
46
+ name: string
47
+ model_visible: boolean
48
+ category: string
49
+ default_scope: ("agent" | "session")
50
+ /**
51
+ * Channel name selected when an op against this scheme has no fragment. Conventionally `body`; exec schemes typically declare `stdout`.
52
+ */
53
+ default_channel: string
54
+ writable_by: ("model" | "client" | "system" | "plugin")[]
55
+ volatile: boolean
56
+ handler: (string | null)
57
+ }
58
+
59
+ export interface ChannelContent {
60
+ /**
61
+ * Raw content bytes/string for this channel. Binary content awaits a future encoding pass (see AGENTS.md).
62
+ */
63
+ content: string
64
+ mimetype: string
65
+ /**
66
+ * Token count of `content` under the active model's tokenizer.
67
+ */
68
+ tokens: number
69
+ }
70
+
71
+ export type Entry = ({
72
+ [k: string]: unknown
73
+ } & {
74
+ id: number
75
+ version: number
76
+ scope: ("agent" | "session")
77
+ session_id: (number | null)
78
+ scheme: (string | null)
79
+ username: (string | null)
80
+ password: (string | null)
81
+ hostname: (string | null)
82
+ port: (number | null)
83
+ pathname: string
84
+ params: (Params | null)
85
+ /**
86
+ * Named channels on this entry. Keys are channel names (lowercase identifiers); values are ChannelContent. Must be non-empty. The scheme registry declares which channel is the default for unspecified ops.
87
+ */
88
+ channels: {
89
+ [k: string]: ChannelContent
90
+ }
91
+ attributes: {
92
+
93
+ }
94
+ tags: string[]
95
+ })
96
+
97
+ /**
98
+ * URL query parameters parsed into a JSON object. Single-value keys map to strings; multi-value keys (repeated in the original query string) map to arrays of strings. Empty object when the URL has no query string; nullable usages wrap this schema in a oneOf with null.
99
+ */
100
+
101
+ export interface Params {
102
+ [k: string]: (string | string[])
103
+ }
104
+ /**
105
+ * One named stream of content on an entry. Channels carry distinct, parallel views of an entry (e.g. `stdout` and `stderr` on `exec://`; `body` and `headers` on `https://`; `body` and `symbols` on a code file). Each channel has its own content bytes, mimetype, and token count.
106
+ */
107
+
108
+ export interface LineMarker {
109
+ first: number
110
+ last: (number | null)
111
+ }
112
+
113
+ export type LogEntry = ({
114
+ [k: string]: unknown
115
+ } & {
116
+ id: number
117
+ version: number
118
+ run_id: number
119
+ loop_id: number
120
+ turn_id: number
121
+ action_index: number
122
+ at: string
123
+ origin: ("model" | "client" | "system" | "plugin")
124
+ op: ("FIND" | "READ" | "EDIT" | "COPY" | "MOVE" | "SHOW" | "HIDE" | "SEND" | "EXEC")
125
+ suffix: string
126
+ signal: (string[] | number | string | null)
127
+ target_scheme: (string | null)
128
+ target_username: (string | null)
129
+ target_password: (string | null)
130
+ target_hostname: (string | null)
131
+ target_port: (number | null)
132
+ target_pathname: (string | null)
133
+ target_params: (Params | null)
134
+ /**
135
+ * Channel selector at request time. Names the channel the op targeted; null when the op used the scheme's default channel.
136
+ */
137
+ target_fragment: (string | null)
138
+ lineMarker: (LineMarker | null)
139
+ /**
140
+ * Raw request payload. For origin=model: the literal plurnk DSL substring of assistant.content. For origin=system/client/plugin: whatever the originator emitted, with `mimetype_tx` declaring the structure.
141
+ */
142
+ tx: string
143
+ /**
144
+ * Mimetype of `tx`. Typically `text/x-plurnk` for model-origin rows; arbitrary per-origin for system/client/plugin.
145
+ */
146
+ mimetype_tx: string
147
+ /**
148
+ * Raw response payload bytes/string.
149
+ */
150
+ rx: string
151
+ mimetype_rx: string
152
+ status_rx: number
153
+ tokens: number
154
+ })
155
+
156
+ /**
157
+ * URL query parameters parsed into a JSON object. Single-value keys map to strings; multi-value keys (repeated in the original query string) map to arrays of strings. Empty object when the URL has no query string; nullable usages wrap this schema in a oneOf with null.
158
+ */
159
+
160
+ export interface Loop {
161
+ id: number
162
+ version: number
163
+ run_id: number
164
+ /**
165
+ * 1-based within the run.
166
+ */
167
+ sequence: number
168
+ /**
169
+ * 102 = continuing; 200 = terminal success; 499 = terminal cancellation.
170
+ */
171
+ status: (102 | 200 | 499)
172
+ /**
173
+ * The original user prompt for this loop, replayed on every turn.
174
+ */
175
+ prompt: string
176
+ }
177
+
178
+ export type MatcherBody = (XPathBody | RegexBody | JsonPathBody | GlobBody)
179
+
180
+ /**
181
+ * XPath 1.0 expression. Validated at parse time via the xpath library.
182
+ */
183
+
184
+ export interface XPathBody {
185
+ dialect: "xpath"
186
+ raw: string
187
+ }
188
+ /**
189
+ * JavaScript regex literal `/pattern/flags`. Pattern and flags are split out for direct use. `raw` preserves the literal form for round-tripping.
190
+ */
191
+
192
+ export interface RegexBody {
193
+ dialect: "regex"
194
+ raw: string
195
+ pattern: string
196
+ flags: string
197
+ }
198
+ /**
199
+ * JSONPath expression. Validated at parse time via jsonpath-plus.
200
+ */
201
+
202
+ export interface JsonPathBody {
203
+ dialect: "jsonpath"
204
+ raw: string
205
+ }
206
+ /**
207
+ * Pattern with no dialect prefix; treated as a glob/literal match.
208
+ */
209
+
210
+ export interface GlobBody {
211
+ dialect: "glob"
212
+ raw: string
213
+ }
214
+
215
+ export type PlurnkStatement = (FindStatement | ReadStatement | ShowStatement | HideStatement | EditStatement | CopyStatement | MoveStatement | SendStatement | ExecStatement)
216
+ /**
217
+ * A parsed path slot from a plurnk statement. Discriminated on `kind`: either a bare local path (no scheme) or a fully decomposed URL.
218
+ */
219
+
220
+ export type ParsedPath = (LocalPath | UrlPath)
221
+ /**
222
+ * Parsed body of a FIND/READ/SHOW/HIDE statement, discriminated on `dialect`. The dialect is determined by the body's leading characters (`//` xpath, `/` regex, `$` jsonpath, else glob). The regex variant carries pattern/flags split out of the `/pattern/flags` literal; the compiled `RegExp` object on the in-memory AST is a runtime ergonomic only and is not part of the persisted/wire contract.
223
+ */
224
+
225
+ export interface Packet {
226
+ /**
227
+ * Total packet tokens — sum of section subtotals.
228
+ */
229
+ tokens: number
230
+ system: {
231
+ tokens: number
232
+ /**
233
+ * text/markdown — plurnk grammar + scheme registry refs.
234
+ */
235
+ system_definition: string
236
+ /**
237
+ * text/markdown — identity / mission.
238
+ */
239
+ persona: string
240
+ index: Entry[]
241
+ log: LogEntry[]
242
+ }
243
+ user: {
244
+ tokens: number
245
+ /**
246
+ * Copy of loop.prompt — never null on a continuation turn.
247
+ */
248
+ prompt: string
249
+ /**
250
+ * text/markdown — dynamically generated tables for budget/status/counts.
251
+ */
252
+ turn: string
253
+ /**
254
+ * text/markdown — per-turn rules.
255
+ */
256
+ system_requirements: string
257
+ }
258
+ assistant: {
259
+ tokens: number
260
+ /**
261
+ * Raw DSL string emitted by the model.
262
+ */
263
+ content: string
264
+ /**
265
+ * Parsed PlurnkStatement[] derived from `content`.
266
+ */
267
+ ops: PlurnkStatement[]
268
+ /**
269
+ * text/plain — provider-exposed CoT when present, null otherwise.
270
+ */
271
+ reasoning: (string | null)
272
+ [k: string]: unknown
273
+ }
274
+ assistantRaw: unknown
275
+ }
276
+ /**
277
+ * URL query parameters parsed into a JSON object. Single-value keys map to strings; multi-value keys (repeated in the original query string) map to arrays of strings. Empty object when the URL has no query string; nullable usages wrap this schema in a oneOf with null.
278
+ */
279
+
280
+ export interface FindStatement {
281
+ op: "FIND"
282
+ suffix: string
283
+ signal: (string[] | null)
284
+ path: (ParsedPath | null)
285
+ lineMarker: (LineMarker | null)
286
+ body: (MatcherBody | null)
287
+ position: Position
288
+ }
289
+ /**
290
+ * A bare local path with no `scheme://` prefix. The raw string is stored verbatim; resolution is the runtime's job.
291
+ */
292
+
293
+ export interface LocalPath {
294
+ kind: "local"
295
+ raw: string
296
+ }
297
+ /**
298
+ * A path with a `scheme://` prefix, fully decomposed via WHATWG URL.
299
+ */
300
+
301
+ export interface UrlPath {
302
+ kind: "url"
303
+ raw: string
304
+ scheme: string
305
+ username: (string | null)
306
+ password: (string | null)
307
+ hostname: (string | null)
308
+ port: (number | null)
309
+ pathname: string
310
+ params: Params
311
+ fragment: (string | null)
312
+ }
313
+ /**
314
+ * XPath 1.0 expression. Validated at parse time via the xpath library.
315
+ */
316
+
317
+ export interface Position {
318
+ line: number
319
+ column: number
320
+ }
321
+
322
+ export interface ReadStatement {
323
+ op: "READ"
324
+ suffix: string
325
+ signal: (string[] | null)
326
+ path: (ParsedPath | null)
327
+ lineMarker: (LineMarker | null)
328
+ body: (MatcherBody | null)
329
+ position: Position
330
+ }
331
+
332
+ export interface ShowStatement {
333
+ op: "SHOW"
334
+ suffix: string
335
+ signal: (string[] | null)
336
+ path: (ParsedPath | null)
337
+ lineMarker: (LineMarker | null)
338
+ body: (MatcherBody | null)
339
+ position: Position
340
+ }
341
+
342
+ export interface HideStatement {
343
+ op: "HIDE"
344
+ suffix: string
345
+ signal: (string[] | null)
346
+ path: (ParsedPath | null)
347
+ lineMarker: (LineMarker | null)
348
+ body: (MatcherBody | null)
349
+ position: Position
350
+ }
351
+
352
+ export interface EditStatement {
353
+ op: "EDIT"
354
+ suffix: string
355
+ signal: (string[] | null)
356
+ path: (ParsedPath | null)
357
+ lineMarker: (LineMarker | null)
358
+ body: (string | null)
359
+ position: Position
360
+ }
361
+
362
+ export interface CopyStatement {
363
+ op: "COPY"
364
+ suffix: string
365
+ signal: (string[] | null)
366
+ path: (ParsedPath | null)
367
+ lineMarker: (LineMarker | null)
368
+ body: (ParsedPath | null)
369
+ position: Position
370
+ }
371
+
372
+ export interface MoveStatement {
373
+ op: "MOVE"
374
+ suffix: string
375
+ signal: (string[] | null)
376
+ path: (ParsedPath | null)
377
+ lineMarker: (LineMarker | null)
378
+ body: (ParsedPath | null)
379
+ position: Position
380
+ }
381
+
382
+ export interface SendStatement {
383
+ op: "SEND"
384
+ suffix: string
385
+ signal: (number | null)
386
+ path: (ParsedPath | null)
387
+ lineMarker: null
388
+ body: (SendBody | null)
389
+ position: Position
390
+ }
391
+ /**
392
+ * Parsed body of a SEND statement. `raw` is the literal body text; `json` is the best-effort `JSON.parse(raw)` result, or null when the body isn't valid JSON.
393
+ */
394
+
395
+ export interface SendBody {
396
+ raw: string
397
+ json: unknown
398
+ }
399
+
400
+ export interface ExecStatement {
401
+ op: "EXEC"
402
+ suffix: string
403
+ signal: (string | null)
404
+ path: (ParsedPath | null)
405
+ lineMarker: null
406
+ body: (string | null)
407
+ position: Position
408
+ }
409
+
410
+ export type TagSignal = (string[] | null)
411
+
412
+ export type PathOrNull = (ParsedPath | null)
413
+ /**
414
+ * A parsed path slot from a plurnk statement. Discriminated on `kind`: either a bare local path (no scheme) or a fully decomposed URL.
415
+ */
416
+
417
+ export type LineMarkerOrNull = (LineMarker | null)
418
+
419
+ export type MatcherBodyOrNull = (MatcherBody | null)
420
+ /**
421
+ * Parsed body of a FIND/READ/SHOW/HIDE statement, discriminated on `dialect`. The dialect is determined by the body's leading characters (`//` xpath, `/` regex, `$` jsonpath, else glob). The regex variant carries pattern/flags split out of the `/pattern/flags` literal; the compiled `RegExp` object on the in-memory AST is a runtime ergonomic only and is not part of the persisted/wire contract.
422
+ */
423
+
424
+ export type SendBodyOrNull = (SendBody | null)
425
+
426
+ export interface Run {
427
+ id: number
428
+ version: number
429
+ session_id: number
430
+ created_at: string
431
+ /**
432
+ * FK to parent run when this is a fork; null for the trunk run.
433
+ */
434
+ parent_run_id: (number | null)
435
+ /**
436
+ * Cumulative cost across this run's turns, in pico-units of the active provider's currency.
437
+ */
438
+ cost_pico: number
439
+ }
440
+
441
+ export interface Session {
442
+ id: number
443
+ version: number
444
+ /**
445
+ * Unique within the agent. Default form: `{modelAlias}-{unixtime}` until renamed.
446
+ */
447
+ name: string
448
+ created_at: string
449
+ /**
450
+ * Cumulative cost across this session's runs.
451
+ */
452
+ cost_pico: number
453
+ scheme_registry_additions: SchemeRegistration[]
454
+ }
455
+ /**
456
+ * A scheme entry in the agent's scheme registry. Defines what `<name>://` resolves to and how it's accessible.
457
+ */
458
+
459
+ export interface Turn {
460
+ id: number
461
+ version: number
462
+ loop_id: number
463
+ /**
464
+ * 1-based within the loop; resets at each new loop.
465
+ */
466
+ sequence: number
467
+ timestamp: string
468
+ status: number
469
+ /**
470
+ * Provider-returned token counts and computed cost.
471
+ */
472
+ usage: {
473
+ prompt: number
474
+ completion: number
475
+ cached: number
476
+ /**
477
+ * Per-turn cost in pico-units of the active provider's currency.
478
+ */
479
+ cost_pico: number
480
+ }
481
+ packet: Packet
482
+ }
483
+ /**
484
+ * One turn's full exchange with the provider: { system, user, assistant, assistantRaw }. system aggregates durable + accumulating context (definition, persona, indexed entries, in-scope log rows). user carries the per-turn ephemera. assistant is the provider-normalized output. assistantRaw is opaque.
485
+ */
486
+
487
+ export interface Visibility {
488
+ entry_id: number
489
+ channel: string
490
+ indexed: boolean
491
+ }
package/src/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ // Schema-derived types are generated from schema/*.json — re-exported here as
2
+ // the single import surface for consumers. Run `npm run build:types` to regenerate.
3
+ export * from "./types.generated.ts";
4
+
5
+ import type { Position, PlurnkStatement } from "./types.generated.ts";
6
+ import type PlurnkParseError from "./PlurnkParseError.ts";
7
+
8
+ // Non-schema types — depend on the PlurnkParseError class and so can't be
9
+ // expressed in JSON Schema. Hand-maintained.
10
+
11
+ export type PlurnkOp =
12
+ | "FIND"
13
+ | "READ"
14
+ | "EDIT"
15
+ | "COPY"
16
+ | "MOVE"
17
+ | "SHOW"
18
+ | "HIDE"
19
+ | "SEND"
20
+ | "EXEC";
21
+
22
+ export type ParseItem =
23
+ | { kind: "statement"; statement: PlurnkStatement }
24
+ | { kind: "error"; error: PlurnkParseError }
25
+ | { kind: "text"; text: string; position: Position };
26
+
27
+ export type ParseResult = {
28
+ items: ParseItem[];
29
+ unparsedTail?: { from: Position; reason: string };
30
+ };