@plurnk/plurnk-grammar 0.2.1 → 0.6.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 (77) hide show
  1. package/bin/plurnk.js +1 -1
  2. package/{schema → dist/schema}/LogEntry.json +1 -1
  3. package/{schema → dist/schema}/Packet.json +16 -4
  4. package/{schema → dist/schema}/ProviderDeclaration.json +3 -3
  5. package/{schema → dist/schema}/Run.json +6 -1
  6. package/{schema → dist/schema}/Session.json +1 -1
  7. package/{schema → dist/schema}/Turn.json +10 -1
  8. package/dist/src/AstBuilder.d.ts +19 -0
  9. package/dist/src/AstBuilder.d.ts.map +1 -0
  10. package/{src/AstBuilder.ts → dist/src/AstBuilder.js} +176 -161
  11. package/dist/src/AstBuilder.js.map +1 -0
  12. package/dist/src/PlurnkErrorStrategy.d.ts +10 -0
  13. package/dist/src/PlurnkErrorStrategy.d.ts.map +1 -0
  14. package/{src/PlurnkErrorStrategy.ts → dist/src/PlurnkErrorStrategy.js} +41 -49
  15. package/dist/src/PlurnkErrorStrategy.js.map +1 -0
  16. package/dist/src/PlurnkParseError.d.ts +14 -0
  17. package/dist/src/PlurnkParseError.d.ts.map +1 -0
  18. package/{src/PlurnkParseError.ts → dist/src/PlurnkParseError.js} +6 -9
  19. package/dist/src/PlurnkParseError.js.map +1 -0
  20. package/dist/src/PlurnkParser.d.ts +6 -0
  21. package/dist/src/PlurnkParser.d.ts.map +1 -0
  22. package/{src/PlurnkParser.ts → dist/src/PlurnkParser.js} +32 -40
  23. package/dist/src/PlurnkParser.js.map +1 -0
  24. package/dist/src/RecordingListener.d.ts +9 -0
  25. package/dist/src/RecordingListener.d.ts.map +1 -0
  26. package/dist/src/RecordingListener.js +19 -0
  27. package/dist/src/RecordingListener.js.map +1 -0
  28. package/dist/src/Validator.d.ts +28 -0
  29. package/dist/src/Validator.d.ts.map +1 -0
  30. package/dist/src/Validator.js +86 -0
  31. package/dist/src/Validator.js.map +1 -0
  32. package/dist/src/generated/plurnkLexer.d.ts +88 -0
  33. package/dist/src/generated/plurnkLexer.d.ts.map +1 -0
  34. package/dist/src/generated/plurnkLexer.js +440 -0
  35. package/dist/src/generated/plurnkLexer.js.map +1 -0
  36. package/dist/src/generated/plurnkParser.d.ts +274 -0
  37. package/dist/src/generated/plurnkParser.d.ts.map +1 -0
  38. package/dist/src/generated/plurnkParser.js +1833 -0
  39. package/dist/src/generated/plurnkParser.js.map +1 -0
  40. package/{src/generated/plurnkParserVisitor.ts → dist/src/generated/plurnkParserVisitor.d.ts} +2 -7
  41. package/dist/src/generated/plurnkParserVisitor.d.ts.map +1 -0
  42. package/dist/src/generated/plurnkParserVisitor.js +131 -0
  43. package/dist/src/generated/plurnkParserVisitor.js.map +1 -0
  44. package/dist/src/index.d.ts +10 -0
  45. package/dist/src/index.d.ts.map +1 -0
  46. package/dist/src/index.js +7 -0
  47. package/dist/src/index.js.map +1 -0
  48. package/dist/src/types.d.ts +23 -0
  49. package/dist/src/types.d.ts.map +1 -0
  50. package/dist/src/types.generated.d.ts +472 -0
  51. package/dist/src/types.generated.d.ts.map +1 -0
  52. package/dist/src/types.generated.js +4 -0
  53. package/dist/src/types.generated.js.map +1 -0
  54. package/dist/src/types.js +4 -0
  55. package/dist/src/types.js.map +1 -0
  56. package/package.json +10 -7
  57. package/plurnk.md +1 -1
  58. package/src/RecordingListener.ts +0 -34
  59. package/src/Validator.ts +0 -94
  60. package/src/generated/plurnkLexer.ts +0 -467
  61. package/src/generated/plurnkParser.ts +0 -1891
  62. package/src/index.ts +0 -29
  63. package/src/types.generated.ts +0 -497
  64. package/src/types.ts +0 -30
  65. /package/{schema → dist/schema}/Agent.json +0 -0
  66. /package/{schema → dist/schema}/ChannelContent.json +0 -0
  67. /package/{schema → dist/schema}/Entry.json +0 -0
  68. /package/{schema → dist/schema}/LineMarker.json +0 -0
  69. /package/{schema → dist/schema}/Loop.json +0 -0
  70. /package/{schema → dist/schema}/MatcherBody.json +0 -0
  71. /package/{schema → dist/schema}/Params.json +0 -0
  72. /package/{schema → dist/schema}/ParsedPath.json +0 -0
  73. /package/{schema → dist/schema}/PlurnkStatement.json +0 -0
  74. /package/{schema → dist/schema}/Position.json +0 -0
  75. /package/{schema → dist/schema}/SchemeRegistration.json +0 -0
  76. /package/{schema → dist/schema}/SendBody.json +0 -0
  77. /package/{schema → dist/schema}/Visibility.json +0 -0
