@principal-ai/subsystems-core 0.44.0 → 0.44.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.
- package/dist/agent-sessions/fixture.d.ts +80 -0
- package/dist/agent-sessions/fixture.d.ts.map +1 -0
- package/dist/agent-sessions/fixture.js +130 -0
- package/dist/agent-sessions/fixture.js.map +1 -0
- package/dist/agent-sessions/index.d.ts +3 -0
- package/dist/agent-sessions/index.d.ts.map +1 -0
- package/dist/agent-sessions/index.js +6 -0
- package/dist/agent-sessions/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +55 -0
- package/dist/node.js.map +1 -0
- package/dist/opencode/OpenCodeEventStore.d.ts +25 -0
- package/dist/opencode/OpenCodeEventStore.d.ts.map +1 -0
- package/dist/opencode/OpenCodeEventStore.js +182 -0
- package/dist/opencode/OpenCodeEventStore.js.map +1 -0
- package/dist/opencode/agent-sessions.d.ts +46 -0
- package/dist/opencode/agent-sessions.d.ts.map +1 -0
- package/dist/opencode/agent-sessions.js +302 -0
- package/dist/opencode/agent-sessions.js.map +1 -0
- package/dist/opencode/index.d.ts +6 -0
- package/dist/opencode/index.d.ts.map +1 -0
- package/dist/opencode/index.js +15 -0
- package/dist/opencode/index.js.map +1 -0
- package/dist/opencode/node-path-adapter.d.ts +25 -0
- package/dist/opencode/node-path-adapter.d.ts.map +1 -0
- package/dist/opencode/node-path-adapter.js +188 -0
- package/dist/opencode/node-path-adapter.js.map +1 -0
- package/dist/opencode/pipeline.d.ts +42 -0
- package/dist/opencode/pipeline.d.ts.map +1 -0
- package/dist/opencode/pipeline.js +90 -0
- package/dist/opencode/pipeline.js.map +1 -0
- package/dist/opencode/types.d.ts +39 -0
- package/dist/opencode/types.d.ts.map +1 -0
- package/dist/opencode/types.js +3 -0
- package/dist/opencode/types.js.map +1 -0
- package/dist/storage/topic-types.d.ts +203 -0
- package/dist/storage/topic-types.d.ts.map +1 -0
- package/dist/storage/topic-types.js +60 -0
- package/dist/storage/topic-types.js.map +1 -0
- package/dist/storage/topicStore.d.ts +131 -0
- package/dist/storage/topicStore.d.ts.map +1 -0
- package/dist/storage/topicStore.js +341 -0
- package/dist/storage/topicStore.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/subsystem-model.d.ts +388 -0
- package/dist/types/subsystem-model.d.ts.map +1 -0
- package/dist/types/subsystem-model.js +87 -0
- package/dist/types/subsystem-model.js.map +1 -0
- package/dist/validation.d.ts +24 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +112 -0
- package/dist/validation.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subsystem Model Types
|
|
3
|
+
*
|
|
4
|
+
* Two layers — do not conflate them:
|
|
5
|
+
*
|
|
6
|
+
* 1. **Portable document** (`SubsystemModelDocument`) — the shareable standard.
|
|
7
|
+
* Schema: `schemas/subsystem-model.schema.json`
|
|
8
|
+
* (`https://principal-ai.dev/schemas/subsystem-model.schema.json`).
|
|
9
|
+
*
|
|
10
|
+
* 2. **Hydrated envelope** (`SubsystemModelHydrated`) — portable document plus
|
|
11
|
+
* host/machine binding (local roots, provenance, store ids, verification).
|
|
12
|
+
* Used by viewers and stores; not part of the portable standard.
|
|
13
|
+
*
|
|
14
|
+
* Ontology: construct = what a node is, framework + stereotype = which
|
|
15
|
+
* framework pattern it plays, role = where it sits, process = where it runs,
|
|
16
|
+
* module = which source file/module the export belongs to,
|
|
17
|
+
* proposed = not yet in source (design / migration placeholder).
|
|
18
|
+
* Package (repo) frames are derived from component `purl` when a graph spans
|
|
19
|
+
* multiple repos — there is no separate `package` field.
|
|
20
|
+
* `symbol` is the code identity; `name` is the display label.
|
|
21
|
+
*/
|
|
22
|
+
/** What the node IS as a declaration. `module` is not an authored construct —
|
|
23
|
+
* a module is its own subsystem. `custom_entity` is an authored actor
|
|
24
|
+
* (Person / agent / queue), not code. */
|
|
25
|
+
export type SubsystemConstruct = 'class' | 'function' | 'method' | 'interface' | 'type_alias' | 'enum' | 'store' | 'external' | 'custom_entity';
|
|
26
|
+
/** Where the node sits in the topology, orthogonal to construct. */
|
|
27
|
+
export type SubsystemComponentRole = 'entry' | 'service';
|
|
28
|
+
/**
|
|
29
|
+
* Actor kind for `construct: custom_entity` (open string).
|
|
30
|
+
* Examples: `Person`, `agent`, `queue`, `slack-channel`.
|
|
31
|
+
* Only meaningful on custom entities.
|
|
32
|
+
*/
|
|
33
|
+
export type SubsystemEntityKind = string;
|
|
34
|
+
/**
|
|
35
|
+
* Framework that owns a stereotype vocabulary (open string).
|
|
36
|
+
* Examples: `react`, `vue`, `nestjs`, `django`, `spring`.
|
|
37
|
+
* Empty when the node is language-only / framework-agnostic.
|
|
38
|
+
*/
|
|
39
|
+
export type SubsystemFramework = string;
|
|
40
|
+
/**
|
|
41
|
+
* Framework-level pattern stamped on a language construct (open string).
|
|
42
|
+
* Examples: `component`, `hook`, `middleware`, `controller`, `guard`.
|
|
43
|
+
* Empty when no framework pattern applies. Pair with `framework` when set.
|
|
44
|
+
*/
|
|
45
|
+
export type SubsystemStereotype = string;
|
|
46
|
+
/**
|
|
47
|
+
* Trail step mechanism — runtime seams with a `file:line` site.
|
|
48
|
+
* Belongs on trail steps; graph edges for these are derived.
|
|
49
|
+
*/
|
|
50
|
+
export type SubsystemTrailMechanism = 'calls' | 'uses' | 'feeds' | 'produces' | 'writes' | 'reads' | 'watches' | 'registers-into';
|
|
51
|
+
/**
|
|
52
|
+
* Edge mechanism used by derived display edges / styling. Display edges are
|
|
53
|
+
* derived from trail steps, so this is the trail mechanism.
|
|
54
|
+
*/
|
|
55
|
+
export type SubsystemEdgeMechanism = SubsystemTrailMechanism;
|
|
56
|
+
export type SubsystemDeclarationProvenance = 'verified' | 'authored';
|
|
57
|
+
export type SubsystemDeclTokenKind = 'keyword' | 'name' | 'member' | 'type' | 'punctuation' | 'string' | 'newline';
|
|
58
|
+
export interface SubsystemDeclToken {
|
|
59
|
+
text: string;
|
|
60
|
+
kind: SubsystemDeclTokenKind;
|
|
61
|
+
/** Optional foreground when pre-tokenized for a theme. */
|
|
62
|
+
color?: string;
|
|
63
|
+
}
|
|
64
|
+
/** Anchored declaration location (usually from verify tooling). */
|
|
65
|
+
export interface SubsystemDeclarationRef {
|
|
66
|
+
file: string;
|
|
67
|
+
startLine: number;
|
|
68
|
+
lineHash: string;
|
|
69
|
+
graphifyNodeId?: string;
|
|
70
|
+
capturedAt: string;
|
|
71
|
+
}
|
|
72
|
+
export interface SubsystemParamInfo {
|
|
73
|
+
name?: string;
|
|
74
|
+
type: string;
|
|
75
|
+
ref?: SubsystemReferenceInfo;
|
|
76
|
+
}
|
|
77
|
+
export interface SubsystemPropertyInfo {
|
|
78
|
+
name: string;
|
|
79
|
+
type?: string;
|
|
80
|
+
typeRef?: SubsystemReferenceInfo;
|
|
81
|
+
nodeId?: string;
|
|
82
|
+
}
|
|
83
|
+
export interface SubsystemMethodInfo {
|
|
84
|
+
nodeId: string;
|
|
85
|
+
name: string;
|
|
86
|
+
parameters?: SubsystemParamInfo[];
|
|
87
|
+
returnType?: string;
|
|
88
|
+
returnTypeRef?: SubsystemReferenceInfo;
|
|
89
|
+
}
|
|
90
|
+
export interface SubsystemCallInfo {
|
|
91
|
+
nodeId: string;
|
|
92
|
+
name: string;
|
|
93
|
+
source_location?: string;
|
|
94
|
+
}
|
|
95
|
+
export interface SubsystemReferenceInfo {
|
|
96
|
+
nodeId: string;
|
|
97
|
+
name: string;
|
|
98
|
+
context?: string;
|
|
99
|
+
source_location?: string;
|
|
100
|
+
}
|
|
101
|
+
export interface SubsystemClassDeclaration {
|
|
102
|
+
kind: 'class';
|
|
103
|
+
methods: SubsystemMethodInfo[];
|
|
104
|
+
properties: SubsystemPropertyInfo[];
|
|
105
|
+
extends: string[];
|
|
106
|
+
implements: string[];
|
|
107
|
+
instantiations: SubsystemCallInfo[];
|
|
108
|
+
references: SubsystemReferenceInfo[];
|
|
109
|
+
}
|
|
110
|
+
export interface SubsystemFunctionDeclaration {
|
|
111
|
+
kind: 'function';
|
|
112
|
+
parameters: SubsystemParamInfo[];
|
|
113
|
+
returnType?: string;
|
|
114
|
+
returnTypeRef?: SubsystemReferenceInfo;
|
|
115
|
+
callers: SubsystemCallInfo[];
|
|
116
|
+
callees: SubsystemCallInfo[];
|
|
117
|
+
}
|
|
118
|
+
export interface SubsystemMethodDeclaration {
|
|
119
|
+
kind: 'method';
|
|
120
|
+
hostClass: string;
|
|
121
|
+
parameters?: SubsystemParamInfo[];
|
|
122
|
+
returnType?: string;
|
|
123
|
+
}
|
|
124
|
+
/** One generic type parameter, e.g. `T` or `K extends keyof StudioMessages`. */
|
|
125
|
+
export interface SubsystemTypeParamInfo {
|
|
126
|
+
name: string;
|
|
127
|
+
/** Constraint written after `extends` (or language equivalent). */
|
|
128
|
+
constraint?: string;
|
|
129
|
+
}
|
|
130
|
+
/** A callable/function type: `(params) => returnType`. */
|
|
131
|
+
export interface SubsystemCallableTypeInfo {
|
|
132
|
+
parameters?: SubsystemParamInfo[];
|
|
133
|
+
returnType?: string;
|
|
134
|
+
}
|
|
135
|
+
/** One enum member, with its optional literal value. */
|
|
136
|
+
export interface SubsystemEnumMemberInfo {
|
|
137
|
+
name: string;
|
|
138
|
+
value?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Type-family declaration (interface / type alias / enum). Structured buckets
|
|
142
|
+
* cover common shapes; `rhs` is the verbatim escape hatch when none fit.
|
|
143
|
+
*/
|
|
144
|
+
export interface SubsystemTypeDeclaration {
|
|
145
|
+
kind: 'type';
|
|
146
|
+
properties: SubsystemPropertyInfo[];
|
|
147
|
+
usedBy: SubsystemReferenceInfo[];
|
|
148
|
+
implementors: string[];
|
|
149
|
+
/** Generic type parameters, e.g. `<K extends keyof StudioMessages>`. */
|
|
150
|
+
generics?: SubsystemTypeParamInfo[];
|
|
151
|
+
/** Callable type — `(params) => returnType`. */
|
|
152
|
+
signature?: SubsystemCallableTypeInfo;
|
|
153
|
+
/** Enum members (name, optional literal value). */
|
|
154
|
+
enumMembers?: SubsystemEnumMemberInfo[];
|
|
155
|
+
/** Alias whose RHS is a plain reference, e.g. `ServerSessionRow[]`. */
|
|
156
|
+
aliasOf?: string;
|
|
157
|
+
/** Simple union of alternatives, e.g. `'started' | 'stopped'`. */
|
|
158
|
+
unionOf?: string[];
|
|
159
|
+
/**
|
|
160
|
+
* Verbatim RHS — escape hatch for shapes the structured fields can't
|
|
161
|
+
* express. Wins over every shape above when set.
|
|
162
|
+
*/
|
|
163
|
+
rhs?: string;
|
|
164
|
+
}
|
|
165
|
+
export interface SubsystemExternalDeclaration {
|
|
166
|
+
kind: 'external';
|
|
167
|
+
label: string;
|
|
168
|
+
}
|
|
169
|
+
export interface SubsystemStoreDeclaration {
|
|
170
|
+
kind: 'store';
|
|
171
|
+
/** Where retained state lives / who mediates access. Authored, never
|
|
172
|
+
* extracted: `memory` (process-lifetime RAM), `disk` (this process
|
|
173
|
+
* reads/writes files), or `external` (another system — db/service; carries
|
|
174
|
+
* no `process`). */
|
|
175
|
+
storage?: 'memory' | 'disk' | 'external';
|
|
176
|
+
/**
|
|
177
|
+
* The type of the retained state itself — a store declares its type the way
|
|
178
|
+
* every other declaration does. A state block names its value type
|
|
179
|
+
* (`Map<string, FeedState>`, `Set<Listener>`); a table names its row/record
|
|
180
|
+
* type. Orthogonal to `storage`: an in-memory store still has a value type.
|
|
181
|
+
*
|
|
182
|
+
* Optional because a store with neither a `valueType` nor named `properties`
|
|
183
|
+
* has no declared type — that is a gap the audit can flag, not an error.
|
|
184
|
+
*/
|
|
185
|
+
valueType?: string;
|
|
186
|
+
/** Resolvable target of `valueType` — makes the type navigable like a
|
|
187
|
+
* property's `typeRef`. */
|
|
188
|
+
valueTypeRef?: SubsystemReferenceInfo;
|
|
189
|
+
properties: SubsystemPropertyInfo[];
|
|
190
|
+
}
|
|
191
|
+
/** A single authored attribute on a custom entity — free-form key/value. */
|
|
192
|
+
export interface SubsystemCustomEntityAttribute {
|
|
193
|
+
key: string;
|
|
194
|
+
value: string;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Declaration for `construct: custom_entity` (an actor — Person/agent/queue).
|
|
198
|
+
* Authored, never extracted: there is no backing source declaration.
|
|
199
|
+
* `attributes` is authored key/value (e.g. `slack`, `permission`, `level`).
|
|
200
|
+
*/
|
|
201
|
+
export interface SubsystemCustomEntityDeclaration {
|
|
202
|
+
kind: 'custom_entity';
|
|
203
|
+
attributes: SubsystemCustomEntityAttribute[];
|
|
204
|
+
}
|
|
205
|
+
/** Structured declaration shape of a construct. */
|
|
206
|
+
export type SubsystemConstructDeclaration = SubsystemClassDeclaration | SubsystemFunctionDeclaration | SubsystemMethodDeclaration | SubsystemTypeDeclaration | SubsystemExternalDeclaration | SubsystemStoreDeclaration | SubsystemCustomEntityDeclaration;
|
|
207
|
+
/** A component node — the named unit, construct-tagged. */
|
|
208
|
+
export interface SubsystemComponent {
|
|
209
|
+
/**
|
|
210
|
+
* Model-local stable alias. Referenced by trail `from` /
|
|
211
|
+
* `to`; unique per model. Edges point at the alias, not the location — a
|
|
212
|
+
* file move or symbol rename leaves edges intact. Code identity lives on
|
|
213
|
+
* `purl` + `file` + `symbol` and is what composed (multi-model) views
|
|
214
|
+
* join on, not this field.
|
|
215
|
+
*/
|
|
216
|
+
alias: string;
|
|
217
|
+
/** Display label. Prefer aligning with `symbol` when present. */
|
|
218
|
+
name: string;
|
|
219
|
+
construct: SubsystemConstruct;
|
|
220
|
+
/** Repo-root-relative source path. */
|
|
221
|
+
file: string;
|
|
222
|
+
/** PURL for repo/package grouping. Multi-repo graphs draw package frames from distinct purl repo keys. */
|
|
223
|
+
purl: string;
|
|
224
|
+
purpose?: string;
|
|
225
|
+
role?: SubsystemComponentRole;
|
|
226
|
+
/**
|
|
227
|
+
* Design / migration placeholder — participates in edges and flows but is
|
|
228
|
+
* not a live source declaration yet. Verification skips source checks until
|
|
229
|
+
* promoted (`proposed` cleared, `file` + `symbol` filled). Orthogonal to
|
|
230
|
+
* `construct` (intended shape) and `role` (topology).
|
|
231
|
+
*/
|
|
232
|
+
proposed?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Framework that owns the stereotype (e.g. `react`, `nestjs`).
|
|
235
|
+
* Orthogonal to `construct` — a React component is still `construct: function`.
|
|
236
|
+
*/
|
|
237
|
+
framework?: SubsystemFramework;
|
|
238
|
+
/**
|
|
239
|
+
* Framework pattern this declaration plays (e.g. `component`, `hook`).
|
|
240
|
+
* Prefer this over inventing framework-specific constructs.
|
|
241
|
+
*/
|
|
242
|
+
stereotype?: SubsystemStereotype;
|
|
243
|
+
process?: string;
|
|
244
|
+
/**
|
|
245
|
+
* Source-module membership — which file/module this export belongs to
|
|
246
|
+
* (e.g. `src/session/transcript.ts`). Nodes sharing a `module` are drawn
|
|
247
|
+
* inside one boundary frame. Prefer this over inventing a module construct:
|
|
248
|
+
* anchor each export as its real construct (`function` / `class` / …) and
|
|
249
|
+
* set `module` so the file reads as a frame, not a node. Orthogonal to
|
|
250
|
+
* `process` (runtime deployment unit).
|
|
251
|
+
*/
|
|
252
|
+
module?: string;
|
|
253
|
+
/** Code identity — real declaration in `file` when set. */
|
|
254
|
+
symbol?: string;
|
|
255
|
+
/**
|
|
256
|
+
* Actor kind for `construct: custom_entity` (e.g. `Person`, `agent`,
|
|
257
|
+
* `queue`), rendered as the node badge. Ignored on code constructs.
|
|
258
|
+
*/
|
|
259
|
+
entityKind?: SubsystemEntityKind;
|
|
260
|
+
/**
|
|
261
|
+
* Node + declaration accent override (hex). Wins over the construct-derived
|
|
262
|
+
* color. Typically used to theme a custom entity (agent, queue).
|
|
263
|
+
*/
|
|
264
|
+
color?: string;
|
|
265
|
+
layer?: number;
|
|
266
|
+
/** Structured declaration shape of the construct (params, members, …). */
|
|
267
|
+
declaration?: SubsystemConstructDeclaration;
|
|
268
|
+
declarationProvenance?: SubsystemDeclarationProvenance;
|
|
269
|
+
tokens?: SubsystemDeclToken[];
|
|
270
|
+
/** Location anchor (file/line/hash) — distinct from `declaration` (shape). */
|
|
271
|
+
declarationRef?: SubsystemDeclarationRef;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Derived / display graph edge used by renderers. Built from trail
|
|
275
|
+
* steps — not authored as its own document field.
|
|
276
|
+
*/
|
|
277
|
+
export interface SubsystemComponentEdge {
|
|
278
|
+
id: string;
|
|
279
|
+
from: string;
|
|
280
|
+
to: string;
|
|
281
|
+
mechanism: SubsystemEdgeMechanism;
|
|
282
|
+
}
|
|
283
|
+
export interface SubsystemTrailStep {
|
|
284
|
+
/** Source component alias. */
|
|
285
|
+
from: string;
|
|
286
|
+
/** Target component alias. */
|
|
287
|
+
to: string;
|
|
288
|
+
/** Runtime seam label (Set B). */
|
|
289
|
+
mechanism: SubsystemTrailMechanism;
|
|
290
|
+
file: string;
|
|
291
|
+
/** 1-based line within `file`. */
|
|
292
|
+
line: number;
|
|
293
|
+
/**
|
|
294
|
+
* File-anchored purl of the seam site (e.g.
|
|
295
|
+
* `pkg:github/owner/name#path/to/file.ts`), mirroring component `purl`.
|
|
296
|
+
* Required: readers resolve the checkout from this instead of guessing
|
|
297
|
+
* the repo from the step's endpoint components.
|
|
298
|
+
*/
|
|
299
|
+
purl: string;
|
|
300
|
+
/**
|
|
301
|
+
* Frame name for this step — the function/method on the stack at the site.
|
|
302
|
+
* Required: the Trails list shows this instead of a bare
|
|
303
|
+
* mechanism + filename fallback.
|
|
304
|
+
*/
|
|
305
|
+
symbol: string;
|
|
306
|
+
/**
|
|
307
|
+
* Free-text note anchored to this step's site line. Optional — informative
|
|
308
|
+
* only, never verified against source; viewers surface it via the codeview's
|
|
309
|
+
* annotation column.
|
|
310
|
+
*/
|
|
311
|
+
annotation?: string;
|
|
312
|
+
}
|
|
313
|
+
/** Ordered runtime trail (one named behavior story). */
|
|
314
|
+
export interface SubsystemTrail {
|
|
315
|
+
id: string;
|
|
316
|
+
title: string;
|
|
317
|
+
steps: SubsystemTrailStep[];
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Portable subsystem model — the shareable standard.
|
|
321
|
+
* No host paths, provenance, document-level repo, store ids, or verification.
|
|
322
|
+
* Repo identity lives on each component's `purl`.
|
|
323
|
+
*/
|
|
324
|
+
/**
|
|
325
|
+
* A pinned commit for one referenced repo. Keyed by `purlRepoKey` (the purl
|
|
326
|
+
* with its fragment stripped). Commit-only — a dirty tree has no reproducible
|
|
327
|
+
* name and is never recorded as a coordinate.
|
|
328
|
+
*/
|
|
329
|
+
export type PurlCommit = string;
|
|
330
|
+
export interface SubsystemModelDocument {
|
|
331
|
+
/**
|
|
332
|
+
* Optional pointer to the JSON Schema that describes this file. Lets editors
|
|
333
|
+
* give autocomplete and validation when the field is set.
|
|
334
|
+
*/
|
|
335
|
+
$schema?: string;
|
|
336
|
+
title: string;
|
|
337
|
+
description?: string;
|
|
338
|
+
components: SubsystemComponent[];
|
|
339
|
+
/** Runtime trails (ordered steps with sites). */
|
|
340
|
+
trails?: SubsystemTrail[];
|
|
341
|
+
/**
|
|
342
|
+
* The commit each referenced repo was at when the model was created. The
|
|
343
|
+
* coordinate system for every `file:line` in the document: without it, a
|
|
344
|
+
* line pointer is ambiguous across commits. Immutable after create.
|
|
345
|
+
*/
|
|
346
|
+
createdAtCommits?: Record<string, PurlCommit>;
|
|
347
|
+
/**
|
|
348
|
+
* The commit each referenced repo was at when a full audit last passed
|
|
349
|
+
* against a clean referenced state. Absent until an audit earns it.
|
|
350
|
+
*/
|
|
351
|
+
verifiedAtCommits?: Record<string, PurlCommit>;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Hydrated model: portable document + store metadata.
|
|
355
|
+
* Shape used after a host accepts/persists a model for viewing on a machine.
|
|
356
|
+
* Local path binding is resolved from Alexandria (via each component's purl)
|
|
357
|
+
* and repo identity is derived from purls — neither is stored here.
|
|
358
|
+
*/
|
|
359
|
+
export interface SubsystemModelHydrated extends SubsystemModelDocument {
|
|
360
|
+
/** Store-assigned id when persisted. */
|
|
361
|
+
id?: string;
|
|
362
|
+
createdAt?: string;
|
|
363
|
+
updatedAt?: string;
|
|
364
|
+
/** Host verification result; shape is host-defined. */
|
|
365
|
+
verification?: unknown;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Type guard: true when the value plausibly conforms to a portable
|
|
369
|
+
* subsystem model. Shallow check — full validation belongs to the schema /
|
|
370
|
+
* host validator.
|
|
371
|
+
*/
|
|
372
|
+
export declare function isSubsystemModelDocument(value: unknown): value is SubsystemModelDocument;
|
|
373
|
+
/**
|
|
374
|
+
* Keep only portable fields — drop host bindings / store metadata if a
|
|
375
|
+
* hydrated record is passed in. Use before writing a gist or any other
|
|
376
|
+
* share surface that must stay schema-clean.
|
|
377
|
+
*/
|
|
378
|
+
export declare function toPortableDocument(doc: SubsystemModelDocument): SubsystemModelDocument;
|
|
379
|
+
/** Stable id for a derived graph edge from a trail step. */
|
|
380
|
+
export declare function derivedGraphEdgeId(from: string, to: string, mechanism: SubsystemEdgeMechanism): string;
|
|
381
|
+
/**
|
|
382
|
+
* Build display edges for the graph canvas from trail steps
|
|
383
|
+
* (deduped by from/to/mechanism).
|
|
384
|
+
*/
|
|
385
|
+
export declare function deriveGraphEdges(doc: {
|
|
386
|
+
trails?: SubsystemTrail[];
|
|
387
|
+
}): SubsystemComponentEdge[];
|
|
388
|
+
//# sourceMappingURL=subsystem-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subsystem-model.d.ts","sourceRoot":"","sources":["../../src/types/subsystem-model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAE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AAC;IACjC,iDAAiD;IACjD,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;IAC1B;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC9C;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CAChD;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAuB,SAAQ,sBAAsB;IACpE,wCAAwC;IACxC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,sBAAsB,CAOxF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,sBAAsB,GAC1B,sBAAsB,CAWxB;AAED,4DAA4D;AAC5D,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,sBAAsB,GAChC,MAAM,CAER;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE;IACpC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;CAC3B,GAAG,sBAAsB,EAAE,CAgB3B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Subsystem Model Types
|
|
4
|
+
*
|
|
5
|
+
* Two layers — do not conflate them:
|
|
6
|
+
*
|
|
7
|
+
* 1. **Portable document** (`SubsystemModelDocument`) — the shareable standard.
|
|
8
|
+
* Schema: `schemas/subsystem-model.schema.json`
|
|
9
|
+
* (`https://principal-ai.dev/schemas/subsystem-model.schema.json`).
|
|
10
|
+
*
|
|
11
|
+
* 2. **Hydrated envelope** (`SubsystemModelHydrated`) — portable document plus
|
|
12
|
+
* host/machine binding (local roots, provenance, store ids, verification).
|
|
13
|
+
* Used by viewers and stores; not part of the portable standard.
|
|
14
|
+
*
|
|
15
|
+
* Ontology: construct = what a node is, framework + stereotype = which
|
|
16
|
+
* framework pattern it plays, role = where it sits, process = where it runs,
|
|
17
|
+
* module = which source file/module the export belongs to,
|
|
18
|
+
* proposed = not yet in source (design / migration placeholder).
|
|
19
|
+
* Package (repo) frames are derived from component `purl` when a graph spans
|
|
20
|
+
* multiple repos — there is no separate `package` field.
|
|
21
|
+
* `symbol` is the code identity; `name` is the display label.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.deriveGraphEdges = exports.derivedGraphEdgeId = exports.toPortableDocument = exports.isSubsystemModelDocument = void 0;
|
|
25
|
+
/**
|
|
26
|
+
* Type guard: true when the value plausibly conforms to a portable
|
|
27
|
+
* subsystem model. Shallow check — full validation belongs to the schema /
|
|
28
|
+
* host validator.
|
|
29
|
+
*/
|
|
30
|
+
function isSubsystemModelDocument(value) {
|
|
31
|
+
if (!value || typeof value !== 'object')
|
|
32
|
+
return false;
|
|
33
|
+
const v = value;
|
|
34
|
+
return typeof v.title === 'string' && Array.isArray(v.components);
|
|
35
|
+
}
|
|
36
|
+
exports.isSubsystemModelDocument = isSubsystemModelDocument;
|
|
37
|
+
/**
|
|
38
|
+
* Keep only portable fields — drop host bindings / store metadata if a
|
|
39
|
+
* hydrated record is passed in. Use before writing a gist or any other
|
|
40
|
+
* share surface that must stay schema-clean.
|
|
41
|
+
*/
|
|
42
|
+
function toPortableDocument(doc) {
|
|
43
|
+
const out = {
|
|
44
|
+
title: doc.title,
|
|
45
|
+
components: doc.components,
|
|
46
|
+
};
|
|
47
|
+
if (doc.$schema)
|
|
48
|
+
out.$schema = doc.$schema;
|
|
49
|
+
if (doc.description)
|
|
50
|
+
out.description = doc.description;
|
|
51
|
+
if (doc.trails)
|
|
52
|
+
out.trails = doc.trails;
|
|
53
|
+
if (doc.createdAtCommits)
|
|
54
|
+
out.createdAtCommits = doc.createdAtCommits;
|
|
55
|
+
if (doc.verifiedAtCommits)
|
|
56
|
+
out.verifiedAtCommits = doc.verifiedAtCommits;
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
exports.toPortableDocument = toPortableDocument;
|
|
60
|
+
/** Stable id for a derived graph edge from a trail step. */
|
|
61
|
+
function derivedGraphEdgeId(from, to, mechanism) {
|
|
62
|
+
return `${from}--${mechanism}-->${to}`;
|
|
63
|
+
}
|
|
64
|
+
exports.derivedGraphEdgeId = derivedGraphEdgeId;
|
|
65
|
+
/**
|
|
66
|
+
* Build display edges for the graph canvas from trail steps
|
|
67
|
+
* (deduped by from/to/mechanism).
|
|
68
|
+
*/
|
|
69
|
+
function deriveGraphEdges(doc) {
|
|
70
|
+
const byId = new Map();
|
|
71
|
+
for (const w of doc.trails ?? []) {
|
|
72
|
+
for (const step of w.steps) {
|
|
73
|
+
const id = derivedGraphEdgeId(step.from, step.to, step.mechanism);
|
|
74
|
+
if (!byId.has(id)) {
|
|
75
|
+
byId.set(id, {
|
|
76
|
+
id,
|
|
77
|
+
from: step.from,
|
|
78
|
+
to: step.to,
|
|
79
|
+
mechanism: step.mechanism,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return [...byId.values()];
|
|
85
|
+
}
|
|
86
|
+
exports.deriveGraphEdges = deriveGraphEdges;
|
|
87
|
+
//# sourceMappingURL=subsystem-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subsystem-model.js","sourceRoot":"","sources":["../../src/types/subsystem-model.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;;;AA8ZH;;;;GAIG;AACH,SAAgB,wBAAwB,CAAC,KAAc;IACrD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAA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,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAClE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;gBACjB,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;oBACX,EAAE;oBACF,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,EAAE,EAAE,IAAI,CAAC,EAAE;oBACX,SAAS,EAAE,IAAI,CAAC,SAAS;iBAC1B,CAAC,CAAC;aACJ;SACF;KACF;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AAC5B,CAAC;AAlBD,4CAkBC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-field validation for a subsystem model document.
|
|
3
|
+
*
|
|
4
|
+
* These are the rules the JSON Schema (`schemas/subsystem-model.schema.json`)
|
|
5
|
+
* cannot express — anything that spans fields or arrays: alias uniqueness,
|
|
6
|
+
* referential integrity between trails and components, and the
|
|
7
|
+
* `module` implies `file` invariant. Structural checks (types, `required`,
|
|
8
|
+
* enums, ranges, closed objects) belong to the schema and are enforced per
|
|
9
|
+
* surface; this module owns only what the schema can't.
|
|
10
|
+
*
|
|
11
|
+
* Pure and dependency-free (browser-safe) — no JSON Schema validator here.
|
|
12
|
+
*/
|
|
13
|
+
import type { SubsystemModelDocument } from './types/subsystem-model';
|
|
14
|
+
export interface SubsystemValidationProblem {
|
|
15
|
+
/** JSON-pointer-ish location, e.g. `/components/2` or `/trails/0/steps/0/from`. */
|
|
16
|
+
path: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate the cross-field rules of a subsystem model document. Returns an
|
|
21
|
+
* empty array when the document is consistent.
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateSubsystemModelCrossField(doc: SubsystemModelDocument): SubsystemValidationProblem[];
|
|
24
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,sBAAsB,EAGvB,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,0BAA0B;IACzC,mFAAmF;IACnF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAyBD;;;GAGG;AACH,wBAAgB,gCAAgC,CAC9C,GAAG,EAAE,sBAAsB,GAC1B,0BAA0B,EAAE,CAuE9B"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Cross-field validation for a subsystem model document.
|
|
4
|
+
*
|
|
5
|
+
* These are the rules the JSON Schema (`schemas/subsystem-model.schema.json`)
|
|
6
|
+
* cannot express — anything that spans fields or arrays: alias uniqueness,
|
|
7
|
+
* referential integrity between trails and components, and the
|
|
8
|
+
* `module` implies `file` invariant. Structural checks (types, `required`,
|
|
9
|
+
* enums, ranges, closed objects) belong to the schema and are enforced per
|
|
10
|
+
* surface; this module owns only what the schema can't.
|
|
11
|
+
*
|
|
12
|
+
* Pure and dependency-free (browser-safe) — no JSON Schema validator here.
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.validateSubsystemModelCrossField = void 0;
|
|
16
|
+
function isUngrounded(c) {
|
|
17
|
+
return c.construct === 'external' || c.proposed === true;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* `file` is a path *inside the repo named by `purl`* — it resolves against that
|
|
21
|
+
* checkout, never against an installed artifact. `node_modules/` is installed,
|
|
22
|
+
* gitignored, and its layout depends on hoisting, so a claim anchored there can
|
|
23
|
+
* never resolve and is unverifiable by construction.
|
|
24
|
+
*
|
|
25
|
+
* Such a component is a third-party dependency: model it as `construct:
|
|
26
|
+
* 'external'` with `purl: 'pkg:npm/<package>'` and no file. Applies to externals
|
|
27
|
+
* too — they carry no file by design, so an install path there is dead weight
|
|
28
|
+
* that draws a link nothing can open. `proposed` is exempt like every other
|
|
29
|
+
* grounding rule: its file is a placeholder for something not placed yet.
|
|
30
|
+
*
|
|
31
|
+
* The same rule covers trail step files — a seam into an external belongs
|
|
32
|
+
* at the call site in the caller, which *is* in the repo.
|
|
33
|
+
*/
|
|
34
|
+
function mentionsNodeModules(path) {
|
|
35
|
+
return /(^|\/)node_modules(\/|$)/.test(path);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Validate the cross-field rules of a subsystem model document. Returns an
|
|
39
|
+
* empty array when the document is consistent.
|
|
40
|
+
*/
|
|
41
|
+
function validateSubsystemModelCrossField(doc) {
|
|
42
|
+
const problems = [];
|
|
43
|
+
const components = doc.components ?? [];
|
|
44
|
+
const trails = doc.trails ?? [];
|
|
45
|
+
// Component aliases must be unique, and the set is the referential target
|
|
46
|
+
// for trail steps.
|
|
47
|
+
const ids = new Set();
|
|
48
|
+
components.forEach((c, i) => {
|
|
49
|
+
if (ids.has(c.alias)) {
|
|
50
|
+
problems.push({
|
|
51
|
+
path: `/components/${i}/alias`,
|
|
52
|
+
message: `component ${JSON.stringify(c.alias)}: duplicate alias`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
ids.add(c.alias);
|
|
57
|
+
}
|
|
58
|
+
// A grounded component that claims a `module` needs a `file` to ground the
|
|
59
|
+
// frame. Externals / proposed carry no file by design.
|
|
60
|
+
const module = typeof c.module === 'string' ? c.module.trim() : '';
|
|
61
|
+
const file = typeof c.file === 'string' ? c.file.trim() : '';
|
|
62
|
+
if (module && !file && !isUngrounded(c)) {
|
|
63
|
+
problems.push({
|
|
64
|
+
path: `/components/${i}/module`,
|
|
65
|
+
message: `component ${JSON.stringify(c.alias)}: module ${JSON.stringify(module)} is set but file is empty — a module frame needs a file to ground it (mark the component proposed if it is not placed yet).`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (file && c.proposed !== true && mentionsNodeModules(file)) {
|
|
69
|
+
problems.push({
|
|
70
|
+
path: `/components/${i}/file`,
|
|
71
|
+
message: `component ${JSON.stringify(c.alias)}: file ${JSON.stringify(file)} points into node_modules — installed artifacts are not part of the repo and cannot be verified. Model the dependency as construct "external" with purl "pkg:npm/<package>" and no file, or anchor the claim to the package's real source.`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
trails.forEach((w, ti) => {
|
|
76
|
+
(w.steps ?? []).forEach((step, si) => {
|
|
77
|
+
if (!ids.has(step.from)) {
|
|
78
|
+
problems.push({
|
|
79
|
+
path: `/trails/${ti}/steps/${si}/from`,
|
|
80
|
+
message: `trail ${JSON.stringify(w.id)}: step ${si} from ${JSON.stringify(step.from)} does not match any component alias`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!ids.has(step.to)) {
|
|
84
|
+
problems.push({
|
|
85
|
+
path: `/trails/${ti}/steps/${si}/to`,
|
|
86
|
+
message: `trail ${JSON.stringify(w.id)}: step ${si} to ${JSON.stringify(step.to)} does not match any component alias`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// A file-anchored step purl names its own site: the fragment must be
|
|
90
|
+
// the step file. Repo-only purls still resolve, so only the anchored
|
|
91
|
+
// form is checked.
|
|
92
|
+
if (typeof step.purl === 'string' && step.purl.includes('#')) {
|
|
93
|
+
const fragment = step.purl.split('#').slice(1).join('#');
|
|
94
|
+
if (fragment !== step.file) {
|
|
95
|
+
problems.push({
|
|
96
|
+
path: `/trails/${ti}/steps/${si}/purl`,
|
|
97
|
+
message: `trail ${JSON.stringify(w.id)}: step ${si} purl fragment ${JSON.stringify(fragment)} does not match step file ${JSON.stringify(step.file)}`,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (mentionsNodeModules(step.file)) {
|
|
102
|
+
problems.push({
|
|
103
|
+
path: `/trails/${ti}/steps/${si}/file`,
|
|
104
|
+
message: `trail ${JSON.stringify(w.id)}: step ${si} file ${JSON.stringify(step.file)} points into node_modules — anchor the seam at the call site inside the repo instead.`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return problems;
|
|
110
|
+
}
|
|
111
|
+
exports.validateSubsystemModelCrossField = validateSubsystemModelCrossField;
|
|
112
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAcH,SAAS,YAAY,CAAC,CAAqB;IACzC,OAAO,CAAC,CAAC,SAAS,KAAK,UAAU,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CAAC;AAC3D,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,0BAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,SAAgB,gCAAgC,CAC9C,GAA2B;IAE3B,MAAM,QAAQ,GAAiC,EAAE,CAAC;IAClD,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;IAEhC,0EAA0E;IAC1E,mBAAmB;IACnB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1B,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;YACpB,QAAQ,CAAC,IAAI,CAAC;gBACZ,IAAI,EAAE,eAAe,CAAC,QAAQ;gBAC9B,OAAO,EAAE,aAA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,SAAS,CAAC,QAAQ,CAAC,6BAA6B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;qBACrJ,CAAC,CAAC;iBACJ;aACF;YACD,IAAI,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBAClC,QAAQ,CAAC,IAAI,CAAC;oBACZ,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO;oBACtC,OAAO,EAAE,SAAS,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,uFAAuF;iBAC5K,CAAC,CAAC;aACJ;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC;AAzED,4EAyEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@principal-ai/subsystems-core",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.1",
|
|
4
4
|
"description": "Subsystem model types and agent-session tooling for Principal AI",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"test": "bun test",
|
|
40
40
|
"test:watch": "bun test --watch",
|
|
41
41
|
"test:coverage": "bun test --coverage",
|
|
42
|
+
"prepack": "bun run build",
|
|
42
43
|
"lint": "cd ../.. && eslint packages/subsystems-core --ext .ts,.tsx,.js,.jsx",
|
|
43
44
|
"lint:fix": "cd ../.. && eslint packages/subsystems-core --ext .ts,.tsx,.js,.jsx --fix"
|
|
44
45
|
},
|