@principal-ai/principal-studio-cli 0.37.0 → 0.37.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/README.md CHANGED
@@ -20,7 +20,7 @@ Bin name: `principal-ai`.
20
20
 
21
21
  | Command | Purpose |
22
22
  |---|---|
23
- | `subsystem-model` | Create / open / list / get subsystem models |
23
+ | `subsystem-model` | Create / open / list / get / audit / propose / accept / reject |
24
24
  | `open-studio` | Launch or focus Subsystems Studio |
25
25
  | `trail` | File City trails |
26
26
  | `tour` | Introduction tours |
@@ -1 +1 @@
1
- {"version":3,"file":"subsystem-model.d.ts","sourceRoot":"","sources":["../../src/commands/subsystem-model.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4QpC,wBAAgB,2BAA2B,IAAI,OAAO,CAwCrD"}
1
+ {"version":3,"file":"subsystem-model.d.ts","sourceRoot":"","sources":["../../src/commands/subsystem-model.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqXpC,wBAAgB,2BAA2B,IAAI,OAAO,CAsFrD"}
@@ -221,8 +221,85 @@ async function getAction(id) {
221
221
  }
222
222
  process.stdout.write(JSON.stringify({ ok: true, graph }, null, 2) + '\n');
223
223
  }
224
+ async function studioFetch(path, init) {
225
+ if (!(await studioHttpUp())) {
226
+ process.stderr.write('Principal Studio HTTP is not running (need audit / propose apply via Studio on :3045).\n');
227
+ process.exit(2);
228
+ }
229
+ try {
230
+ const res = await fetch(`${studioHttpBase()}${path}`, {
231
+ ...init,
232
+ signal: AbortSignal.timeout(120_000),
233
+ headers: {
234
+ 'Content-Type': 'application/json',
235
+ ...(init?.headers ?? {}),
236
+ },
237
+ });
238
+ const json = (await res.json());
239
+ return { ok: res.ok && json.ok !== false, status: res.status, json };
240
+ }
241
+ catch (err) {
242
+ process.stderr.write(`Studio request failed: ${err.message}\n`);
243
+ process.exit(2);
244
+ }
245
+ }
246
+ async function auditAction(id) {
247
+ if (!id) {
248
+ process.stderr.write('Pass a model id.\n');
249
+ process.exit(2);
250
+ }
251
+ const { ok, json } = await studioFetch(`/api/subsystem-model/${encodeURIComponent(id)}/audit`);
252
+ process.stdout.write(JSON.stringify(json, null, 2) + '\n');
253
+ if (!ok)
254
+ process.exit(2);
255
+ }
256
+ async function proposalsListAction(id, opts) {
257
+ if (!id) {
258
+ process.stderr.write('Pass a model id.\n');
259
+ process.exit(2);
260
+ }
261
+ const q = opts.includeResolved ? '?includeResolved=1' : '';
262
+ const { ok, json } = await studioFetch(`/api/subsystem-model/${encodeURIComponent(id)}/proposals${q}`);
263
+ process.stdout.write(JSON.stringify(json, null, 2) + '\n');
264
+ if (!ok)
265
+ process.exit(2);
266
+ }
267
+ async function proposeAction(id, opts) {
268
+ if (!id) {
269
+ process.stderr.write('Pass a model id.\n');
270
+ process.exit(2);
271
+ }
272
+ const payload = (await readPayload(opts.file));
273
+ if (opts.author && typeof payload['author'] !== 'string') {
274
+ payload['author'] = opts.author;
275
+ }
276
+ const { ok, json } = await studioFetch(`/api/subsystem-model/${encodeURIComponent(id)}/proposals`, { method: 'POST', body: JSON.stringify(payload) });
277
+ process.stdout.write(JSON.stringify(json, null, 2) + '\n');
278
+ if (!ok)
279
+ process.exit(2);
280
+ }
281
+ async function acceptAction(id, proposalId) {
282
+ if (!id || !proposalId) {
283
+ process.stderr.write('Pass a model id and proposal id.\n');
284
+ process.exit(2);
285
+ }
286
+ const { ok, json } = await studioFetch(`/api/subsystem-model/${encodeURIComponent(id)}/proposals/${encodeURIComponent(proposalId)}/accept`, { method: 'POST', body: '{}' });
287
+ process.stdout.write(JSON.stringify(json, null, 2) + '\n');
288
+ if (!ok)
289
+ process.exit(2);
290
+ }
291
+ async function rejectAction(id, proposalId) {
292
+ if (!id || !proposalId) {
293
+ process.stderr.write('Pass a model id and proposal id.\n');
294
+ process.exit(2);
295
+ }
296
+ const { ok, json } = await studioFetch(`/api/subsystem-model/${encodeURIComponent(id)}/proposals/${encodeURIComponent(proposalId)}/reject`, { method: 'POST', body: '{}' });
297
+ process.stdout.write(JSON.stringify(json, null, 2) + '\n');
298
+ if (!ok)
299
+ process.exit(2);
300
+ }
224
301
  export function createSubsystemModelCommand() {
225
- const cmd = new Command('subsystem-model').description('Create, open, and list subsystem models (works without Studio already running)');
302
+ const cmd = new Command('subsystem-model').description('Create, open, audit, and propose corrections for subsystem models');
226
303
  cmd
227
304
  .command('create')
228
305
  .description('Validate + persist a subsystem model JSON, then open it in Principal Studio')
@@ -245,5 +322,35 @@ export function createSubsystemModelCommand() {
245
322
  .description('Print a stored subsystem model as JSON')
246
323
  .argument('[id]', 'Model id (sg-…)')
247
324
  .action(getAction);
325
+ cmd
326
+ .command('audit')
327
+ .description('Run the deterministic dry-run audit (requires Principal Studio HTTP)')
328
+ .argument('<id>', 'Model id (sg-…)')
329
+ .action(auditAction);
330
+ cmd
331
+ .command('proposals')
332
+ .description('List correction proposals for a model (requires Studio HTTP)')
333
+ .argument('<id>', 'Model id (sg-…)')
334
+ .option('--include-resolved', 'Include accepted/rejected proposals')
335
+ .action((id, opts) => proposalsListAction(id, opts));
336
+ cmd
337
+ .command('propose')
338
+ .description('Submit a correction proposal with rationale (does not apply unless auto-accept is on)')
339
+ .argument('<id>', 'Model id (sg-…)')
340
+ .option('-f, --file <path>', 'Proposal JSON: { rationale, changes[], finding?, author? } (default: stdin)')
341
+ .option('--author <name>', 'Author tag (e.g. agent name)')
342
+ .action((id, opts) => proposeAction(id, opts));
343
+ cmd
344
+ .command('accept')
345
+ .description('Accept a pending proposal and apply it to the model')
346
+ .argument('<id>', 'Model id (sg-…)')
347
+ .argument('<proposalId>', 'Proposal id (sp-…)')
348
+ .action(acceptAction);
349
+ cmd
350
+ .command('reject')
351
+ .description('Reject a pending proposal without changing the model')
352
+ .argument('<id>', 'Model id (sg-…)')
353
+ .argument('<proposalId>', 'Proposal id (sp-…)')
354
+ .action(rejectAction);
248
355
  return cmd;
249
356
  }
package/dist/index.cjs CHANGED
@@ -3457,7 +3457,7 @@ 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.isSubsystemModelDocument = void 0;
3460
+ exports2.toPortableDocument = exports2.isSubsystemModelDocument = void 0;
3461
3461
  function isSubsystemModelDocument(value) {
3462
3462
  if (!value || typeof value !== "object")
3463
3463
  return false;
@@ -3465,6 +3465,46 @@ var require_subsystem_model = __commonJS({
3465
3465
  return typeof v.title === "string" && Array.isArray(v.components) && Array.isArray(v.edges);
3466
3466
  }
3467
3467
  exports2.isSubsystemModelDocument = isSubsystemModelDocument;
3468
+ function toPortableDocument(doc) {
3469
+ const out = {
3470
+ title: doc.title,
3471
+ components: doc.components,
3472
+ edges: doc.edges
3473
+ };
3474
+ if (doc.$schema)
3475
+ out.$schema = doc.$schema;
3476
+ if (doc.description)
3477
+ out.description = doc.description;
3478
+ if (doc.throughlines)
3479
+ out.throughlines = doc.throughlines;
3480
+ return out;
3481
+ }
3482
+ exports2.toPortableDocument = toPortableDocument;
3483
+ }
3484
+ });
3485
+
3486
+ // node_modules/@principal-ai/subsystems-core/dist/types/index.js
3487
+ var require_types = __commonJS({
3488
+ "node_modules/@principal-ai/subsystems-core/dist/types/index.js"(exports2) {
3489
+ "use strict";
3490
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
3491
+ if (k2 === void 0) k2 = k;
3492
+ var desc = Object.getOwnPropertyDescriptor(m, k);
3493
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
3494
+ desc = { enumerable: true, get: function() {
3495
+ return m[k];
3496
+ } };
3497
+ }
3498
+ Object.defineProperty(o, k2, desc);
3499
+ } : function(o, m, k, k2) {
3500
+ if (k2 === void 0) k2 = k;
3501
+ o[k2] = m[k];
3502
+ });
3503
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
3504
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
3505
+ };
3506
+ Object.defineProperty(exports2, "__esModule", { value: true });
3507
+ __exportStar(require_subsystem_model(), exports2);
3468
3508
  }