package/bin/plurnk.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { readFileSync } from "node:fs";
3
3
  import { parseArgs } from "node:util";
4
- import { PlurnkParser } from "../src/index.ts";
4
+ import { PlurnkParser } from "../dist/src/index.js";
5
5
 
6
6
  const USAGE = `Usage:
7
7
  plurnk [file] Parse plurnk source from a file (or stdin if omitted or '-')
@@ -58,7 +58,7 @@
58
58
  ]
59
59
  },
60
60
  "tx": { "type": "string", "description": "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." },
61
- "mimetype_tx": { "type": "string", "minLength": 1, "description": "Mimetype of `tx`. Typically `text/x-plurnk` for model-origin rows; arbitrary per-origin for system/client/plugin." },
61
+ "mimetype_tx": { "type": "string", "minLength": 1, "description": "Mimetype of `tx`. Typically `text/vnd.plurnk` for model-origin rows; arbitrary per-origin for system/client/plugin." },
62
62
  "rx": { "type": "string", "description": "Raw response payload bytes/string." },
63
63
  "mimetype_rx": { "type": "string", "minLength": 1 },
64
64
  "status_rx": { "type": "integer", "minimum": 100, "maximum": 599 },
@@ -32,21 +32,33 @@
32
32
  },
33
33
  "user": {
34
34
  "type": "object",
35
- "required": ["tokens", "prompt", "turn", "system_requirements"],
35
+ "required": ["tokens", "prompt", "telemetry", "system_requirements"],
36
36
  "additionalProperties": false,
37
37
  "properties": {
38
38
  "tokens": { "type": "integer", "minimum": 0 },
39
39
  "prompt": { "type": "string", "description": "Copy of loop.prompt — never null on a continuation turn." },
40
- "turn": { "type": "string", "description": "text/markdown — dynamically generated tables for budget/status/counts." },
40
+ "telemetry": {
41
+ "type": "object",
42
+ "description": "Per-turn instrumentation surfaced to the model. `budget` is renderer-provided markdown describing remaining context / cost / etc. `errors` carries actionless failures (parse errors and similar) that the model should confront on this turn. Inner shapes intentionally open at v0; consumers populate as needs solidify.",
43
+ "required": ["budget", "errors"],
44
+ "additionalProperties": false,
45
+ "properties": {
46
+ "budget": { "type": "string", "description": "text/markdown — budget surface (token/cost/etc. left to spend). Empty string when nothing to surface." },
47
+ "errors": {
48
+ "type": "array",
49
+ "items": { "type": "object" },
50
+ "description": "TelemetryError[] — element shape TBD. Empty array when no errors to surface."
51
+ }
52
+ }
53
+ },
41
54
  "system_requirements": { "type": "string", "description": "text/markdown — per-turn rules." }
42
55
  }
43
56
  },
44
57
  "assistant": {
45
58
  "type": "object",
46
- "required": ["tokens", "content", "ops", "reasoning"],
59
+ "required": ["content", "ops", "reasoning"],
47
60
  "additionalProperties": true,
48
61
  "properties": {
49
- "tokens": { "type": "integer", "minimum": 0 },
50
62
  "content": { "type": "string", "description": "Raw DSL string emitted by the model." },
51
63
  "ops": {
52
64
  "type": "array",
@@ -7,9 +7,9 @@
7
7
  "required": ["provider", "family", "model", "contextSize", "currency"],
8
8
  "additionalProperties": false,
9
9
  "properties": {
10
- "provider": { "type": "string", "minLength": 1, "description": "API vendor identifier (e.g. \"anthropic\", \"openai\", \"google\", \"local\")." },
11
- "family": { "type": "string", "minLength": 1, "description": "Model family (e.g. \"claude\", \"gpt\", \"gemini\", \"llama\")." },
12
- "model": { "type": "string", "minLength": 1, "description": "Specific model id (e.g. \"claude-opus-4-7\")." },
10
+ "provider": { "type": "string", "minLength": 1, "description": "API vendor identifier (e.g. \"local\", \"openrouter\", \"anthropic\", \"openai\")." },
11
+ "family": { "type": "string", "minLength": 1, "description": "Model family (e.g. \"gemma\", \"llama\", \"qwen\", \"claude\", \"gpt\", \"gemini\")." },
12
+ "model": { "type": "string", "minLength": 1, "description": "Specific model id (e.g. \"gemma3-12b\")." },
13
13
  "contextSize": { "type": "integer", "minimum": 1, "description": "Total context window in tokens." },
14
14
  "currency": { "type": "string", "pattern": "^[A-Z]{3}$", "description": "ISO 4217 code; the unit `cost_pico` is denominated in." }
15
15
  }
@@ -4,12 +4,17 @@
4
4
  "title": "Run",
5
5
  "description": "A stretch of work within a session. Forkable via parent_run_id. Owns per-run logs and visibility state.",
6
6
  "type": "object",
7
- "required": ["id", "version", "session_id", "created_at", "parent_run_id", "cost_pico"],
7
+ "required": ["id", "version", "session_id", "name", "created_at", "parent_run_id", "cost_pico"],
8
8
  "additionalProperties": false,
9
9
  "properties": {
10
10
  "id": { "type": "integer", "minimum": 1 },
11
11
  "version": { "type": "integer", "minimum": 0 },
12
12
  "session_id": { "type": "integer", "minimum": 1 },
13
+ "name": {
14
+ "type": "string",
15
+ "minLength": 1,
16
+ "description": "Unique within the session. Auto-populated default form `run-{unixtime}` until renamed. Clients display this; cross-table references use `id` so renames don't cascade-break."
17
+ },
13
18
  "created_at": { "type": "string", "format": "date-time" },
14
19
  "parent_run_id": {
15
20
  "type": ["integer", "null"],
@@ -9,7 +9,7 @@
9
9
  "properties": {
10
10
  "id": { "type": "integer", "minimum": 1 },
11
11
  "version": { "type": "integer", "minimum": 0 },
12
- "name": { "type": "string", "minLength": 1, "description": "Unique within the agent. Default form: `{modelAlias}-{unixtime}` until renamed." },
12
+ "name": { "type": "string", "minLength": 1, "description": "Unique within the agent. Auto-populated default form `session-{unixtime}` until renamed. Clients display this; cross-table references use `id` so renames don't cascade-break." },
13
13
  "created_at": { "type": "string", "format": "date-time" },
14
14
  "cost_pico": { "type": "integer", "minimum": 0, "description": "Cumulative cost across this session's runs." },
15
15
  "scheme_registry_additions": {
@@ -4,7 +4,7 @@
4
4
  "title": "Turn",
5
5
  "description": "The leaf of the envelope hierarchy. One model-provider exchange. Persists the full packet plus provider-returned usage and the turn-level status.",
6
6
  "type": "object",
7
- "required": ["id", "version", "loop_id", "sequence", "timestamp", "status", "usage", "packet"],
7
+ "required": ["id", "version", "loop_id", "sequence", "timestamp", "status", "usage", "finish_reason", "model", "packet"],
8
8
  "additionalProperties": false,
9
9
  "properties": {
10
10
  "id": { "type": "integer", "minimum": 1 },
@@ -25,6 +25,15 @@
25
25
  "cost_pico": { "type": "integer", "minimum": 0, "description": "Per-turn cost in pico-units of the active provider's currency." }
26
26
  }
27
27
  },
28
+ "finish_reason": {
29
+ "type": ["string", "null"],
30
+ "description": "Provider-reported completion-state token (`stop` | `length` | `tool_calls` | `content_filter` | provider-specific). Null when not reported. Distinct from `status` (HTTP-aligned turn outcome); `finish_reason` describes how the model stopped, `status` describes how the turn resolved."
31
+ },
32
+ "model": {
33
+ "type": "string",
34
+ "minLength": 1,
35
+ "description": "Wire-reported model identifier. May differ from `agent.provider.model` for routing-relay providers (OpenRouter, etc.); the verification surface for served-vs-requested alignment."
36
+ },
28
37
  "packet": { "$ref": "https://schemas.plurnk.dev/v0/Packet.json" }
29
38
  }
30
39
  }
@@ -0,0 +1,19 @@
1
+ import type { ParsedPath, PlurnkStatement, Position } from "./types.ts";
2
+ import type { StatementContext } from "./generated/plurnkParser.ts";
3
+ declare module "xpath" {
4
+ function parse(expression: string): unknown;
5
+ }
6
+ export default class AstBuilder {
7
+ #private;
8
+ static build(ctx: StatementContext): PlurnkStatement;
9
+ /**
10
+ * Parse a path string into a ParsedPath, mirroring how the AST visitor
11
+ * decomposes path slots inside HEREDOC statements. Public for consumers
12
+ * (RPC layers, scheme handlers) that need to honor the grammar's
13
+ * authority-vs-opaque cleavage without round-tripping through a fake
14
+ * HEREDOC. Returns null when `raw` is empty. Throws PlurnkParseError
15
+ * when `raw` starts with `scheme://` but WHATWG URL rejects it.
16
+ */
17
+ static parsePath(raw: string, pos?: Position): ParsedPath | null;
18
+ }
19
+ //# sourceMappingURL=AstBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AstBuilder.d.ts","sourceRoot":"","sources":["../../src/AstBuilder.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EASR,UAAU,EAEV,eAAe,EACf,QAAQ,EAKX,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAYR,gBAAgB,EAEnB,MAAM,6BAA6B,CAAC;AAWrC,OAAO,QAAQ,OAAO,CAAC;IACnB,SAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;CACtD;AAQD,MAAM,CAAC,OAAO,OAAO,UAAU;;IAa3B,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,eAAe;IA6NpD;;;;;;;OAOG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,QAAiC,GAAG,UAAU,GAAG,IAAI;CA6H3F"}