@crewhaus/ir 0.3.2 → 0.4.2

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.
package/dist/index.js CHANGED
@@ -1,3 +1,8 @@
1
1
  // Generated-bundle README renderer (item 42) — pure functions over the IR,
2
2
  // shared by every target emitter. See ./readme.ts for the module docs.
3
3
  export { GENERATED_README_MARKER, collectSecretRefs, renderBundleReadme, } from "./readme";
4
+ // Loop contract 0.4 (Batch B, G42) — the canonical agent-loop projection
5
+ // (`projectLoop(ir)`), whose LoopProjection shape is the wire contract
6
+ // shared with the studio's /builder page and the compiler-worker's
7
+ // `POST /loop` endpoint. See ./loop.ts for the module docs.
8
+ export { CANVAS_TARGETS, NO_BUDGET_WARNING, PERCEIVE_TOOL_RE, RING_TARGETS, SEGMENT_ORDER, projectLoop, } from "./loop";
package/dist/loop.d.ts ADDED
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Loop contract 0.4 (Batch B, G42) — `projectLoop(ir)`: project a lowered
3
+ * {@link IrNode} into its canonical AGENT-LOOP phase graph.
4
+ *
5
+ * The {@link LoopProjection} shape below is the WIRE CONTRACT shared with
6
+ * the studio's client-side projection (`studio-pwa/src/lib/loop-model.ts`):
7
+ * plain JSON-serializable data — no functions, no classes — rendered by the
8
+ * /builder page verbatim. The compiler-worker's `POST /loop` endpoint
9
+ * returns exactly this object for `projectLoop(lower(parseSpec(yaml)))`.
10
+ *
11
+ * Two projection kinds:
12
+ * - `"ring"` — single-agent shapes (cli / channel / managed): the
13
+ * seven-component loop as ring segments (perceive / reason / act /
14
+ * evaluate / update) plus the Stop and Safety boundary panels.
15
+ * - `"canvas"` — step/node/role shapes (workflow / graph / crew /
16
+ * pipeline / research / batch): steps/nodes/roles as canvas nodes,
17
+ * edges/handoffs as arrows, HITL and judge gates surfaced, each node
18
+ * carrying its own mini seven-segment summary.
19
+ *
20
+ * The remaining shapes (voice / browser / eval / onchain / onchain-game)
21
+ * fall back to the generic ring with an honest warning — "say so rather
22
+ * than shrink".
23
+ *
24
+ * MAPPING SOURCE OF TRUTH: the IR's RESOLVED fields, not the raw spec.
25
+ * This differs from the studio's spec-object projection in two deliberate
26
+ * ways:
27
+ * - default-on config that the runtime WILL wire lights its segment
28
+ * (e.g. cli continuity is default-on in 0.3+, so `update` is active
29
+ * unless the spec opted out) — the projection reports what the loop
30
+ * actually does;
31
+ * - per-step/node models are resolved at lower time, so node minis always
32
+ * show the resolved model (the spec-side "inherits the spec-level
33
+ * model" state is not reconstructible from IR).
34
+ * Stop stays defaults-honest: with neither `budget` nor `limits` in the IR
35
+ * the segment is inactive and {@link NO_BUDGET_WARNING} is emitted.
36
+ *
37
+ * `keys` entries remain SPEC-dotted paths (`"agent.model_pool"`,
38
+ * `"channels.slack"`, `"tools[webFetch]"`) so the operator can jump from a
39
+ * segment to the YAML that (would) configure it.
40
+ *
41
+ * Pure functions of the IR — no I/O, no imports beyond the IR types.
42
+ */
43
+ import type { IrNode } from "./index";
44
+ /** The seven loop components, in canonical render order. */
45
+ export type LoopSegmentId = "perceive" | "reason" | "act" | "evaluate" | "update" | "stop" | "safety";
46
+ /** Canonical segment order — every ring and every node mini uses exactly this. */
47
+ export declare const SEGMENT_ORDER: readonly LoopSegmentId[];
48
+ /**
49
+ * One loop component. `active` iff the RESOLVED IR configures it; `keys`
50
+ * are the dotted spec paths that lit it (e.g. "agent.model_pool",
51
+ * "tools[webFetch]", "channels.slack"); `summary` is a one-line,
52
+ * operator-facing description of what is (or isn't) configured.
53
+ */
54
+ export type LoopSegment = {
55
+ readonly id: LoopSegmentId;
56
+ readonly active: boolean;
57
+ readonly keys: readonly string[];
58
+ readonly summary: string;
59
+ };
60
+ /** The single-agent loop ring: always all seven segments, in SEGMENT_ORDER. */
61
+ export type LoopRing = {
62
+ readonly segments: readonly LoopSegment[];
63
+ };
64
+ /**
65
+ * What a canvas node represents on its shape. EXACTLY the studio's
66
+ * `LoopNodeKind` union (studio-pwa `src/lib/loop-model.ts`) — the studio
67
+ * renderer is the wire consumer, so factory must not emit kinds outside it.
68
+ * Research branches and the batch queue render as `"node"`, mirroring the
69
+ * studio's own client-side projection of those shapes.
70
+ */
71
+ export type LoopNodeKind = "step" | "node" | "role" | "doc";
72
+ /**
73
+ * One canvas node (a workflow step, graph node, crew role, research branch,
74
+ * batch queue, or a doc/report artifact). `hitl` marks a human-approval
75
+ * badge; `mini` is the node's own seven-segment summary.
76
+ */
77
+ export type LoopNode = {
78
+ readonly id: string;
79
+ readonly label: string;
80
+ readonly kind: LoopNodeKind;
81
+ readonly hitl?: boolean;
82
+ readonly mini: readonly LoopSegment[];
83
+ };
84
+ /** One canvas arrow. `conditional` marks a guarded edge (a graph `when`, a
85
+ * judge gate's pass/retry, a routing rule). */
86
+ export type LoopEdge = {
87
+ readonly from: string;
88
+ readonly to: string;
89
+ readonly label?: string;
90
+ readonly conditional?: boolean;
91
+ };
92
+ export type LoopCanvas = {
93
+ readonly nodes: readonly LoopNode[];
94
+ readonly edges: readonly LoopEdge[];
95
+ };
96
+ /**
97
+ * The full projection. Exactly one of `ring` / `canvas` is set, matching
98
+ * `kind`. `target` is the IR's target. `warnings` carry defaults-only
99
+ * boundaries (see {@link NO_BUDGET_WARNING}), family hints for fallback
100
+ * targets, and structural notes (crew routing, dangling graph edges,
101
+ * parallel barrier groups).
102
+ */
103
+ export type LoopProjection = {
104
+ readonly kind: "ring" | "canvas";
105
+ readonly target: string;
106
+ readonly ring?: LoopRing;
107
+ readonly canvas?: LoopCanvas;
108
+ readonly warnings: readonly string[];
109
+ };
110
+ /** Single-agent shapes rendered as the seven-component ring. */
111
+ export declare const RING_TARGETS: readonly string[];
112
+ /** Step/node/role shapes rendered as a node canvas. */
113
+ export declare const CANVAS_TARGETS: readonly string[];
114
+ /**
115
+ * The exact defaults-only Stop warning (guardrails-first affordance): with
116
+ * neither `budget:` nor `limits:` the loop's only boundary is the runtime's
117
+ * hardcoded tool-iteration cap. Shared verbatim with the studio.
118
+ */
119
+ export declare const NO_BUDGET_WARNING = "no budget: \u2014 stops only at the 500-iteration default";
120
+ /**
121
+ * Tool names that count as PERCEPTION (bringing outside state into the
122
+ * loop) rather than plain action. Everything in `tools` still counts toward
123
+ * the Act segment; matching names ALSO light Perceive.
124
+ */
125
+ export declare const PERCEIVE_TOOL_RE: RegExp;
126
+ /**
127
+ * Project a lowered IR into its canonical loop view. Total over the IrNode
128
+ * union and never throws: every variant maps to a ring or canvas, and the
129
+ * shapes without a dedicated projection fall back to the generic ring with
130
+ * an honest warning.
131
+ */
132
+ export declare function projectLoop(ir: IrNode): LoopProjection;