3469
3509
  });
3470
3510
 
@@ -9671,12 +9711,25 @@ var require_fixture = __commonJS({
9671
9711
  var require_node = __commonJS({
9672
9712
  "node_modules/@principal-ai/subsystems-core/dist/node.js"(exports2) {
9673
9713
  "use strict";
9714
+ var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
9715
+ if (k2 === void 0) k2 = k;
9716
+ var desc = Object.getOwnPropertyDescriptor(m, k);
9717
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9718
+ desc = { enumerable: true, get: function() {
9719
+ return m[k];
9720
+ } };
9721
+ }
9722
+ Object.defineProperty(o, k2, desc);
9723
+ } : function(o, m, k, k2) {
9724
+ if (k2 === void 0) k2 = k;
9725
+ o[k2] = m[k];
9726
+ });
9727
+ var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
9728
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
9729
+ };
9674
9730
  Object.defineProperty(exports2, "__esModule", { value: true });
9675
- exports2.opencodeRowsToUniversalEvents = exports2.collectRepositories = exports2.accumulateEvents = exports2.normalizeEventsWithAdapter = exports2.normalizeEvents = exports2.NodePathNormalizationAdapter = exports2.buildAgentSessionFixture = exports2.fetchRawEvents = exports2.detectAgent = exports2.listAgentSessions = exports2.defaultOpenCodeDBPath = exports2.OpenCodeEventStore = exports2.publishedFromDraft = exports2.LEGACY_TOPICS_BLOB = exports2.TOPICS_DIR = exports2.PRINCIPAL_DIR = exports2.TopicStore = exports2.isSubsystemModelDocument = void 0;
9676
- var subsystem_model_1 = require_subsystem_model();
9677
- Object.defineProperty(exports2, "isSubsystemModelDocument", { enumerable: true, get: function() {
9678
- return subsystem_model_1.isSubsystemModelDocument;
9679
- } });
9731
+ exports2.opencodeRowsToUniversalEvents = exports2.collectRepositories = exports2.accumulateEvents = exports2.normalizeEventsWithAdapter = exports2.normalizeEvents = exports2.NodePathNormalizationAdapter = exports2.buildAgentSessionFixture = exports2.fetchRawEvents = exports2.detectAgent = exports2.listAgentSessions = exports2.defaultOpenCodeDBPath = exports2.OpenCodeEventStore = exports2.publishedFromDraft = exports2.LEGACY_TOPICS_BLOB = exports2.TOPICS_DIR = exports2.PRINCIPAL_DIR = exports2.TopicStore = void 0;
9732
+ __exportStar(require_types(), exports2);
9680
9733
  var topicStore_1 = require_topicStore();
9681
9734
  Object.defineProperty(exports2, "TopicStore", { enumerable: true, get: function() {
9682
9735
  return topicStore_1.TopicStore;
@@ -15357,7 +15410,8 @@ var SUBSYSTEM_COMPONENT_CONSTRUCTS = [
15357
15410
  "type_alias",
15358
15411
  "enum",
15359
15412
  "store",
15360
- "external"
15413
+ "external",
15414
+ "custom_entity"
15361
15415
  ];
15362
15416
  var SUBSYSTEM_DETAIL_PROVENANCES = ["verified", "authored"];
15363
15417
  function graphId() {
@@ -15478,7 +15532,8 @@ function normalizeDetailProvenance(components) {
15478
15532
  method: ["parameters"],
15479
15533
  class: ["methods", "properties", "extends", "implements", "instantiations", "references"],
15480
15534
  type: ["properties", "usedBy", "implementors"],
15481
- module: ["imports", "exports", "symbols"]
15535
+ module: ["imports", "exports", "symbols"],
15536
+ custom_entity: ["attributes"]
15482
15537
  };
15483
15538
  for (const key of arrays[String(kind)] ?? []) {
15484
15539
  if (!Array.isArray(detail[key])) detail[key] = [];
@@ -15520,7 +15575,8 @@ function indexEntryFor(record) {
15520
15575
  lastOpenedAt: record.lastOpenedAt,
15521
15576
  fileName: `${record.id}.json`,
15522
15577
  source: record.source,
15523
- repo: record.repo
15578
+ repo: record.repo,
15579
+ gist: record.gist
15524
15580
  };
15525
15581
  }
15526
15582
  async function readIndex() {
@@ -15809,9 +15865,94 @@ async function getAction(id) {
15809
15865
  }
15810
15866
  process.stdout.write(JSON.stringify({ ok: true, graph }, null, 2) + "\n");
15811
15867
  }
15868
+ async function studioFetch(path, init) {
15869
+ if (!await studioHttpUp()) {
15870
+ process.stderr.write(
15871
+ "Principal Studio HTTP is not running (need audit / propose apply via Studio on :3045).\n"
15872
+ );
15873
+ process.exit(2);
15874
+ }
15875
+ try {
15876
+ const res = await fetch(`${studioHttpBase()}${path}`, {
15877
+ ...init,
15878
+ signal: AbortSignal.timeout(12e4),
15879
+ headers: {
15880
+ "Content-Type": "application/json",
15881
+ ...init?.headers ?? {}
15882
+ }
15883
+ });
15884
+ const json = await res.json();
15885
+ return { ok: res.ok && json.ok !== false, status: res.status, json };
15886
+ } catch (err) {
15887
+ process.stderr.write(`Studio request failed: ${err.message}
15888
+ `);
15889
+ process.exit(2);
15890
+ }
15891
+ }
15892
+ async function auditAction(id) {
15893
+ if (!id) {
15894
+ process.stderr.write("Pass a model id.\n");
15895
+ process.exit(2);
15896
+ }
15897
+ const { ok, json } = await studioFetch(`/api/subsystem-model/${encodeURIComponent(id)}/audit`);
15898
+ process.stdout.write(JSON.stringify(json, null, 2) + "\n");
15899
+ if (!ok) process.exit(2);
15900
+ }
15901
+ async function proposalsListAction(id, opts) {
15902
+ if (!id) {
15903
+ process.stderr.write("Pass a model id.\n");
15904
+ process.exit(2);
15905
+ }
15906
+ const q = opts.includeResolved ? "?includeResolved=1" : "";
15907
+ const { ok, json } = await studioFetch(
15908
+ `/api/subsystem-model/${encodeURIComponent(id)}/proposals${q}`
15909
+ );
15910
+ process.stdout.write(JSON.stringify(json, null, 2) + "\n");
15911
+ if (!ok) process.exit(2);
15912
+ }
15913
+ async function proposeAction(id, opts) {
15914
+ if (!id) {
15915
+ process.stderr.write("Pass a model id.\n");
15916
+ process.exit(2);
15917
+ }
15918
+ const payload = await readPayload2(opts.file);
15919
+ if (opts.author && typeof payload["author"] !== "string") {
15920
+ payload["author"] = opts.author;
15921
+ }
15922
+ const { ok, json } = await studioFetch(
15923
+ `/api/subsystem-model/${encodeURIComponent(id)}/proposals`,
15924
+ { method: "POST", body: JSON.stringify(payload) }
15925
+ );
15926
+ process.stdout.write(JSON.stringify(json, null, 2) + "\n");
15927
+ if (!ok) process.exit(2);
15928
+ }
15929
+ async function acceptAction(id, proposalId) {
15930
+ if (!id || !proposalId) {
15931
+ process.stderr.write("Pass a model id and proposal id.\n");
15932
+ process.exit(2);
15933
+ }
15934
+ const { ok, json } = await studioFetch(
15935
+ `/api/subsystem-model/${encodeURIComponent(id)}/proposals/${encodeURIComponent(proposalId)}/accept`,
15936
+ { method: "POST", body: "{}" }
15937
+ );
15938
+ process.stdout.write(JSON.stringify(json, null, 2) + "\n");
15939
+ if (!ok) process.exit(2);
15940
+ }
15941
+ async function rejectAction(id, proposalId) {
15942
+ if (!id || !proposalId) {
15943
+ process.stderr.write("Pass a model id and proposal id.\n");
15944
+ process.exit(2);
15945
+ }
15946
+ const { ok, json } = await studioFetch(
15947
+ `/api/subsystem-model/${encodeURIComponent(id)}/proposals/${encodeURIComponent(proposalId)}/reject`,
15948
+ { method: "POST", body: "{}" }
15949
+ );
15950
+ process.stdout.write(JSON.stringify(json, null, 2) + "\n");
15951
+ if (!ok) process.exit(2);
15952
+ }
15812
15953
  function createSubsystemModelCommand() {
15813
15954
  const cmd = new Command("subsystem-model").description(
15814
- "Create, open, and list subsystem models (works without Studio already running)"
15955
+ "Create, open, audit, and propose corrections for subsystem models"
15815
15956
  );
15816
15957
  cmd.command("create").description(
15817
15958
  "Validate + persist a subsystem model JSON, then open it in Principal Studio"
@@ -15825,11 +15966,27 @@ function createSubsystemModelCommand() {
15825
15966
  ).action(openAction);
15826
15967
  cmd.command("list").description("List stored subsystem models").action(listAction);
15827
15968
  cmd.command("get").description("Print a stored subsystem model as JSON").argument("[id]", "Model id (sg-\u2026)").action(getAction);
15969
+ cmd.command("audit").description(
15970
+ "Run the deterministic dry-run audit (requires Principal Studio HTTP)"
15971
+ ).argument("<id>", "Model id (sg-\u2026)").action(auditAction);
15972
+ cmd.command("proposals").description("List correction proposals for a model (requires Studio HTTP)").argument("<id>", "Model id (sg-\u2026)").option("--include-resolved", "Include accepted/rejected proposals").action(
15973
+ (id, opts) => proposalsListAction(id, opts)
15974
+ );
15975
+ cmd.command("propose").description(
15976
+ "Submit a correction proposal with rationale (does not apply unless auto-accept is on)"
15977
+ ).argument("<id>", "Model id (sg-\u2026)").option(
15978
+ "-f, --file <path>",
15979
+ "Proposal JSON: { rationale, changes[], finding?, author? } (default: stdin)"
15980
+ ).option("--author <name>", "Author tag (e.g. agent name)").action(
15981
+ (id, opts) => proposeAction(id, opts)
15982
+ );
15983
+ cmd.command("accept").description("Accept a pending proposal and apply it to the model").argument("<id>", "Model id (sg-\u2026)").argument("<proposalId>", "Proposal id (sp-\u2026)").action(acceptAction);
15984
+ cmd.command("reject").description("Reject a pending proposal without changing the model").argument("<id>", "Model id (sg-\u2026)").argument("<proposalId>", "Proposal id (sp-\u2026)").action(rejectAction);
15828
15985
  return cmd;
15829
15986
  }
15830
15987
 
15831
15988
  // src/index.ts
15832
- var VERSION = true ? "0.37.0" : "0.0.0-dev";
15989
+ var VERSION = true ? "0.37.1" : "0.0.0-dev";
15833
15990
  var program2 = new Command();
15834
15991
  program2.name("principal-ai").description(
15835
15992
  "Principal AI CLI \u2014 subsystem models, Subsystems Studio, trails, and agent sessions"