@aitoroses/telar 0.0.0-stage → 0.1.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 (92) hide show
  1. package/README.md +453 -2
  2. package/dist/compile.d.ts +48 -0
  3. package/dist/compile.js +1238 -0
  4. package/dist/contract.d.ts +109 -0
  5. package/dist/contract.js +497 -0
  6. package/dist/evaluator.d.ts +23 -0
  7. package/dist/evaluator.js +40 -0
  8. package/dist/guide.d.ts +8 -0
  9. package/dist/guide.js +16 -0
  10. package/dist/install.d.ts +104 -0
  11. package/dist/install.js +402 -0
  12. package/dist/iso.d.ts +8 -0
  13. package/dist/iso.js +68 -0
  14. package/dist/node/build.d.ts +1 -0
  15. package/dist/node/build.js +34 -0
  16. package/dist/node/telar-module.d.ts +2 -0
  17. package/dist/node/telar-module.js +28 -0
  18. package/dist/observer.d.ts +47 -0
  19. package/dist/observer.js +53 -0
  20. package/dist/pieces.d.ts +230 -0
  21. package/dist/pieces.js +178 -0
  22. package/dist/powers.d.ts +46 -0
  23. package/dist/powers.js +126 -0
  24. package/dist/protocol.d.ts +212 -0
  25. package/dist/protocol.js +236 -0
  26. package/dist/query.d.ts +67 -0
  27. package/dist/query.js +102 -0
  28. package/dist/read.d.ts +37 -0
  29. package/dist/read.js +27 -0
  30. package/dist/runner.d.ts +112 -0
  31. package/dist/runner.js +134 -0
  32. package/dist/scenario/builder.d.ts +25 -0
  33. package/dist/scenario/builder.js +603 -0
  34. package/dist/scenario/templates.d.ts +35 -0
  35. package/dist/scenario/templates.js +64 -0
  36. package/dist/scenario/types.d.ts +441 -0
  37. package/dist/scenario/types.js +10 -0
  38. package/dist/scenario/validate.d.ts +7 -0
  39. package/dist/scenario/validate.js +19 -0
  40. package/dist/scenario.d.ts +4 -0
  41. package/dist/scenario.js +4 -0
  42. package/dist/schema.d.ts +219 -0
  43. package/dist/schema.js +221 -0
  44. package/dist/seating.d.ts +49 -0
  45. package/dist/seating.js +26 -0
  46. package/dist/send-hook.d.ts +46 -0
  47. package/dist/send-hook.js +123 -0
  48. package/dist/show.d.ts +34 -0
  49. package/dist/show.js +1 -0
  50. package/dist/source.d.ts +85 -0
  51. package/dist/source.js +104 -0
  52. package/dist/spec.d.ts +20 -0
  53. package/dist/spec.js +17 -0
  54. package/dist/standard-schema.d.ts +21 -0
  55. package/dist/standard-schema.js +1 -0
  56. package/dist/std/accuracy.d.ts +12 -0
  57. package/dist/std/accuracy.js +122 -0
  58. package/dist/std/ack.d.ts +14 -0
  59. package/dist/std/ack.js +43 -0
  60. package/dist/std/actions.d.ts +106 -0
  61. package/dist/std/actions.js +154 -0
  62. package/dist/std/brief.d.ts +36 -0
  63. package/dist/std/brief.js +78 -0
  64. package/dist/std/claude-code.d.ts +9 -0
  65. package/dist/std/claude-code.js +106 -0
  66. package/dist/std/compare.d.ts +29 -0
  67. package/dist/std/compare.js +36 -0
  68. package/dist/std/git-workspace.d.ts +44 -0
  69. package/dist/std/git-workspace.js +184 -0
  70. package/dist/std/judgment.d.ts +85 -0
  71. package/dist/std/judgment.js +462 -0
  72. package/dist/std/observe-command.d.ts +23 -0
  73. package/dist/std/observe-command.js +151 -0
  74. package/dist/std/observe-github-checks.d.ts +26 -0
  75. package/dist/std/observe-github-checks.js +299 -0
  76. package/dist/std/observe-http-status.d.ts +27 -0
  77. package/dist/std/observe-http-status.js +181 -0
  78. package/dist/std/plan.d.ts +7 -0
  79. package/dist/std/plan.js +28 -0
  80. package/dist/std/queries.d.ts +31 -0
  81. package/dist/std/queries.js +318 -0
  82. package/dist/std/reading.d.ts +17 -0
  83. package/dist/std/reading.js +88 -0
  84. package/dist/std/schedule.d.ts +19 -0
  85. package/dist/std/schedule.js +122 -0
  86. package/dist/std.d.ts +15 -0
  87. package/dist/std.js +15 -0
  88. package/dist/types.d.ts +366 -0
  89. package/dist/types.js +1 -0
  90. package/dist/values.d.ts +81 -0
  91. package/dist/values.js +129 -0
  92. package/package.json +65 -3
