@principal-ai/principal-view-cli 0.4.0 → 0.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/commands/formats.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAycpC,wBAAgB,oBAAoB,IAAI,OAAO,CA6B9C"}
1
+ {"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/commands/formats.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA+fpC,wBAAgB,oBAAoB,IAAI,OAAO,CA6B9C"}
@@ -48,13 +48,18 @@ ${chalk.dim('│')} ${chalk.yellow('"type"')}: "text",
48
48
  ${chalk.dim('│')} ${chalk.yellow('"text"')}: "# Event Name", ${chalk.dim('// Markdown description')} ${chalk.dim('│')}
49
49
  ${chalk.dim('│')} ${chalk.yellow('"x"')}: 0, ${chalk.yellow('"y"')}: 0, ${chalk.yellow('"width"')}: 200, ${chalk.yellow('"height"')}: 100, ${chalk.dim('│')}
50
50
  ${chalk.dim('│')} ${chalk.green('"pv"')}: { ${chalk.dim('│')}
51
- ${chalk.dim('│')} ${chalk.cyan('"otelEvent"')}: { ${chalk.dim('// OTEL event definition')} ${chalk.dim('│')}
52
- ${chalk.dim('│')} ${chalk.yellow('"name"')}: "feature.event.name", ${chalk.dim('│')}
53
- ${chalk.dim('│')} ${chalk.cyan('"attributes"')}: { ${chalk.dim('// Required & optional attrs')} ${chalk.dim('│')}
54
- ${chalk.dim('│')} ${chalk.green('"required"')}: ["attr.name", ...], ${chalk.dim('│')}
55
- ${chalk.dim('│')} ${chalk.green('"optional"')}: ["attr.name", ...] ${chalk.dim('│')}
56
- ${chalk.dim('│')} } ${chalk.dim('│')}
57
- ${chalk.dim('│')} } ${chalk.dim('│')}
51
+ ${chalk.dim('│')} ${chalk.cyan('"event"')}: "feature.event.name", ${chalk.dim('// Event name')} ${chalk.dim('│')}
52
+ ${chalk.dim('│')} ${chalk.cyan('"sources"')}: ["src/file.ts"], ${chalk.dim('// Source files')} ${chalk.dim('│')}
53
+ ${chalk.dim('│')} ${chalk.cyan('"otel"')}: { ${chalk.dim('// OTEL metadata')} ${chalk.dim('│')}
54
+ ${chalk.dim('│')} ${chalk.yellow('"kind"')}: "event", ${chalk.dim('│')}
55
+ ${chalk.dim('│')} ${chalk.yellow('"category"')}: "lifecycle" ${chalk.dim('│')}
56
+ ${chalk.dim('│')} }, ${chalk.dim('│')}
57
+ ${chalk.dim('│')} ${chalk.cyan('"dataSchema"')}: { ${chalk.dim('// Attribute definitions')} ${chalk.dim('│')}
58
+ ${chalk.dim('│')} ${chalk.yellow('"attr.name"')}: { ${chalk.dim('│')}
59
+ ${chalk.dim('│')} ${chalk.green('"type"')}: "string", ${chalk.dim('│')}
60
+ ${chalk.dim('│')} ${chalk.green('"required"')}: true ${chalk.dim('│')}
61
+ ${chalk.dim('│')} } ${chalk.dim('│')}
62
+ ${chalk.dim('│')} } ${chalk.dim('│')}
58
63
  ${chalk.dim('│')} } ${chalk.dim('│')}
59
64
  ${chalk.dim('│')} } ${chalk.dim('│')}
60
65
  ${chalk.dim('│')} ], ${chalk.dim('│')}
@@ -161,12 +166,26 @@ ${chalk.cyan('2. Standard scenario set:')}
161
166
  - ${chalk.yellow('Failure')} (priority 2): Feature encountered error
162
167
  - ${chalk.dim('Fallback')} (priority 999): Generic execution captured
