@principal-ai/principal-studio-cli 0.37.1 → 0.39.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.
@@ -152,8 +152,8 @@ async function createAction(options) {
152
152
  title: body['title'],
153
153
  description: typeof body['description'] === 'string' ? body['description'] : undefined,
154
154
  components: body['components'],
155
- edges: body['edges'],
156
- throughlines: Array.isArray(body['throughlines']) ? body['throughlines'] : undefined,
155
+ relations: body['relations'],
156
+ walkthroughs: Array.isArray(body['walkthroughs']) ? body['walkthroughs'] : undefined,
157
157
  source: typeof body['source'] === 'string' ? body['source'] : undefined,
158
158
  repo: body['repo'],
159
159
  repoRoot: typeof body['repoRoot'] === 'string' ? body['repoRoot'] : undefined,
package/dist/index.cjs CHANGED
@@ -3457,29 +3457,63 @@ var require_subsystem_model = __commonJS({
3457
3457
  "node_modules/@principal-ai/subsystems-core/dist/types/subsystem-model.js"(exports2) {
3458
3458
  "use strict";
3459
3459
  Object.defineProperty(exports2, "__esModule", { value: true });
3460
- exports2.toPortableDocument = exports2.isSubsystemModelDocument = void 0;
3460
+ exports2.deriveGraphEdges = exports2.derivedGraphEdgeId = exports2.toPortableDocument = exports2.isSubsystemModelDocument = void 0;
3461
3461
  function isSubsystemModelDocument(value) {
3462
3462
  if (!value || typeof value !== "object")
3463
3463
  return false;
3464
3464
  const v = value;
3465
- return typeof v.title === "string" && Array.isArray(v.components) && Array.isArray(v.edges);
3465
+ return typeof v.title === "string" && Array.isArray(v.components) && Array.isArray(v.relations);
3466
3466
  }
3467
3467
  exports2.isSubsystemModelDocument = isSubsystemModelDocument;
3468
3468
  function toPortableDocument(doc) {
3469
3469
  const out = {
3470
3470
  title: doc.title,
3471
3471
  components: doc.components,
3472
- edges: doc.edges
3472
+ relations: doc.relations
3473
3473
  };
3474
3474
  if (doc.$schema)
3475
3475
  out.$schema = doc.$schema;
3476
3476
  if (doc.description)
3477
3477
  out.description = doc.description;
3478
- if (doc.throughlines)
3479
- out.throughlines = doc.throughlines;
3478
+ if (doc.walkthroughs)
3479
+ out.walkthroughs = doc.walkthroughs;
3480
3480
  return out;
3481
3481
  }
3482
3482
  exports2.toPortableDocument = toPortableDocument;
3483
+ function derivedGraphEdgeId(from, to, mechanism) {
3484
+ return `${from}--${mechanism}-->${to}`;
3485
+ }
3486
+ exports2.derivedGraphEdgeId = derivedGraphEdgeId;
3487
+ function deriveGraphEdges2(doc) {
3488
+ const byId = /* @__PURE__ */ new Map();
3489
+ for (const r of doc.relations ?? []) {
3490
+ const id = r.id || derivedGraphEdgeId(r.from, r.to, r.relationType);
3491
+ if (!byId.has(id)) {
3492
+ byId.set(id, {
3493
+ id,
3494
+ from: r.from,
3495
+ to: r.to,
3496
+ mechanism: r.relationType,
3497
+ refs: r.refs
3498
+ });
3499
+ }
3500
+ }
3501
+ for (const w of doc.walkthroughs ?? []) {
3502
+ for (const step of w.steps) {
3503
+ const id = derivedGraphEdgeId(step.from, step.to, step.mechanism);
3504
+ if (!byId.has(id)) {
3505
+ byId.set(id, {
3506
+ id,
3507
+ from: step.from,
3508
+ to: step.to,
3509
+ mechanism: step.mechanism
3510
+ });
3511
+ }
3512
+ }
3513
+ }
3514
+ return [...byId.values()];
3515
+ }
3516
+ exports2.deriveGraphEdges = deriveGraphEdges2;
3483
3517
  }
3484
3518
  });
3485
3519
 
@@ -9790,6 +9824,31 @@ var require_node = __commonJS({
9790
9824
  }
9791
9825
  });
