@principal-ai/principal-studio-cli 0.37.0 → 0.38.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.
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"}
@@ -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,
@@ -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
  }