163
168
 
164
- ${chalk.cyan('3. Template interpolation:')}
165
- Use {{path.to.value}} to reference event attributes
166
- Examples:
167
- - {{record.count}}
168
- - {{error.message}}
169
- - {{result.invalidCount}}
169
+ ${chalk.cyan('3. Template syntax (Handlebars):')}
170
+ Templates use Handlebars syntax for dynamic content:
171
+
172
+ ${chalk.bold('Variables:')}
173
+ - {{variable}} Simple variable
174
+ - {{result.count}} Nested property
175
+ - {{error.message}} Deeply nested
176
+
177
+ ${chalk.bold('Conditionals:')}
178
+ - {{#if condition}}...{{/if}} If block
179
+ - {{#if condition}}...{{else}}...{{/if}} If-else
180
+ - {{#if (eq status "ok")}}✅{{else}}❌{{/if}} Comparison
181
+
182
+ ${chalk.bold('Loops:')}
183
+ - {{#each items}}{{this}}{{/each}} Iterate array
184
+ - {{#each items}}{{@index}}: {{this}}{{/each}} With index
185
+
186
+ ${chalk.bold('Comparison helpers:')}
187
+ - eq, ne, lt, gt, lte, gte, and, or, not
188
+ - Example: {{#if (gt count 10)}}Many{{/if}}
170
189
 
171
190
  ${chalk.cyan('4. Template style:')}
172
191
  - Clear, concise summary line
@@ -292,11 +311,20 @@ ${chalk.yellow('.principal-views/data-validator.otel.canvas')}
292
311
  "text": "# validation.started\\n\\nEmitted when validation begins",
293
312
  "x": 0, "y": 0, "width": 200, "height": 100,
294
313
  "pv": {
295
- "otelEvent": {
296
- "name": "validation.started",
297
- "attributes": {
298
- "required": ["input.recordCount"],
299
- "optional": ["input.source"]
314
+ "event": "validation.started",
315
+ "sources": ["src/validator.ts"],
316
+ "otel": {
317
+ "kind": "event",
318
+ "category": "lifecycle"
319
+ },
320
+ "dataSchema": {
321
+ "input.recordCount": {
322
+ "type": "number",
323
+ "required": true
324
+ },
325
+ "input.source": {
326
+ "type": "string",
327
+ "required": false
300
328
  }
301
329
  }
302
330
  }
@@ -307,11 +335,24 @@ ${chalk.yellow('.principal-views/data-validator.otel.canvas')}
307
335
  "text": "# validation.complete\\n\\nEmitted when validation succeeds",
308
336
  "x": 250, "y": 0, "width": 200, "height": 100,
309
337
  "pv": {
310
- "otelEvent": {
311
- "name": "validation.complete",
312
- "attributes": {
313
- "required": ["result.validCount", "result.invalidCount"],
314
- "optional": ["duration.ms"]
338
+ "event": "validation.complete",
339
+ "sources": ["src/validator.ts"],
340
+ "otel": {
341
+ "kind": "event",
342
+ "category": "lifecycle"
343
+ },
344
+ "dataSchema": {
345
+ "result.validCount": {
346
+ "type": "number",
347
+ "required": true
348
+ },
349
+ "result.invalidCount": {
350
+ "type": "number",
351
+ "required": true
352
+ },
353
+ "duration.ms": {
354
+ "type": "number",
355
+ "required": false
315
356
  }
316
357
  }
317
358
  }
@@ -322,11 +363,24 @@ ${chalk.yellow('.principal-views/data-validator.otel.canvas')}
322
363
  "text": "# validation.error\\n\\nEmitted when validation fails",
323
364
  "x": 500, "y": 0, "width": 200, "height": 100,
324
365
  "pv": {
325
- "otelEvent": {
326
- "name": "validation.error",
327
- "attributes": {
328
- "required": ["error.type", "error.message"],
329
- "optional": ["error.stage"]
366
+ "event": "validation.error",
367
+ "sources": ["src/validator.ts"],
368
+ "otel": {
369
+ "kind": "event",
370
+ "category": "error"
371
+ },
372
+ "dataSchema": {
373
+ "error.type": {
374
+ "type": "string",
375
+ "required": true
376
+ },
377
+ "error.message": {
378
+ "type": "string",
379
+ "required": true
380
+ },
381
+ "error.stage": {
382
+ "type": "string",
383
+ "required": false
330
384
  }
331
385
  }
332
386
  }
package/dist/index.cjs CHANGED
@@ -241190,19 +241190,6 @@ function getNestedValue(obj, path4) {
241190
241190
  }
241191
241191
  return current;
241192
241192
  }
241193
- function setNestedValue(obj, path4, value) {
241194
- const keys = path4.split(".");
241195
- let current = obj;
241196
- for (let i = 0; i < keys.length - 1; i++) {
241197
- const key = keys[i];
241198
- if (current[key] === void 0 || typeof current[key] !== "object") {
241199
- current[key] = {};
241200
- }
241201
- current = current[key];
241202
- }
241203
- const lastKey = keys[keys.length - 1];
241204
- current[lastKey] = value;
241205
- }
241206
241193
  function computeAggregates(events) {
241207
241194
  const aggregates = {
241208
241195
  // Event counts
@@ -241216,15 +241203,12 @@ function computeAggregates(events) {
241216
241203
  "warnLogs.count": events.filter((e) => e.type === "log" && (e.severityNumber ?? 0) >= 13 && (e.severityNumber ?? 0) <= 16).length,
241217
241204
  "debugLogs.count": events.filter((e) => e.type === "log" && (e.severityNumber ?? 0) >= 5 && (e.severityNumber ?? 0) <= 8).length
241218
241205
  };
241219
- for (const event of events) {
241206
+ const summaryEventPatterns = [".complete", ".summary", ".error", ".started"];
241207
+ const summaryEvents = events.filter((e) => summaryEventPatterns.some((pattern) => e.name.endsWith(pattern)));
241208
+ for (const event of summaryEvents) {
241220
241209
  if (event.attributes) {
241221
241210
  for (const [key, value] of Object.entries(event.attributes)) {
241222
- if (getNestedValue(aggregates, key) === void 0) {
241223
- setNestedValue(aggregates, key, value);
241224
- if (key.includes(".")) {
241225
- aggregates[key] = value;
241226
- }
241227
- }
241211
+ aggregates[key] = value;
241228
241212
  }
241229
241213
  }
241230
241214
  }
@@ -241334,7 +241318,25 @@ function renderSpanTree(tree, scenario, context, formatting2) {
241334
241318
  const parts = [];
241335
241319
  for (const node of tree) {
241336
241320
  const indent = (formatting2.indentPerLevel || " ").repeat(node.depth);
241337
- const eventContext = { ...context, ...node.span.attributes, span: node.span };
241321
+ const eventContext = { ...context };
241322
+ if (node.span.attributes) {
241323
+ for (const [key, value] of Object.entries(node.span.attributes)) {
241324
+ if (key.includes(".")) {
241325
+ const parts2 = key.split(".");
241326
+ let current = eventContext;
241327
+ for (let i = 0; i < parts2.length - 1; i++) {
241328
+ if (!current[parts2[i]] || typeof current[parts2[i]] !== "object") {
241329
+ current[parts2[i]] = {};
241330
+ }
241331
+ current = current[parts2[i]];
241332
+ }
241333
+ current[parts2[parts2.length - 1]] = value;
241334
+ } else {
241335
+ eventContext[key] = value;
241336
+ }
241337
+ }
241338
+ }
241339
+ eventContext.span = node.span;
241338
241340
  if (scenario.template.span) {
241339
241341
  const spanText = parseTemplate(scenario.template.span, eventContext);
241340
241342
  parts.push(indent + spanText);
@@ -241368,7 +241370,24 @@ function renderTimeline(events, scenario, context, formatting2) {
241368
241370
  return aTime - bTime;
241369
241371
  });
241370
241372
  for (const event of sorted) {
241371
- const eventContext = { ...context, ...event.attributes };
241373
+ const eventContext = { ...context };
241374
+ if (event.attributes) {
241375
+ for (const [key, value] of Object.entries(event.attributes)) {
241376
+ if (key.includes(".")) {
241377
+ const parts2 = key.split(".");
241378
+ let current = eventContext;
241379
+ for (let i = 0; i < parts2.length - 1; i++) {
241380
+ if (!current[parts2[i]] || typeof current[parts2[i]] !== "object") {
241381
+ current[parts2[i]] = {};
241382
+ }
241383
+ current = current[parts2[i]];
241384
+ }
241385
+ current[parts2[parts2.length - 1]] = value;
241386
+ } else {
241387
+ eventContext[key] = value;
241388
+ }
241389
+ }
241390
+ }
241372
241391
  let eventText;
241373
241392
  if (event.type === "log") {
241374
241393
  eventText = renderLog(event, scenario, { ...eventContext, log: event }, formatting2);
@@ -241688,8 +241707,8 @@ var NarrativeValidator = class {
241688
241707
  }
241689
241708
  const canvasEvents = /* @__PURE__ */ new Set();
241690
241709
  for (const node of canvas.nodes) {
241691
- if (node.pv?.event?.name) {
241692
- canvasEvents.add(node.pv.event.name);
241710
+ if (node.pv?.event && typeof node.pv.event === "string") {
241711
+ canvasEvents.add(node.pv.event);
241693
241712
  }
241694
241713
  }
241695
241714
  const narrativeEvents = /* @__PURE__ */ new Set();
@@ -241703,7 +241722,9 @@ var NarrativeValidator = class {
241703
241722
  }
241704
241723
  if (scenario.template?.events) {
241705
241724
  for (const eventName of Object.keys(scenario.template.events)) {
241706
- narrativeEvents.add(eventName);
241725
+ if (!eventName.includes("*")) {
241726
+ narrativeEvents.add(eventName);
241727
+ }
241707
241728
  }
241708
241729
  }
241709
241730
  }
@@ -242119,7 +242140,7 @@ var NarrativeValidator = class {
242119
242140
  path: path4,
242120
242141
  message: `Incomplete conditional expression: ${expr}`,
242121
242142
  impact: "Template will fail to render",
242122
- suggestion: 'Conditional format: {condition ? "true" : "false"}',
242143
+ suggestion: "Use Handlebars syntax: {{#if condition}}true{{else}}false{{/if}}",
242123
242144
  fixable: false
242124
242145
  });
242125
242146
  }
@@ -247618,13 +247639,18 @@ ${source_default.dim("\u2502")} ${source_default.yellow('"type"')}: "text"
247618
247639
  ${source_default.dim("\u2502")} ${source_default.yellow('"text"')}: "# Event Name", ${source_default.dim("// Markdown description")} ${source_default.dim("\u2502")}
247619
247640
  ${source_default.dim("\u2502")} ${source_default.yellow('"x"')}: 0, ${source_default.yellow('"y"')}: 0, ${source_default.yellow('"width"')}: 200, ${source_default.yellow('"height"')}: 100, ${source_default.dim("\u2502")}
247620
247641
  ${source_default.dim("\u2502")} ${source_default.green('"pv"')}: { ${source_default.dim("\u2502")}
247621
- ${source_default.dim("\u2502")} ${source_default.cyan('"otelEvent"')}: { ${source_default.dim("// OTEL event definition")} ${source_default.dim("\u2502")}
247622
- ${source_default.dim("\u2502")} ${source_default.yellow('"name"')}: "feature.event.name", ${source_default.dim("\u2502")}
247623
- ${source_default.dim("\u2502")} ${source_default.cyan('"attributes"')}: { ${source_default.dim("// Required & optional attrs")} ${source_default.dim("\u2502")}
247624
- ${source_default.dim("\u2502")} ${source_default.green('"required"')}: ["attr.name", ...], ${source_default.dim("\u2502")}
247625
- ${source_default.dim("\u2502")} ${source_default.green('"optional"')}: ["attr.name", ...] ${source_default.dim("\u2502")}
247626
- ${source_default.dim("\u2502")} } ${source_default.dim("\u2502")}
247627
- ${source_default.dim("\u2502")} } ${source_default.dim("\u2502")}
247642
+ ${source_default.dim("\u2502")} ${source_default.cyan('"event"')}: "feature.event.name", ${source_default.dim("// Event name")} ${source_default.dim("\u2502")}
247643
+ ${source_default.dim("\u2502")} ${source_default.cyan('"sources"')}: ["src/file.ts"], ${source_default.dim("// Source files")} ${source_default.dim("\u2502")}
247644
+ ${source_default.dim("\u2502")} ${source_default.cyan('"otel"')}: { ${source_default.dim("// OTEL metadata")} ${source_default.dim("\u2502")}
247645
+ ${source_default.dim("\u2502")} ${source_default.yellow('"kind"')}: "event", ${source_default.dim("\u2502")}
247646
+ ${source_default.dim("\u2502")} ${source_default.yellow('"category"')}: "lifecycle" ${source_default.dim("\u2502")}
247647
+ ${source_default.dim("\u2502")} }, ${source_default.dim("\u2502")}
247648
+ ${source_default.dim("\u2502")} ${source_default.cyan('"dataSchema"')}: { ${source_default.dim("// Attribute definitions")} ${source_default.dim("\u2502")}
247649
+ ${source_default.dim("\u2502")} ${source_default.yellow('"attr.name"')}: { ${source_default.dim("\u2502")}
247650
+ ${source_default.dim("\u2502")} ${source_default.green('"type"')}: "string", ${source_default.dim("\u2502")}
247651
+ ${source_default.dim("\u2502")} ${source_default.green('"required"')}: true ${source_default.dim("\u2502")}
247652
+ ${source_default.dim("\u2502")} } ${source_default.dim("\u2502")}
247653
+ ${source_default.dim("\u2502")} } ${source_default.dim("\u2502")}
247628
247654
  ${source_default.dim("\u2502")} } ${source_default.dim("\u2502")}
247629
247655
  ${source_default.dim("\u2502")} } ${source_default.dim("\u2502")}
247630
247656
  ${source_default.dim("\u2502")} ], ${source_default.dim("\u2502")}
@@ -247731,12 +247757,26 @@ ${source_default.cyan("2. Standard scenario set:")}
247731
247757
  - ${source_default.yellow("Failure")} (priority 2): Feature encountered error
247732
247758
  - ${source_default.dim("Fallback")} (priority 999): Generic execution captured
247733
247759
 
247734
- ${source_default.cyan("3. Template interpolation:")}
247735
- Use {{path.to.value}} to reference event attributes
247736
- Examples:
247737
- - {{record.count}}
247738
- - {{error.message}}
247739
- - {{result.invalidCount}}
247760
+ ${source_default.cyan("3. Template syntax (Handlebars):")}
247761
+ Templates use Handlebars syntax for dynamic content:
247762
+
247763
+ ${source_default.bold("Variables:")}
247764
+ - {{variable}} Simple variable
247765
+ - {{result.count}} Nested property
247766
+ - {{error.message}} Deeply nested
247767
+
247768
+ ${source_default.bold("Conditionals:")}
247769
+ - {{#if condition}}...{{/if}} If block
247770
+ - {{#if condition}}...{{else}}...{{/if}} If-else
247771
+ - {{#if (eq status "ok")}}\u2705{{else}}\u274C{{/if}} Comparison
247772
+
247773
+ ${source_default.bold("Loops:")}
247774
+ - {{#each items}}{{this}}{{/each}} Iterate array
247775
+ - {{#each items}}{{@index}}: {{this}}{{/each}} With index
247776
+
247777
+ ${source_default.bold("Comparison helpers:")}
247778
+ - eq, ne, lt, gt, lte, gte, and, or, not
247779
+ - Example: {{#if (gt count 10)}}Many{{/if}}
247740
247780
 
247741
247781
  ${source_default.cyan("4. Template style:")}
247742
247782
  - Clear, concise summary line
@@ -247862,11 +247902,20 @@ ${source_default.yellow(".principal-views/data-validator.otel.canvas")}
247862
247902
  "text": "# validation.started\\n\\nEmitted when validation begins",
247863
247903
  "x": 0, "y": 0, "width": 200, "height": 100,
247864
247904
  "pv": {
247865
- "otelEvent": {
247866
- "name": "validation.started",
247867
- "attributes": {
247868
- "required": ["input.recordCount"],
247869
- "optional": ["input.source"]
247905
+ "event": "validation.started",
247906
+ "sources": ["src/validator.ts"],
247907
+ "otel": {
247908
+ "kind": "event",
247909
+ "category": "lifecycle"
247910
+ },
247911
+ "dataSchema": {
247912
+ "input.recordCount": {
247913
+ "type": "number",
247914
+ "required": true
247915
+ },
247916
+ "input.source": {
247917
+ "type": "string",
247918
+ "required": false
247870
247919
  }
247871
247920
  }
247872
247921
  }
@@ -247877,11 +247926,24 @@ ${source_default.yellow(".principal-views/data-validator.otel.canvas")}
247877
247926
  "text": "# validation.complete\\n\\nEmitted when validation succeeds",
247878
247927
  "x": 250, "y": 0, "width": 200, "height": 100,
247879
247928
  "pv": {
247880
- "otelEvent": {
247881
- "name": "validation.complete",
247882
- "attributes": {
247883
- "required": ["result.validCount", "result.invalidCount"],
247884
- "optional": ["duration.ms"]
247929
+ "event": "validation.complete",
247930
+ "sources": ["src/validator.ts"],
247931
+ "otel": {
247932
+ "kind": "event",
247933
+ "category": "lifecycle"
247934
+ },
247935
+ "dataSchema": {
247936
+ "result.validCount": {
247937
+ "type": "number",
247938
+ "required": true
247939
+ },
247940
+ "result.invalidCount": {
247941
+ "type": "number",
247942
+ "required": true
247943
+ },
247944
+ "duration.ms": {
247945
+ "type": "number",
247946
+ "required": false
247885
247947
  }
247886
247948
  }
247887
247949
  }
@@ -247892,11 +247954,24 @@ ${source_default.yellow(".principal-views/data-validator.otel.canvas")}
247892
247954
  "text": "# validation.error\\n\\nEmitted when validation fails",
247893
247955
  "x": 500, "y": 0, "width": 200, "height": 100,
247894
247956
  "pv": {
247895
- "otelEvent": {
247896
- "name": "validation.error",
247897
- "attributes": {
247898
- "required": ["error.type", "error.message"],
247899
- "optional": ["error.stage"]
247957
+ "event": "validation.error",
247958
+ "sources": ["src/validator.ts"],
247959
+ "otel": {
247960
+ "kind": "event",
247961
+ "category": "error"
247962
+ },
247963
+ "dataSchema": {
247964
+ "error.type": {
247965
+ "type": "string",
247966
+ "required": true
247967
+ },
247968
+ "error.message": {
247969
+ "type": "string",
247970
+ "required": true
247971
+ },
247972
+ "error.stage": {
247973
+ "type": "string",
247974
+ "required": false
247900
247975
  }
247901
247976
  }
247902
247977
  }