9792
9826
 
9827
+ // node_modules/@principal-ai/subsystems-core/dist/index.js
9828
+ var require_dist2 = __commonJS({
9829
+ "node_modules/@principal-ai/subsystems-core/dist/index.js"(exports2) {
9830
+ "use strict";
9831
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
9832
+ if (k2 === void 0) k2 = k;
9833
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9834
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9835
+ desc = { enumerable: true, get: function() {
9836
+ return m[k];
9837
+ } };
9838
+ }
9839
+ Object.defineProperty(o, k2, desc);
9840
+ } : function(o, m, k, k2) {
9841
+ if (k2 === void 0) k2 = k;
9842
+ o[k2] = m[k];
9843
+ });
9844
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
9845
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
9846
+ };
9847
+ Object.defineProperty(exports2, "__esModule", { value: true });
9848
+ __exportStar(require_types(), exports2);
9849
+ }
9850
+ });
9851
+
9793
9852
  // node_modules/commander/esm.mjs
9794
9853
  var import_index = __toESM(require_commander(), 1);
9795
9854
  var {
@@ -15379,29 +15438,9 @@ var import_node_fs7 = require("node:fs");
15379
15438
  var import_node_fs6 = require("node:fs");
15380
15439
  var import_node_os6 = require("node:os");
15381
15440
  var import_node_path5 = require("node:path");
15441
+ var import_subsystems_core = __toESM(require_dist2(), 1);
15382
15442
  var ROOT3 = (0, import_node_path5.join)((0, import_node_os6.homedir)(), ".principal", "subsystem-models");
15383
15443
  var INDEX_PATH = (0, import_node_path5.join)(ROOT3, "_index.json");
15384
- var SUBSYSTEM_EDGE_MECHANISMS = [
15385
- "imports",
15386
- "imports_from",
15387
- "re_exports",
15388
- "defines",
15389
- "calls",
15390
- "extends",
15391
- "inherits",
15392
- "implements",
15393
- "mixes_in",
15394
- "uses",
15395
- "method",
15396
- "references",
15397
- "contains",
15398
- "feeds",
15399
- "produces",
15400
- "writes",
15401
- "reads",
15402
- "watches",
15403
- "registers-into"
15404
- ];
15405
15444
  var SUBSYSTEM_COMPONENT_CONSTRUCTS = [
15406
15445
  "class",
15407
15446
  "function",
@@ -15413,7 +15452,7 @@ var SUBSYSTEM_COMPONENT_CONSTRUCTS = [
15413
15452
  "external",
15414
15453
  "custom_entity"
15415
15454
  ];
15416
- var SUBSYSTEM_DETAIL_PROVENANCES = ["verified", "authored"];
15455
+ var SUBSYSTEM_DECLARATION_PROVENANCES = ["verified", "authored"];
15417
15456
  function graphId() {
15418
15457
  const ts = Date.now();
15419
15458
  const rand = Math.random().toString(36).slice(2, 11);
@@ -15428,56 +15467,81 @@ function subsystemModelFilePath(id) {
15428
15467
  async function ensureDir() {
15429
15468
  await import_node_fs6.promises.mkdir(ROOT3, { recursive: true });
15430
15469
  }
15431
- function findEdgeMechanismProblems(edges) {
15432
- if (!Array.isArray(edges)) return [];
15470
+ var SUBSYSTEM_RELATION_TYPES = [
15471
+ "imports",
15472
+ "extends",
15473
+ "inherits",
15474
+ "implements",
15475
+ "mixes_in",
15476
+ "method",
15477
+ "references",
15478
+ "contains"
15479
+ ];
15480
+ var SUBSYSTEM_WALKTHROUGH_MECHANISMS = [
15481
+ "calls",
15482
+ "uses",
15483
+ "feeds",
15484
+ "produces",
15485
+ "writes",
15486
+ "reads",
15487
+ "watches",
15488
+ "registers-into"
15489
+ ];
15490
+ function findRelationTypeProblems(relations) {
15491
+ if (!Array.isArray(relations)) return ["relations must be an array"];
15433
15492
  const problems = [];
15434
- for (const edge of edges) {
15435
- const e = edge;
15436
- if (typeof e?.mechanism === "string" && SUBSYSTEM_EDGE_MECHANISMS.includes(e.mechanism)) {
15437
- continue;
15493
+ for (const rel of relations) {
15494
+ const r = rel;
15495
+ if (typeof r?.id !== "string" || !r.id.trim()) {
15496
+ problems.push(`relation ${JSON.stringify(r?.id ?? "<no id>")}: id is required`);
15497
+ }
15498
+ if (typeof r?.from !== "string" || !r.from.trim()) {
15499
+ problems.push(`relation ${JSON.stringify(r?.id ?? "<no id>")}: from is required`);
15500
+ }
15501
+ if (typeof r?.to !== "string" || !r.to.trim()) {
15502
+ problems.push(`relation ${JSON.stringify(r?.id ?? "<no id>")}: to is required`);
15503
+ }
15504
+ if (typeof r?.relationType !== "string" || !SUBSYSTEM_RELATION_TYPES.includes(r.relationType)) {
15505
+ problems.push(
15506
+ `relation ${JSON.stringify(r?.id ?? "<no id>")}: unknown relationType ${JSON.stringify(r?.relationType)}`
15507
+ );
15438
15508
  }
15439
- problems.push(
15440
- `edge ${JSON.stringify(e?.id ?? "<no id>")}: unknown mechanism ${JSON.stringify(e?.mechanism)} \u2014 allowed: ${SUBSYSTEM_EDGE_MECHANISMS.join(", ")}`
15441
- );
15442
15509
  }
15443
15510
  return problems;
15444
15511
  }
15445
- function findThroughlineProblems(edges, throughlines) {
15446
- if (throughlines === void 0) return [];
15447
- if (!Array.isArray(throughlines)) return ["throughlines must be an array"];
15448
- const edgeIds = new Set(
15449
- (Array.isArray(edges) ? edges : []).map((e) => e?.id).filter((id) => typeof id === "string")
15450
- );
15512
+ function findWalkthroughProblems(walkthroughs) {
15513
+ if (walkthroughs === void 0) return [];
15514
+ if (!Array.isArray(walkthroughs)) return ["walkthroughs must be an array"];
15451
15515
  const problems = [];
15452
- for (const tl of throughlines) {
15453
- const t = tl;
15454
- const label = JSON.stringify(t?.id ?? "<no id>");
15455
- if (typeof t?.id !== "string" || !t.id.trim()) {
15456
- problems.push(`throughline ${label}: id is required`);
15516
+ for (const wt of walkthroughs) {
15517
+ const w = wt;
15518
+ const label = JSON.stringify(w?.id ?? "<no id>");
15519
+ if (typeof w?.id !== "string" || !w.id.trim()) {
15520
+ problems.push(`walkthrough ${label}: id is required`);
15457
15521
  continue;
15458
15522
  }
15459
- if (typeof t?.title !== "string" || !t.title.trim()) {
15460
- problems.push(`throughline ${label}: title is required`);
15523
+ if (typeof w?.title !== "string" || !w.title.trim()) {
15524
+ problems.push(`walkthrough ${label}: title is required`);
15461
15525
  }
15462
- if (!Array.isArray(t.steps)) {
15463
- problems.push(`throughline ${label}: steps array is required`);
15526
+ if (!Array.isArray(w.steps)) {
15527
+ problems.push(`walkthrough ${label}: steps array is required`);
15464
15528
  continue;
15465
15529
  }
15466
- t.steps.forEach((step, i) => {
15530
+ w.steps.forEach((step, i) => {
15467
15531
  const s = step;
15468
- if (typeof s?.edgeId !== "string" || !edgeIds.has(s.edgeId)) {
15469
- problems.push(
15470
- `throughline ${label}: step ${i} edgeId ${JSON.stringify(s?.edgeId ?? "<missing>")} does not match any edge in the graph`
15471
- );
15532
+ if (typeof s?.from !== "string" || !s.from.trim()) {
15533
+ problems.push(`walkthrough ${label}: step ${i} from is required`);
15534
+ }
15535
+ if (typeof s?.to !== "string" || !s.to.trim()) {
15536
+ problems.push(`walkthrough ${label}: step ${i} to is required`);
15537
+ }
15538
+ if (typeof s?.mechanism !== "string" || !SUBSYSTEM_WALKTHROUGH_MECHANISMS.includes(s.mechanism)) {
15539
+ problems.push(`walkthrough ${label}: step ${i} unknown mechanism ${JSON.stringify(s?.mechanism)}`);
15472
15540
  }
15473
15541
  if (typeof s?.file !== "string" || !s.file.trim()) {
15474
- problems.push(
15475
- `throughline ${label}: step ${i} file is required (edgeId ${JSON.stringify(s?.edgeId ?? "<missing>")})`
15476
- );
15542
+ problems.push(`walkthrough ${label}: step ${i} file is required`);
15477
15543
  } else if (typeof s?.line !== "number" || !Number.isInteger(s.line) || s.line < 1) {
15478
- problems.push(
15479
- `throughline ${label}: step ${i} line must be a positive 1-based integer (edgeId ${JSON.stringify(s?.edgeId ?? "<missing>")}, file ${JSON.stringify(s?.file)})`
15480
- );
15544
+ problems.push(`walkthrough ${label}: step ${i} line must be a positive 1-based integer`);
15481
15545
  }
15482
15546
  });
15483
15547
  }
@@ -15497,46 +15561,47 @@ function findComponentConstructProblems(components) {
15497
15561
  }
15498
15562
  return problems;
15499
15563
  }
15500
- function findDetailProvenanceProblems(components) {
15564
+ function findDeclarationProvenanceProblems(components) {
15501
15565
  if (!Array.isArray(components)) return [];
15502
15566
  const problems = [];
15503
15567
  for (const component of components) {
15504
15568
  const c = component;
15505
- if (!c || typeof c !== "object" || !c["detail"]) continue;
15506
- const p = c["detailProvenance"];
15569
+ if (!c || typeof c !== "object") continue;
15570
+ if (!c["declaration"]) continue;
15571
+ const p = c["declarationProvenance"];
15507
15572
  if (p === void 0) continue;
15508
- if (typeof p === "string" && SUBSYSTEM_DETAIL_PROVENANCES.includes(p)) {
15573
+ if (typeof p === "string" && SUBSYSTEM_DECLARATION_PROVENANCES.includes(p)) {
15509
15574
  continue;
15510
15575
  }
15511
15576
  problems.push(
15512
- `component ${JSON.stringify(String(c["id"] ?? "<no id>"))}: invalid detailProvenance ${JSON.stringify(p)} \u2014 allowed: ${SUBSYSTEM_DETAIL_PROVENANCES.join(", ")}. Hand-authored details must be "authored"; "verified" is reserved for tool-extracted data.`
15577
+ `component ${JSON.stringify(String(c["id"] ?? "<no id>"))}: invalid declarationProvenance ${JSON.stringify(p)} \u2014 allowed: ${SUBSYSTEM_DECLARATION_PROVENANCES.join(", ")}. Hand-authored declarations must be "authored"; "verified" is reserved for tool-extracted data.`
15513
15578
  );
15514
15579
  }
15515
15580
  return problems;
15516
15581
  }
15517
- function normalizeDetailProvenance(components) {
15582
+ function normalizeDeclarationProvenance(components) {
15518
15583
  if (!Array.isArray(components)) return;
15519
15584
  for (const component of components) {
15520
15585
  const c = component;
15521
15586
  if (!c || typeof c !== "object") continue;
15522
- const detail = c["detail"];
15523
- if (!detail || typeof detail !== "object") {
15524
- delete c["detailProvenance"];
15587
+ const declaration = c["declaration"];
15588
+ if (!declaration || typeof declaration !== "object") {
15589
+ delete c["declarationProvenance"];
15525
15590
  continue;
15526
15591
  }
15527
- const p = c["detailProvenance"];
15528
- if (p !== "verified" && p !== "authored") c["detailProvenance"] = "authored";
15529
- const kind = detail["kind"];
15592
+ const p = c["declarationProvenance"];
15593
+ if (p !== "verified" && p !== "authored") c["declarationProvenance"] = "authored";
15594
+ const kind = declaration["kind"];
15530
15595
  const arrays = {
15531
15596
  function: ["parameters", "callers", "callees"],
15532
15597
  method: ["parameters"],
15533
15598
  class: ["methods", "properties", "extends", "implements", "instantiations", "references"],
15534
15599
  type: ["properties", "usedBy", "implementors"],
15535
- module: ["imports", "exports", "symbols"],
15536
- custom_entity: ["attributes"]
15600
+ custom_entity: ["attributes"],
15601
+ store: ["properties"]
15537
15602
  };
15538
15603
  for (const key of arrays[String(kind)] ?? []) {
15539
- if (!Array.isArray(detail[key])) detail[key] = [];
15604
+ if (!Array.isArray(declaration[key])) declaration[key] = [];
15540
15605
  }
15541
15606
  }
15542
15607
  }
@@ -15552,15 +15617,15 @@ function findCreateProblems(body) {
15552
15617
  if (!Array.isArray(body["components"])) {
15553
15618
  problems.push("components array is required");
15554
15619
  }
15555
- if (!Array.isArray(body["edges"])) {
15556
- problems.push("edges array is required");
15620
+ if (!Array.isArray(body["relations"])) {
15621
+ problems.push("relations array is required");
15557
15622
  }
15558
15623
  if (problems.length > 0) return problems;
15559
15624
  return [
15560
15625
  ...findComponentConstructProblems(body["components"]),
15561
- ...findDetailProvenanceProblems(body["components"]),
15562
- ...findEdgeMechanismProblems(body["edges"]),
15563
- ...findThroughlineProblems(body["edges"], body["throughlines"])
15626
+ ...findDeclarationProvenanceProblems(body["components"]),
15627
+ ...findRelationTypeProblems(body["relations"]),
15628
+ ...findWalkthroughProblems(body["walkthroughs"])
15564
15629
  ];
15565
15630
  }
15566
15631
  function indexEntryFor(record) {
@@ -15569,7 +15634,10 @@ function indexEntryFor(record) {
15569
15634
  title: record.title,
15570
15635
  description: record.description,
15571
15636
  componentCount: record.components.length,
15572
- edgeCount: record.edges.length,
15637
+ edgeCount: (0, import_subsystems_core.deriveGraphEdges)({
15638
+ relations: record.relations,
15639
+ walkthroughs: record.walkthroughs
15640
+ }).length,
15573
15641
  createdAt: record.createdAt,
15574
15642
  updatedAt: record.updatedAt,
15575
15643
  lastOpenedAt: record.lastOpenedAt,
@@ -15635,7 +15703,7 @@ async function getSubsystemModel(id) {
15635
15703
  }
15636
15704
  async function createSubsystemModel(doc) {
15637
15705
  await ensureDir();
15638
- normalizeDetailProvenance(doc.components);
15706
+ normalizeDeclarationProvenance(doc.components);
15639
15707
  const now = (/* @__PURE__ */ new Date()).toISOString();
15640
15708
  const record = {
15641
15709
  ...doc,
@@ -15779,8 +15847,8 @@ async function createAction(options) {
15779
15847
  title: body["title"],
15780
15848
  description: typeof body["description"] === "string" ? body["description"] : void 0,
15781
15849
  components: body["components"],
15782
- edges: body["edges"],
15783
- throughlines: Array.isArray(body["throughlines"]) ? body["throughlines"] : void 0,
15850
+ relations: body["relations"],
15851
+ walkthroughs: Array.isArray(body["walkthroughs"]) ? body["walkthroughs"] : void 0,
15784
15852
  source: typeof body["source"] === "string" ? body["source"] : void 0,
15785
15853
  repo: body["repo"],
15786
15854
  repoRoot: typeof body["repoRoot"] === "string" ? body["repoRoot"] : void 0,
@@ -15986,7 +16054,7 @@ function createSubsystemModelCommand() {
15986
16054
  }
15987
16055
 
15988
16056
  // src/index.ts
15989
- var VERSION = true ? "0.37.1" : "0.0.0-dev";
16057
+ var VERSION = true ? "0.39.0" : "0.0.0-dev";
15990
16058
  var program2 = new Command();
15991
16059
  program2.name("principal-ai").description(
15992
16060
  "Principal AI CLI \u2014 subsystem models, Subsystems Studio, trails, and agent sessions"