@plurnk/plurnk-grammar 0.1.1 → 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.
@@ -0,0 +1,497 @@
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
+ /**
55
+ * Per-channel content-orientation hints. `head` = whole-document or front-anchored (readers care about the beginning); `tail` = append-temporal stream (readers care about the latest content). Channels not listed default to `head`. Renderers use this to pick truncation direction; the amount to render is a core/runtime concern, not a contract field.
56
+ */
57
+ channel_orientations?: {
58
+ [k: string]: ("head" | "tail")
59
+ }
60
+ writable_by: ("model" | "client" | "system" | "plugin")[]
61
+ volatile: boolean
62
+ handler: (string | null)
63
+ }
64
+
65
+ export interface ChannelContent {
66
+ /**
67
+ * Raw content bytes/string for this channel. Binary content awaits a future encoding pass (see AGENTS.md).
68
+ */
69
+ content: string
70
+ mimetype: string
71
+ /**
72
+ * Token count of `content` under the active model's tokenizer.
73
+ */
74
+ tokens: number
75
+ }
76
+
77
+ export type Entry = ({
78
+ [k: string]: unknown
79
+ } & {
80
+ id: number
81
+ version: number
82
+ scope: ("agent" | "session")
83
+ session_id: (number | null)
84
+ scheme: (string | null)
85
+ username: (string | null)
86
+ password: (string | null)
87
+ hostname: (string | null)
88
+ port: (number | null)
89
+ pathname: string
90
+ params: (Params | null)
91
+ /**
92
+ * 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.
93
+ */
94
+ channels: {
95
+ [k: string]: ChannelContent
96
+ }
97
+ attributes: {
98
+
99
+ }
100
+ tags: string[]
101
+ })
102
+
103
+ /**
104
+ * 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.
105
+ */
106
+
107
+ export interface Params {
108
+ [k: string]: (string | string[])
109
+ }
110
+ /**
111
+ * 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.
112
+ */
113
+
114
+ export interface LineMarker {
115
+ first: number
116
+ last: (number | null)
117
+ }
118
+
119
+ export type LogEntry = ({
120
+ [k: string]: unknown
121
+ } & {
122
+ id: number
123
+ version: number
124
+ run_id: number
125
+ loop_id: number
126
+ turn_id: number
127
+ action_index: number
128
+ at: string
129
+ origin: ("model" | "client" | "system" | "plugin")
130
+ op: ("FIND" | "READ" | "EDIT" | "COPY" | "MOVE" | "SHOW" | "HIDE" | "SEND" | "EXEC")
131
+ suffix: string
132
+ signal: (string[] | number | string | null)
133
+ target_scheme: (string | null)
134
+ target_username: (string | null)
135
+ target_password: (string | null)
136
+ target_hostname: (string | null)
137
+ target_port: (number | null)
138
+ target_pathname: (string | null)
139
+ target_params: (Params | null)
140
+ /**
141
+ * Channel selector at request time. Names the channel the op targeted; null when the op used the scheme's default channel.
142
+ */
143
+ target_fragment: (string | null)
144
+ lineMarker: (LineMarker | null)
145
+ /**
146
+ * 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.
147
+ */
148
+ tx: string
149
+ /**
150
+ * Mimetype of `tx`. Typically `text/x-plurnk` for model-origin rows; arbitrary per-origin for system/client/plugin.
151
+ */
152
+ mimetype_tx: string
153
+ /**
154
+ * Raw response payload bytes/string.
155
+ */
156
+ rx: string
157
+ mimetype_rx: string
158
+ status_rx: number
159
+ tokens: number
160
+ })
161
+
162
+ /**
163
+ * 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.
164
+ */
165
+
166
+ export interface Loop {
167
+ id: number
168
+ version: number
169
+ run_id: number
170
+ /**
171
+ * 1-based within the run.
172
+ */
173
+ sequence: number
174
+ /**
175
+ * 102 = continuing; 200 = terminal success; 499 = terminal cancellation.
176
+ */
177
+ status: (102 | 200 | 499)
178
+ /**
179
+ * The original user prompt for this loop, replayed on every turn.
180
+ */
181
+ prompt: string
182
+ }
183
+
184
+ export type MatcherBody = (XPathBody | RegexBody | JsonPathBody | GlobBody)
185
+
186
+ /**
187
+ * XPath 1.0 expression. Validated at parse time via the xpath library.
188
+ */
189
+
190
+ export interface XPathBody {
191
+ dialect: "xpath"
192
+ raw: string
193
+ }
194
+ /**
195
+ * JavaScript regex literal `/pattern/flags`. Pattern and flags are split out for direct use. `raw` preserves the literal form for round-tripping.
196
+ */
197
+
198
+ export interface RegexBody {
199
+ dialect: "regex"
200
+ raw: string
201
+ pattern: string
202
+ flags: string
203
+ }
204
+ /**
205
+ * JSONPath expression. Validated at parse time via jsonpath-plus.
206
+ */
207
+
208
+ export interface JsonPathBody {
209
+ dialect: "jsonpath"
210
+ raw: string
211
+ }
212
+ /**
213
+ * Pattern with no dialect prefix; treated as a glob/literal match.
214
+ */
215
+
216
+ export interface GlobBody {
217
+ dialect: "glob"
218
+ raw: string
219
+ }
220
+
221
+ export type PlurnkStatement = (FindStatement | ReadStatement | ShowStatement | HideStatement | EditStatement | CopyStatement | MoveStatement | SendStatement | ExecStatement)
222
+ /**
223
+ * A parsed path slot from a plurnk statement. Discriminated on `kind`: either a bare local path (no scheme) or a fully decomposed URL.
224
+ */
225
+
226
+ export type ParsedPath = (LocalPath | UrlPath)
227
+ /**
228
+ * 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.
229
+ */
230
+
231
+ export interface Packet {
232
+ /**
233
+ * Total packet tokens — sum of section subtotals.
234
+ */
235
+ tokens: number
236
+ system: {
237
+ tokens: number
238
+ /**
239
+ * text/markdown — plurnk grammar + scheme registry refs.
240
+ */
241
+ system_definition: string
242
+ /**
243
+ * text/markdown — identity / mission.
244
+ */
245
+ persona: string
246
+ index: Entry[]
247
+ log: LogEntry[]
248
+ }
249
+ user: {
250
+ tokens: number
251
+ /**
252
+ * Copy of loop.prompt — never null on a continuation turn.
253
+ */
254
+ prompt: string
255
+ /**
256
+ * text/markdown — dynamically generated tables for budget/status/counts.
257
+ */
258
+ turn: string
259
+ /**
260
+ * text/markdown — per-turn rules.
261
+ */
262
+ system_requirements: string
263
+ }
264
+ assistant: {
265
+ tokens: number
266
+ /**
267
+ * Raw DSL string emitted by the model.
268
+ */
269
+ content: string
270
+ /**
271
+ * Parsed PlurnkStatement[] derived from `content`.
272
+ */
273
+ ops: PlurnkStatement[]
274
+ /**
275
+ * text/plain — provider-exposed CoT when present, null otherwise.
276
+ */
277
+ reasoning: (string | null)
278
+ [k: string]: unknown
279
+ }
280
+ assistantRaw: unknown
281
+ }
282
+ /**
283
+ * 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.
284
+ */
285
+
286
+ export interface FindStatement {
287
+ op: "FIND"
288
+ suffix: string
289
+ signal: (string[] | null)
290
+ path: (ParsedPath | null)
291
+ lineMarker: (LineMarker | null)
292
+ body: (MatcherBody | null)
293
+ position: Position
294
+ }
295
+ /**
296
+ * A bare local path with no `scheme://` prefix. The raw string is stored verbatim; resolution is the runtime's job.
297
+ */
298
+
299
+ export interface LocalPath {
300
+ kind: "local"
301
+ raw: string
302
+ }
303
+ /**
304
+ * A path with a `scheme://` prefix, fully decomposed via WHATWG URL.
305
+ */
306
+
307
+ export interface UrlPath {
308
+ kind: "url"
309
+ raw: string
310
+ scheme: string
311
+ username: (string | null)
312
+ password: (string | null)
313
+ hostname: (string | null)
314
+ port: (number | null)
315
+ pathname: string
316
+ params: Params
317
+ fragment: (string | null)
318
+ }
319
+ /**
320
+ * XPath 1.0 expression. Validated at parse time via the xpath library.
321
+ */
322
+
323
+ export interface Position {
324
+ line: number
325
+ column: number
326
+ }
327
+
328
+ export interface ReadStatement {
329
+ op: "READ"
330
+ suffix: string
331
+ signal: (string[] | null)
332
+ path: (ParsedPath | null)
333
+ lineMarker: (LineMarker | null)
334
+ body: (MatcherBody | null)
335
+ position: Position
336
+ }
337
+
338
+ export interface ShowStatement {
339
+ op: "SHOW"
340
+ suffix: string
341
+ signal: (string[] | null)
342
+ path: (ParsedPath | null)
343
+ lineMarker: (LineMarker | null)
344
+ body: (MatcherBody | null)
345
+ position: Position
346
+ }
347
+
348
+ export interface HideStatement {
349
+ op: "HIDE"
350
+ suffix: string
351
+ signal: (string[] | null)
352
+ path: (ParsedPath | null)
353
+ lineMarker: (LineMarker | null)
354
+ body: (MatcherBody | null)
355
+ position: Position
356
+ }
357
+
358
+ export interface EditStatement {
359
+ op: "EDIT"
360
+ suffix: string
361
+ signal: (string[] | null)
362
+ path: (ParsedPath | null)
363
+ lineMarker: (LineMarker | null)
364
+ body: (string | null)
365
+ position: Position
366
+ }
367
+
368
+ export interface CopyStatement {
369
+ op: "COPY"
370
+ suffix: string
371
+ signal: (string[] | null)
372
+ path: (ParsedPath | null)
373
+ lineMarker: (LineMarker | null)
374
+ body: (ParsedPath | null)
375
+ position: Position
376
+ }
377
+
378
+ export interface MoveStatement {
379
+ op: "MOVE"
380
+ suffix: string
381
+ signal: (string[] | null)
382
+ path: (ParsedPath | null)
383
+ lineMarker: (LineMarker | null)
384
+ body: (ParsedPath | null)
385
+ position: Position
386
+ }
387
+
388
+ export interface SendStatement {
389
+ op: "SEND"
390
+ suffix: string
391
+ signal: (number | null)
392
+ path: (ParsedPath | null)
393
+ lineMarker: null
394
+ body: (SendBody | null)
395
+ position: Position
396
+ }
397
+ /**
398
+ * 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.
399
+ */
400
+
401
+ export interface SendBody {
402
+ raw: string
403
+ json: unknown
404
+ }
405
+
406
+ export interface ExecStatement {
407
+ op: "EXEC"
408
+ suffix: string
409
+ signal: (string | null)
410
+ path: (ParsedPath | null)
411
+ lineMarker: null
412
+ body: (string | null)
413
+ position: Position
414
+ }
415
+
416
+ export type TagSignal = (string[] | null)
417
+
418
+ export type PathOrNull = (ParsedPath | null)
419
+ /**
420
+ * A parsed path slot from a plurnk statement. Discriminated on `kind`: either a bare local path (no scheme) or a fully decomposed URL.
421
+ */
422
+
423
+ export type LineMarkerOrNull = (LineMarker | null)
424
+
425
+ export type MatcherBodyOrNull = (MatcherBody | null)
426
+ /**
427
+ * 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.
428
+ */
429
+
430
+ export type SendBodyOrNull = (SendBody | null)
431
+
432
+ export interface Run {
433
+ id: number
434
+ version: number
435
+ session_id: number
436
+ created_at: string
437
+ /**
438
+ * FK to parent run when this is a fork; null for the trunk run.
439
+ */
440
+ parent_run_id: (number | null)
441
+ /**
442
+ * Cumulative cost across this run's turns, in pico-units of the active provider's currency.
443
+ */
444
+ cost_pico: number
445
+ }
446
+
447
+ export interface Session {
448
+ id: number
449
+ version: number
450
+ /**
451
+ * Unique within the agent. Default form: `{modelAlias}-{unixtime}` until renamed.
452
+ */
453
+ name: string
454
+ created_at: string
455
+ /**
456
+ * Cumulative cost across this session's runs.
457
+ */
458
+ cost_pico: number
459
+ scheme_registry_additions: SchemeRegistration[]
460
+ }
461
+ /**
462
+ * A scheme entry in the agent's scheme registry. Defines what `<name>://` resolves to and how it's accessible.
463
+ */
464
+
465
+ export interface Turn {
466
+ id: number
467
+ version: number
468
+ loop_id: number
469
+ /**
470
+ * 1-based within the loop; resets at each new loop.
471
+ */
472
+ sequence: number
473
+ timestamp: string
474
+ status: number
475
+ /**
476
+ * Provider-returned token counts and computed cost.
477
+ */
478
+ usage: {
479
+ prompt: number
480
+ completion: number
481
+ cached: number
482
+ /**
483
+ * Per-turn cost in pico-units of the active provider's currency.
484
+ */
485
+ cost_pico: number
486
+ }
487
+ packet: Packet
488
+ }
489
+ /**
490
+ * 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.
491
+ */
492
+
493
+ export interface Visibility {
494
+ entry_id: number
495
+ channel: string
496
+ indexed: boolean
497
+ }
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
+ };