package/README.md CHANGED
@@ -1,3 +1,454 @@
1
- # Temporary Holding Version
1
+ # `telar/spec`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Typed who-does-what authoring library compiling directly to `telar.spec/1` JSON. Zero runtime dependencies, zero `node:*` imports (runs in QuickJS and Node), type-checked by `tsrs`.
4
+
5
+ The npm package is `@aitoroses/telar`. Install it under the name `telar`, at the version of your `telar` binary, so every `telar/*` import resolves:
6
+
7
+ ```sh
8
+ pnpm add -D telar@npm:@aitoroses/telar@<version>
9
+ ```
10
+
11
+ > Note for repositories using `oxlint` with `unicorn`: disable `"unicorn/no-thenable": "off"` so steps can write `then: [...]` without `[THEN]` shims (`then` is an array of effects, not a Promise).
12
+
13
+ ## One example per construct
14
+
15
+ ### 1. Type language (`t`) and named `contract`
16
+
17
+ ```ts
18
+ import { contract, t, type Infer } from "telar/spec";
19
+
20
+ const nonEmpty = t.string({ nonEmpty: true });
21
+ const optionId = t.string({ nonEmpty: true, brand: "OptionId", audience: "agent" });
22
+
23
+ const option = contract("brief-option", {
24
+ id: optionId,
25
+ label: t.string({ nonEmpty: true, maxLength: 40, audience: "person" }),
26
+ note: t.optional(nonEmpty),
27
+ });
28
+
29
+ // Passing a Contract inside another schema emits { kind: "ref", schema: "brief-option" }
30
+ // and registers "brief-option" in spec.schemas automatically.
31
+ const brief = contract(
32
+ "std-brief",
33
+ {
34
+ headline: t.string({ nonEmpty: true, maxLength: 80, audience: "person" }),
35
+ options: t.array(option, { nonEmpty: true }),
36
+ urgency: t.enum(["low", "normal", "blocking"]),
37
+ },
38
+ { validator: "telar.std/brief/2", description: "Structured brief" },
39
+ );
40
+
41
+ type Brief = Infer<typeof brief>;
42
+ ```
43
+
44
+ Tagged structs and unions (`t.tagged`, `t.union`, `t.unionOf`):
45
+
46
+ ```ts
47
+ const approveSpend = contract(
48
+ "approve-spend-op",
49
+ t.tagged("ApproveSpend", {
50
+ budgetRef: nonEmpty,
51
+ maxUsd: t.number({ exclusiveMin: 0 }),
52
+ }),
53
+ );
54
+
55
+ const removeContract = contract(
56
+ "remove-contract-op",
57
+ t.tagged("RemoveContract", { contractRef: nonEmpty }),
58
+ );
59
+
60
+ // Flattens tagged structs and sub-unions into one tagged union on _tag
61
+ const pendingOp = contract("pending-op", t.unionOf([approveSpend, removeContract]));
62
+
63
+ // Direct tagged union
64
+ const answerShape = contract(
65
+ "reply-shape",
66
+ t.union({
67
+ Reply: { text: nonEmpty },
68
+ Close: { reason: nonEmpty },
69
+ }),
70
+ );
71
+ ```
72
+
73
+ ### 2. Roles (`role`) and per-protocol view overrides (`roleView`)
74
+
75
+ ```ts
76
+ import { role, roleView } from "telar/spec";
77
+
78
+ const user = role("user", { view: "all" });
79
+ const lead = role("lead", { view: "lineage" });
80
+ const reviewer = role("reviewer", { view: "blind", seatLabels: { rung: ["cheap", "strong"] } });
81
+
82
+ // On a protocol:
83
+ // roleViews: [roleView(lead, "lineage", { includePredecessor: true })]
84
+ ```
85
+
86
+ ### 3. Classes (`defineClass`)
87
+
88
+ ```ts
89
+ import { defineClass } from "telar/spec";
90
+
91
+ const decideAsUser = defineClass("decide-as-user", {
92
+ authorized: [user],
93
+ delegatedWhenAway: [{ role: lead, for: user }],
94
+ });
95
+ const irreversible = defineClass("irreversible", {
96
+ authorized: [user],
97
+ admitsImpossible: true,
98
+ });
99
+ ```
100
+
101
+ ### 4. World effects (`check`, `defineAction`)
102
+
103
+ ```ts
104
+ import { check, defineAction } from "telar/spec";
105
+
106
+ const repoHead = contract("repo-head", { repo: nonEmpty, head: nonEmpty });
107
+ const empty = contract("empty", {});
108
+
109
+ const ciGreen = check("ci.green", { input: repoHead });
110
+ const ladderPolicy = check("clarity.policy", {
111
+ input: repoHead,
112
+ evaluator: "telar.std/ladder/1",
113
+ });
114
+
115
+ const publish = defineAction({
116
+ id: "releases/action/publish/1",
117
+ input: repoHead,
118
+ output: empty,
119
+ class: irreversible,
120
+ reversible: false,
121
+ run: () => ({}),
122
+ });
123
+ ```
124
+
125
+ An action is its step handle and its implementation: `run(input, powers)` returns the declared `output`, or throws `ActionError(code, message)`. List it in `defineInstallation({ actions })`, with any std action from `stdActions` (`telar/std`) a step calls. See [docs/reference/actions.md](../../docs/reference/actions.md).
126
+
127
+ ### 5. Case fields (`fields`, `engine`, `field`) and value refs (`fromAnswer`, `seat`, `cause`, `literal`)
128
+
129
+ ```ts
130
+ import { cause, engine, field, fields, fromAnswer, literal, seat } from "telar/spec";
131
+
132
+ const caseData = fields({
133
+ area: nonEmpty,
134
+ notes: t.array(nonEmpty),
135
+ previousCase: t.optional(nonEmpty),
136
+ pendingOp: engine(t.optional(pendingOp)),
137
+ decisions: engine(t.array(nonEmpty), { default: [] }),
138
+ maxReopens: engine.byField(t.int({ min: 1 }), {
139
+ field: "area",
140
+ values: { alpha: 1 },
141
+ default: 2,
142
+ }),
143
+ priorSummary: engine.fromPredecessor(nonEmpty, "summary"),
144
+ inputDigest: engine.digestOf(nonEmpty, "area"),
145
+ });
146
+
147
+ // Standalone field handle when not using fields():
148
+ const version = field<string>("version");
149
+
150
+ // Value refs: caseData.area ($field), fromAnswer("text") ($answer), seat.id, seat.role, cause.fact, literal(...)
151
+ // Plain JSON primitives and arrays auto-lift to $literal.
152
+ ```
153
+
154
+ ### 6. Guides (`guide`) and messages (`message`, `ack`, `redeliver`, `openOnMiss`, `msg`)
155
+
156
+ ```ts
157
+ import { ack, guide, message, msg, openOnMiss, protocolRef, redeliver } from "telar/spec";
158
+
159
+ const missedAck = protocolRef("missed-ack");
160
+ const askPayload = contract("ask-payload", { brief });
161
+
162
+ const askBrief = message("ask-brief", {
163
+ payload: askPayload,
164
+ template: (p) => guide`${p.brief}`,
165
+ ack: ack.read({
166
+ within: 4 * 3_600_000,
167
+ onMiss: [
168
+ redeliver(),
169
+ openOnMiss(missedAck, {
170
+ for: lead,
171
+ data: { message: msg.id, messageKind: msg.kind, toRole: msg.toRole },
172
+ }),
173
+ ],
174
+ }),
175
+ });
176
+ ```
177
+
178
+ ### 7. Bounds (`bound`)
179
+
180
+ ```ts
181
+ import { bound } from "telar/spec";
182
+
183
+ // Inline bound on a single step:
184
+ const inline = bound({ max: 2, onLimit: lead });
185
+
186
+ // Named shared bound across multiple steps (auto-registered on protocol.bounds):
187
+ const exchanges = bound("exchanges", {
188
+ max: 50,
189
+ byField: { field: caseData.area, values: { alpha: 2 } },
190
+ onLimit: lead,
191
+ });
192
+ ```
193
+
194
+ ### 8. Needs and effects
195
+
196
+ ```ts
197
+ import {
198
+ answer,
199
+ anyOf,
200
+ append,
201
+ authorize,
202
+ boundReached,
203
+ childrenEnded,
204
+ childrenEndedIn,
205
+ childrenIn,
206
+ emit,
207
+ openChild,
208
+ received,
209
+ set,
210
+ } from "telar/spec";
211
+
212
+ // Needs:
213
+ answer(lead, answerShape, ["Reply"]);
214
+ answer(reviewer, answerShape, {
215
+ variants: ["Reply"],
216
+ seatLabel: { key: "rung", values: ["cheap"] },
217
+ });
218
+ authorize(irreversible);
219
+ authorize.fromField(caseData.area, [decideAsUser, irreversible]);
220
+ ciGreen({ repo: caseData.area, head: fromAnswer("head") });
221
+ childrenEnded({ allowEmpty: true });
222
+ childrenIn(missedAck, "open", { allowEmpty: false });
223
+ childrenEndedIn(missedAck, "closed", {
224
+ where: { childField: "subject", parentField: caseData.area },
225
+ allowEmpty: false,
226
+ });
227
+ received(askBrief, { from: lead });
228
+ boundReached("reopen");
229
+ anyOf(answer(lead, answerShape, ["Reply"]), answer(user, answerShape, ["Close"]));
230
+
231
+ // Effects:
232
+ set(caseData.pendingOp, fromAnswer("operation"));
233
+ append(caseData.notes, fromAnswer("text"));
234
+ openChild(missedAck, { for: lead, seatScopeFrom: "area", data: { area: caseData.area } });
235
+ emit(askBrief, { to: user, payload: { brief: caseData.area } });
236
+ publish({ repo: caseData.area, head: fromAnswer("head") });
237
+ ```
238
+
239
+ ### 9. Steps, protocols, installation, and compilation
240
+
241
+ ```ts
242
+ import { compile, installation, protocol, step } from "telar/spec";
243
+
244
+ const work = protocol("work", {
245
+ states: ["open", "done"],
246
+ start: "open",
247
+ final: ["done"],
248
+ data: caseData,
249
+ steps: [
250
+ step("finish", {
251
+ from: "open",
252
+ to: "done",
253
+ needs: [answer(lead, answerShape, ["Close"])],
254
+ }),
255
+ ],
256
+ });
257
+
258
+ const spec = compile(
259
+ installation({
260
+ name: "demo",
261
+ governedBy: irreversible,
262
+ roles: [user, lead, reviewer],
263
+ classes: [decideAsUser, irreversible],
264
+ root: work,
265
+ protocols: [work],
266
+ roster: { seating: {}, caps: {}, grants: {} },
267
+ }),
268
+ );
269
+ ```
270
+
271
+ ### 10. Installation points (`defineInstallation`)
272
+
273
+ `defineInstallation` builds the module that `telar.config.ts` imports. Export the installation under its own name, quoted when the name has a hyphen: `export { desk as "acme-desk" };`. telar calls it at four points, each with `{ config }`, where `config` is the configuration after the installation's `config` function:
274
+
275
+ | Point | Field | Called by | Answers |
276
+ | --------------- | ------- | ---------------------------- | -------------------------------------------------------------------------------------- |
277
+ | `install:admit` | `admit` | `telar check`, `telar test` | `AdmissionProblem[]` (`{ path, message, fix }`); any problem refuses the configuration |
278
+ | `install:spec` | `spec` | `telar check`, `telar adopt` | the compiled `telar.spec/1` for this configuration |
279
+ | `install:pack` | `pack` | `telar check` | `telar.scenario/1[]` run on a fake world after admission |
280
+ | `install:test` | `test` | `telar test` | `InstallationTest[]`: `{ scenario, proofs? }`, each proof `{ query, args?, rows }` |
281
+
282
+ `pack` and `test` both hold scenarios. `install:pack` runs in `telar check` against the team's own configuration, so it proves that this configuration works. `install:test` holds the author's scenarios and trail proofs for `telar test`: each proof runs a declared query with its `args` on the scenario's trail, and its decoded rows must equal `rows`. Other names in `fills` answer the scenario extension points the spec declares.
283
+
284
+ A computed check that the installation decides names an evaluator declared with `defineEvaluator({ id: "<installation>/evaluator/<name>/<v>", evaluate })` and listed in `defineInstallation({ evaluators })`. A raw `check:` fill is refused. See [docs/reference/evaluators.md](../../docs/reference/evaluators.md).
285
+
286
+ A send hook (`hooks.send`) fill reads its args with `decodeSendHookArgs` and returns a `SendVerdict` (`{ allow: true }` or `{ allow: false, reason }`). Both decoders throw `PluginCallError` naming the bad field, so `call` answers with an error frame:
287
+
288
+ ```ts
289
+ fills: {
290
+ "hook:acme.send": (args) => {
291
+ const input = decodeSendHookArgs(args);
292
+ return input.toRole === "lead" ? { allow: true } : { allow: false, reason: "leads only" };
293
+ },
294
+ },
295
+ ```
296
+
297
+ ### 11. Building the installation module (`telar/build`, `telar-module`)
298
+
299
+ telar loads one ES module that imports only `telar/spec`, `telar/std` and `telar/scenario`. `telar-module <entry> [--out <file>]` bundles your entry with rolldown (an optional peer dependency: install `rolldown` beside `telar` to use it) into that module, keeps the three SDK specifiers external, and drops code your exports never reach (Node imports included). `buildModule(entry)` from `telar/build` does the same and returns the module text. Then `telar build <module.mjs> <types.d.mts>` refuses any other import and packs the module and your declarations into `<name>.telar.json`:
300
+
301
+ ```sh
302
+ telar-module installation.ts --out installation.mjs
303
+ telar build installation.mjs installation.d.mts --out dist
304
+ ```
305
+
306
+ ## Porting from guild's old spec compiler
307
+
308
+ | Old guild construct | Replacement in `telar/spec` |
309
+ | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
310
+ | `Schema.*` + `lowerEffectSchema` + `refs` map | `t.*` + `contract(name, ...)` (auto-collected refs) |
311
+ | `ProtocolFieldTable` + `compileProtocolFieldTable` | `fields({ callerField: ..., managed: engine(...) })` |
312
+ | `B.stepDecl` / `stp(...)` | `step(name, { from, to, needs, then, bound })` |
313
+ | `B.protocolDecl` | `protocol(name, { states, start, final, data, steps })` |
314
+ | `B.answerNeed` | `answer(roleOrRoles, contract, variantsOrOpts)` |
315
+ | `B.authNeed` / `B.authFromFieldNeed` | `authorize(cls)` / `authorize.fromField(fieldRef, classes)` |
316
+ | `B.childrenEndedNeed` / `B.childrenEndedInNeed` | `childrenEnded(...)` / `childrenEndedIn(proto, state, ...)` |
317
+ | `setAns` / `setVal` / `record-data` | `set(fieldRef, value)` / `append(fieldRef, item)` |
318
+ | `openChild(...)` / `open-child` | `openChild(proto, { for, seatScopeFrom?, data })` |
319
+ | `emit-message` | `emit(messageKind, { to, payload })` |
320
+ | `B.boundRef` + `bounds: { ... }` | `const b = bound("name", ...)` passed to `bound: b` |
321
+ | `defineMessageKind` + `B.messageDecl` + `B.lowerAckDecl` | `message(name, { payload, template: (p) => guide\`...\`, ack })` |
322
+ | `defineSpec` + `compileSpec` + `validateSpecAgainstPublishedSchema` | `compile(installation(...))` + `telar` admission |
323
+ | `judgment.ts` + `question.ts` + `policy.ts` + `override.ts` | `telar/std`: `judgmentProtocol`, `choiceKind`, `customKind`, `ladder`, `judgmentOverrideProtocol`, `withRungLabels` |
324
+ | `brief.ts` + `refs.ts` | `telar/std`: `stdBrief`, `typedRef`, `briefOption`, `briefRecommendation`, `personText`, `engineeringText` |
325
+ | `ack.ts` + `missed-ack.ts` | `telar/std`: `HOUR_MS`, `defaultMissPolicy`, `missedAckAnswer`, `missedAckProtocol` |
326
+ | `compare.ts` | `telar/std`: `compareNumber`, `compareBool`, `compareString`, `stdCompareChecks` |
327
+ | `reading.ts` | `telar/std`: `verdictContract`, `readingProtocol` |
328
+
329
+ ## `telar/std` (user-land std protocols and shapes)
330
+
331
+ Built strictly on `telar/spec`'s public API (ADR 0012):
332
+
333
+ ```ts
334
+ import {
335
+ HOUR_MS,
336
+ choiceKind,
337
+ defaultMissPolicy,
338
+ judgmentOverrideProtocol,
339
+ judgmentProtocol,
340
+ ladder,
341
+ missedAckProtocol,
342
+ planProtocol,
343
+ readingProtocol,
344
+ stdBrief,
345
+ verdictContract,
346
+ withRungLabels,
347
+ } from "telar/std";
348
+ ```
349
+
350
+ - **Judgment + override:** `const policy = ladder([{ role: reviewer, label: "cheap", threshold: 0.9 }], { role: architect, label: "strong" }); const j = judgmentProtocol({ question: "clarity", input: stdBrief, kind: choiceKind({ options: ["yes", "missing"] }), ...policy }); const ov = judgmentOverrideProtocol({ question: "clarity", outcomes: j.outcomes, rungs: policy.rungs });`
351
+ - **Brief + ack:** `stdBrief`, `typedRef`, `defaultMissPolicy(missedAck, chiefOfStaff)`, `missedAckProtocol({ responsible: chiefOfStaff })`.
352
+ - **Blind reading + verdict:** `const v = verdictContract("shape-reading", ["Ready", "Reopen"], { summary: nonEmpty }); readingProtocol({ name: "reading", data, finalStates: ["ready", "reopen"], readers: [...] })`.
353
+ - **Plan:** `planProtocol({ name: "plan", planner: lead, itemProtocol: ticket })`.
354
+
355
+ ## `telar/scenario` (executable scenarios on `telar/spec`, ADR 0016)
356
+
357
+ One typed builder compiling to `telar.scenario/1` JSON (zero runtime deps, zero `node:*` imports). Accepts `telar/spec` handles (`Installation`, `Protocol`, `Role`, `MessageKind`, `Check`, `Contract`) or raw wire strings, checks symbolic `$alias` declarations and references at compile time (`tsrs`) and at `.build()`, and runs with unconditional trail replay through the `telar` binary.
358
+
359
+ ### One example per construct
360
+
361
+ ```ts
362
+ import {
363
+ absent,
364
+ bindCase,
365
+ bindMessage,
366
+ bindSeatRef,
367
+ checkGateHappyPath,
368
+ contains,
369
+ refusalPreservesState,
370
+ scenario,
371
+ stepById,
372
+ stepIdOf,
373
+ } from "telar/scenario";
374
+
375
+ const sc = scenario({
376
+ id: "demo/release-flow",
377
+ title: "typed scenario with inputs, bindings, expected trail, and scoped sub-flows",
378
+ stories: ["story-1"],
379
+ spec: inst, // Installation, compiled TelarSpecV1, or relative path string
380
+ world: { clockStart: "2026-01-01T00:00:00Z" },
381
+ })
382
+ .openUnbound(
383
+ { protocol: work, data: { title: 123 } },
384
+ { expect: { result: { ok: false, code: "INVALID_CASE_DATA" } } },
385
+ )
386
+ .open(
387
+ "$c1",
388
+ { protocol: work, data: { title: "ship" } },
389
+ {
390
+ id: "open-work",
391
+ note: "root case opens cleanly",
392
+ expect: {
393
+ states: { $c1: "open" },
394
+ phases: { $c1: "open" },
395
+ data: { $c1: { title: contains("shi"), error: absent } },
396
+ },
397
+ },
398
+ )
399
+ .bindSeat("$lead", { binding: "case", role: lead, case: "$c1" })
400
+ .roleAvailability({ role: user, available: false, reason: "offline" })
401
+ .answer(
402
+ { case: "$c1", seat: "$lead", payload: { _tag: "Ask" } },
403
+ {
404
+ bind: {
405
+ $child: bindCase(clarity, { parent: "$c1", index: -1 }),
406
+ $m1: bindMessage(askBrief, { case: "$c1" }),
407
+ },
408
+ expect: {
409
+ trail: {
410
+ scope: "step",
411
+ contains: [{ kind: "message-recorded", case: "$c1", message: "$m1" }],
412
+ },
413
+ },
414
+ },
415
+ )
416
+ .read({ seat: "$lead", message: "$m1" })
417
+ .clock({ advanceMs: 5000 })
418
+ .worldEvent({ kind: "check", check: ciGreen, args: { title: "ship" }, ok: true })
419
+ .withScope("review", { cases: { $c: "$child" }, seats: {} }, (sub) =>
420
+ sub.bindSeat("$rev", {
421
+ binding: "case",
422
+ role: reviewer,
423
+ case: "$c",
424
+ labels: { rung: "cheap" },
425
+ }),
426
+ )
427
+ .closeSeat("$lead")
428
+ .cancel({ case: "$c1", reason: "done" })
429
+ .build();
430
+ ```
431
+
432
+ - **Templates:** `checkGateHappyPath(...)` and `refusalPreservesState(...)` produce ready-to-run `TelarScenarioV1` objects.
433
+ - **Step lookup:** `stepIdOf(step)` and `stepById(sc, "open-work")` inspect `[id:...]` annotations; `withScope("review", ...)` prefixes local aliases (`$review_rev`) and step IDs (`review/...`).
434
+ - **Additional inputs:** `.message(...)`, `.adopt({ spec: nextSpec, migration? })`, and `.extension({ kind: "ns.name", ... })`.
435
+ - **Run on the real `telar` binary:**
436
+ - `telar test` (validates and runs the scenarios your installation returns from `test`, each with its replay)
437
+ - `telar explore --depth <n>` (explores every world those scenarios reach)
438
+ - `telar replay` (replays the installation's own trail)
439
+
440
+ ### Porting from guild's `modules/scenarios/lib`
441
+
442
+ | Old guild construct (`modules/scenarios/lib`) | Replacement in `telar/scenario` |
443
+ | --------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
444
+ | `scenario(...)` / `storyScenario({ stories, origin })` | `scenario({ id, title, spec, stories?, config?, world? })` (one entry point) |
445
+ | `scenarioId("x")` / `storyId("story-1")` / `nonNegativeInt(n)` | plain `"x"`, `"story-1"`, `n` (validated by `telar check`) |
446
+ | `.open("$c1", input, expect, meta)` | `.open("$c1", input, { id?, note?, bind?, expect? })` (one uniform options shape) |
447
+ | `.clock({ advanceMs }, expect, meta)` / `.clock(..., { bind })` | `.clock({ advanceMs }, { id?, note?, bind?, expect? })` |
448
+ | `bindChild("clarity", "reviewer")` / raw bind objects | `bindCase(clarity, { parent: "$c1", forRole: reviewer, index: -1 })` |
449
+ | `{ kind: "message", messageKind: "ask", case: "$c1" }` | `bindMessage(ask, { case: "$c1" })` |
450
+ | `{ kind: "seat", role: "lead", scope: "core" }` | `bindSeatRef(lead, { scope: "core" })` |
451
+ | `{ $absent: true }` / `{ $contains: "sub" }` | `absent` / `contains("sub")` |
452
+ | `validateScenarioAgainstPublishedSchema` + alias validator | Compile-time alias/handle types + `telar check` / `telar test` in Rust (single validator) |
453
+ | `checkGateHappyPath` / `refusalPreservesState` (`templates.ts`) | `checkGateHappyPath` / `refusalPreservesState` from `telar/scenario` |
454
+ | `stepIdOf` / `stepById` / `.withScope(...)` | `stepIdOf` / `stepById` / `.withScope(...)` from `telar/scenario` |
@@ -0,0 +1,48 @@
1
+ import type { AnyAction, AnyAuthClass, AnyCheck, AnyMessageKind, AnyRole } from "./pieces.js";
2
+ import type { AnyProtocol, BindingFieldOf } from "./protocol.js";
3
+ import type { GranteeGrantsDecl, HooksDecl, Rec, RoleBindingDecl, SeatBindingDecl, TelarSpecV1 } from "./types.js";
4
+ export declare class SpecCompileError extends Error {
5
+ readonly name: string;
6
+ readonly path: string;
7
+ constructor(path: string, message: string);
8
+ }
9
+ export interface RosterInput<Role extends string = string, Field extends string = string, Protocol extends string = string> {
10
+ readonly seating: Rec<SeatBindingDecl>;
11
+ readonly bindings?: {
12
+ readonly [R in Role]?: RoleBindingDecl<Field, Protocol>;
13
+ } | undefined;
14
+ readonly caps: Rec<number>;
15
+ readonly spendCapUsd?: number | undefined;
16
+ readonly grants?: Rec<GranteeGrantsDecl> | undefined;
17
+ }
18
+ export interface InstallationInput<R extends AnyRole = AnyRole, P extends AnyProtocol = AnyProtocol> {
19
+ readonly name: string;
20
+ readonly profile?: "m1" | undefined;
21
+ readonly governedBy: AnyAuthClass;
22
+ readonly roles: readonly R[];
23
+ readonly classes: readonly AnyAuthClass[];
24
+ readonly root: AnyProtocol;
25
+ readonly protocols: readonly P[];
26
+ readonly checks?: readonly AnyCheck[] | undefined;
27
+ readonly actions?: readonly AnyAction[] | undefined;
28
+ readonly messages?: readonly AnyMessageKind[] | undefined;
29
+ readonly roster: NoInfer<RosterInput<R["name"], BindingFieldOf<P>, P["name"]>>;
30
+ readonly hooks?: HooksDecl | undefined;
31
+ }
32
+ export interface Installation {
33
+ readonly kind: "installation";
34
+ readonly name: string;
35
+ readonly profile?: "m1";
36
+ readonly governedBy: AnyAuthClass;
37
+ readonly roles: readonly AnyRole[];
38
+ readonly classes: readonly AnyAuthClass[];
39
+ readonly root: AnyProtocol;
40
+ readonly protocols: readonly AnyProtocol[];
41
+ readonly checks: readonly AnyCheck[];
42
+ readonly actions: readonly AnyAction[];
43
+ readonly messages: readonly AnyMessageKind[];
44
+ readonly roster: RosterInput;
45
+ readonly hooks?: HooksDecl;
46
+ }
47
+ export declare function installation<R extends AnyRole, P extends AnyProtocol>(def: InstallationInput<R, P>): Installation;
48
+ export declare function compile(inst: Installation): TelarSpecV1;