@prism-d1/cli 1.0.79 → 1.0.81

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.
Files changed (72) hide show
  1. package/dist/assets/github-workflows/prism-ai-metrics.yml +83 -122
  2. package/dist/assets/github-workflows/prism-eval-gate-kiro.yml +66 -0
  3. package/dist/assets/github-workflows/prism-eval-gate.yml +1 -1
  4. package/dist/assets/gitlab-workflows/.gitlab-ci.yml +0 -3
  5. package/dist/assets/gitlab-workflows/prism-ai-metrics.yml +53 -56
  6. package/dist/assets/infra/bin/app.ts +1 -0
  7. package/dist/assets/infra/lib/constructs/otel-collector-construct.ts +4 -0
  8. package/dist/assets/infra/lib/dashboard-stack.ts +378 -1235
  9. package/dist/assets/infra/lib/lambda/event-schema.ts +144 -0
  10. package/dist/assets/infra/lib/lambda/metrics-processor.ts +124 -36
  11. package/dist/assets/infra/lib/lambda/otel-receiver.ts +249 -35
  12. package/dist/assets/infra/lib/lambda/security-remediation-tracker.ts +17 -2
  13. package/dist/assets/infra/lib/lambda/velocity-widget.ts +1483 -0
  14. package/dist/assets/infra/lib/metrics-pipeline-stack.ts +111 -119
  15. package/dist/assets/infra/package.json +2 -1
  16. package/dist/assets/infra/tsconfig.json +9 -2
  17. package/dist/src/commands/assessment/web.d.ts.map +1 -1
  18. package/dist/src/commands/assessment/web.js +25 -2
  19. package/dist/src/commands/assessment/web.js.map +1 -1
  20. package/dist/src/commands/bootstrapper/install-eval-harness.d.ts +8 -2
  21. package/dist/src/commands/bootstrapper/install-eval-harness.d.ts.map +1 -1
  22. package/dist/src/commands/bootstrapper/install-eval-harness.js +46 -36
  23. package/dist/src/commands/bootstrapper/install-eval-harness.js.map +1 -1
  24. package/dist/src/commands/bootstrapper/install-git-hooks.d.ts.map +1 -1
  25. package/dist/src/commands/bootstrapper/install-git-hooks.js +10 -14
  26. package/dist/src/commands/bootstrapper/install-git-hooks.js.map +1 -1
  27. package/dist/src/commands/bootstrapper/install-github-workflows.d.ts.map +1 -1
  28. package/dist/src/commands/bootstrapper/install-github-workflows.js +7 -2
  29. package/dist/src/commands/bootstrapper/install-github-workflows.js.map +1 -1
  30. package/dist/src/commands/bootstrapper/install-gitlab-workflows.d.ts.map +1 -1
  31. package/dist/src/commands/bootstrapper/install-gitlab-workflows.js +7 -1
  32. package/dist/src/commands/bootstrapper/install-gitlab-workflows.js.map +1 -1
  33. package/dist/src/commands/bootstrapper/setup-github-oidc.d.ts.map +1 -1
  34. package/dist/src/commands/bootstrapper/setup-github-oidc.js +50 -27
  35. package/dist/src/commands/bootstrapper/setup-github-oidc.js.map +1 -1
  36. package/dist/src/commands/bootstrapper/setup-gitlab-oidc.d.ts.map +1 -1
  37. package/dist/src/commands/bootstrapper/setup-gitlab-oidc.js +69 -25
  38. package/dist/src/commands/bootstrapper/setup-gitlab-oidc.js.map +1 -1
  39. package/dist/src/commands/bootstrapper/setup-otel-sync.d.ts.map +1 -1
  40. package/dist/src/commands/bootstrapper/setup-otel-sync.js +145 -53
  41. package/dist/src/commands/bootstrapper/setup-otel-sync.js.map +1 -1
  42. package/dist/src/commands/workshop/generate-demo-data.d.ts +41 -2
  43. package/dist/src/commands/workshop/generate-demo-data.d.ts.map +1 -1
  44. package/dist/src/commands/workshop/generate-demo-data.js +391 -167
  45. package/dist/src/commands/workshop/generate-demo-data.js.map +1 -1
  46. package/dist/src/commands/workshop/verify-setup.d.ts.map +1 -1
  47. package/dist/src/commands/workshop/verify-setup.js +75 -14
  48. package/dist/src/commands/workshop/verify-setup.js.map +1 -1
  49. package/dist/src/utils/exec.d.ts +56 -0
  50. package/dist/src/utils/exec.d.ts.map +1 -0
  51. package/dist/src/utils/exec.js +72 -0
  52. package/dist/src/utils/exec.js.map +1 -0
  53. package/dist/src/utils/region.d.ts +50 -0
  54. package/dist/src/utils/region.d.ts.map +1 -0
  55. package/dist/src/utils/region.js +62 -0
  56. package/dist/src/utils/region.js.map +1 -0
  57. package/dist/src/utils/tempfile.d.ts +19 -0
  58. package/dist/src/utils/tempfile.d.ts.map +1 -0
  59. package/dist/src/utils/tempfile.js +32 -0
  60. package/dist/src/utils/tempfile.js.map +1 -0
  61. package/dist/src/utils/validate.d.ts +54 -0
  62. package/dist/src/utils/validate.d.ts.map +1 -0
  63. package/dist/src/utils/validate.js +143 -0
  64. package/dist/src/utils/validate.js.map +1 -0
  65. package/package.json +2 -2
  66. package/dist/assets/eval-harness/README.md +0 -144
  67. package/dist/assets/github-workflows/README.md +0 -110
  68. package/dist/assets/github-workflows/prism-dora-weekly.yml +0 -334
  69. package/dist/assets/gitlab-workflows/prism-dora-weekly.yml +0 -181
  70. package/dist/assets/infra/lib/lambda/defect-correlator.ts +0 -142
  71. package/dist/assets/infra/lib/lambda/spec-to-code-calculator.ts +0 -123
  72. package/dist/assets/metric-hooks/README.md +0 -107
@@ -1,123 +0,0 @@
1
- import {
2
- DynamoDBClient,
3
- QueryCommand,
4
- } from '@aws-sdk/client-dynamodb';
5
- import {
6
- EventBridgeClient,
7
- PutEventsCommand,
8
- } from '@aws-sdk/client-eventbridge';
9
-
10
- const dynamoClient = new DynamoDBClient({});
11
- const eventBridgeClient = new EventBridgeClient({});
12
-
13
- const EVENTS_TABLE = process.env.EVENTS_TABLE!;
14
- const EVENT_BUS_NAME = process.env.EVENT_BUS_NAME!;
15
-
16
- interface PrMergedEvent {
17
- source: string;
18
- 'detail-type': string;
19
- detail: {
20
- team_id: string;
21
- repo: string;
22
- timestamp: string;
23
- ai_context?: {
24
- tool: string;
25
- model: string;
26
- origin: string;
27
- };
28
- pr?: {
29
- spec_ref?: string;
30
- merged_at?: string;
31
- };
32
- };
33
- }
34
-
35
- /**
36
- * Triggered by merged PR events that have a Spec-Ref.
37
- * Calculates spec-to-code hours by finding the earliest commit
38
- * referencing the same spec and computing the time delta to PR merge.
39
- */
40
- export async function handler(event: PrMergedEvent): Promise<void> {
41
- const detail = event.detail;
42
- const specRef = detail.pr?.spec_ref;
43
-
44
- if (!specRef) {
45
- console.log('No spec reference in PR event, skipping');
46
- return;
47
- }
48
-
49
- console.log(`Calculating spec-to-code for spec: ${specRef}`);
50
-
51
- // Query for the earliest commit event in this repo that references this spec.
52
- // spec_ref is stored as a top-level DynamoDB attribute by the metrics-processor.
53
- try {
54
- const result = await dynamoClient.send(
55
- new QueryCommand({
56
- TableName: EVENTS_TABLE,
57
- KeyConditionExpression: 'pk = :pk',
58
- FilterExpression: 'spec_ref = :spec_ref AND detail_type = :dt',
59
- ExpressionAttributeValues: {
60
- ':pk': { S: `${detail.team_id}#${detail.repo}` },
61
- ':spec_ref': { S: specRef },
62
- ':dt': { S: 'prism.d1.commit' },
63
- },
64
- ScanIndexForward: true, // Oldest first
65
- Limit: 1,
66
- }),
67
- );
68
-
69
- if (!result.Items || result.Items.length === 0) {
70
- console.log(`No commit events found referencing spec: ${specRef}`);
71
- return;
72
- }
73
-
74
- const earliestSpecCommitTime = result.Items[0].sk?.S;
75
- if (!earliestSpecCommitTime) {
76
- console.log('Could not determine spec commit timestamp');
77
- return;
78
- }
79
-
80
- const mergedAt = detail.pr?.merged_at ?? detail.timestamp;
81
- const specTime = new Date(earliestSpecCommitTime);
82
- const mergeTime = new Date(mergedAt);
83
- const specToCodeHours = (mergeTime.getTime() - specTime.getTime()) / (1000 * 60 * 60);
84
-
85
- if (specToCodeHours < 0) {
86
- console.log('Negative spec-to-code time, likely data issue');
87
- return;
88
- }
89
-
90
- const specEvent = {
91
- team_id: detail.team_id,
92
- repo: detail.repo,
93
- timestamp: detail.timestamp,
94
- prism_level: 3,
95
- metric: {
96
- name: 'spec_to_code_hours',
97
- value: Math.round(specToCodeHours * 100) / 100,
98
- unit: 'hours',
99
- },
100
- ai_context: detail.ai_context,
101
- ai_dora: {
102
- spec_to_code_hours: Math.round(specToCodeHours * 100) / 100,
103
- },
104
- };
105
-
106
- await eventBridgeClient.send(
107
- new PutEventsCommand({
108
- Entries: [
109
- {
110
- Source: 'prism.d1.velocity',
111
- DetailType: 'prism.d1.pr',
112
- EventBusName: EVENT_BUS_NAME,
113
- Detail: JSON.stringify(specEvent),
114
- },
115
- ],
116
- }),
117
- );
118
-
119
- console.log(`Spec-to-code: ${specToCodeHours.toFixed(2)} hours for spec ${specRef}`);
120
- } catch (err) {
121
- console.error('Failed to calculate spec-to-code hours:', err);
122
- }
123
- }
@@ -1,107 +0,0 @@
1
- # Metric Hooks
2
-
3
- A `prepare-commit-msg` git hook that automatically tags commits with AI origin metadata and token usage.
4
-
5
- ## What It Does
6
-
7
- Every commit gets trailers appended to the message:
8
-
9
- ```
10
- feat: add order creation endpoint
11
-
12
- AI-Origin: ai-generated
13
- AI-Tool: claude-code
14
- AI-Model: us.anthropic.claude-sonnet-4-5-20250929-v1:0
15
- AI-Input-Tokens: 12450
16
- AI-Output-Tokens: 3200
17
- AI-Cost: $0.08
18
- Spec-Ref: specs/create-order-endpoint.md
19
- ```
20
-
21
- These trailers are read by the `prism-ai-metrics.yml` GitHub workflow on PR merge to emit metrics to EventBridge.
22
-
23
- ## Installation
24
-
25
- ```bash
26
- bash prism-cli bootstrapper install-git-hooks --team-id my-team
27
- ```
28
-
29
- Or interactively (prompts for team ID):
30
-
31
- ```bash
32
- bash prism-cli bootstrapper install-git-hooks
33
- ```
34
-
35
- To remove:
36
-
37
- ```bash
38
- bash prism-cli bootstrapper install-git-hooks --uninstall
39
- ```
40
-
41
- The installer also registers a Claude Code `SessionStart` hook in
42
- `~/.claude/settings.json` (served by `prism-cli git claude-session-context`).
43
- It captures the Claude session id into the environment so commits made during a
44
- Claude Code session are attributed correctly.
45
-
46
- ## Prerequisites
47
-
48
- - **prism-cli** — Runs the hook logic (`prism-cli git commit-trailers`). Install: `npm install -g @prism-d1/cli`
49
- - **codeburn** *(optional)* — Token usage tracking for non-Kiro tools. Install: `npm install -g codeburn` (or `brew install codeburn` on macOS). Kiro sessions are parsed directly by prism-cli, no codeburn needed.
50
-
51
- > The hook is a thin bash delegator to prism-cli. It requires only `git` and
52
- > `bash` (with `prism-cli` on PATH) — **no `jq`, `bc`, or `sed`** — so it works
53
- > on Linux, macOS, and Windows Git Bash. If `prism-cli` is not installed, the
54
- > commit proceeds normally without trailers.
55
-
56
- ## How AI Detection Works
57
-
58
- The hook (via `prism-cli git commit-trailers`) checks for AI tool involvement, in order:
59
-
60
- 1. **Claude Code**: `CLAUDE_CODE` or `CLAUDE_CODE_SESSION_ID` environment variable
61
- 2. **Kiro**: `KIRO_SESSION_ID` / `KIRO_SESSION` env var, `TERM_PROGRAM=kiro` (IDE terminal), or a `kiro` path in `VSCODE_GIT_ASKPASS_NODE` / `GIT_ASKPASS` (Source Control panel commits)
62
- 3. **Q Developer**: `Q_DEVELOPER_SESSION` environment variable
63
- 4. **Default**: No indicators → `AI-Origin: human`
64
-
65
- ## Token Tracking
66
-
67
- When an AI tool is detected, the hook computes a per-commit delta:
68
-
69
- 1. Collects lifetime token totals — Kiro sessions are parsed directly by prism-cli; other tools use `codeburn report -p all --format json`
70
- 2. Compares against a snapshot from the previous commit (`~/.prism/tokentracker/<project-basename>.json`)
71
- 3. Writes the delta as `AI-Input-Tokens` and `AI-Output-Tokens` trailers
72
- 4. Saves the new snapshot for next time
73
-
74
- If no usage data is available (e.g. codeburn absent for a non-Kiro tool) or no AI tool is detected, token trailers are omitted.
75
-
76
- ## Configuration
77
-
78
- The installer creates `.prism/config.json`:
79
-
80
- ```json
81
- {
82
- "team_id": "your-team",
83
- "max_tokens": 1000000,
84
- "max_cost": 100
85
- }
86
- ```
87
-
88
- | Field | Description | Default |
89
- |-------|-------------|---------|
90
- | `team_id` | Team identifier for metric attribution | *(required)* |
91
- | `max_tokens` | Max input/output tokens per commit (capped at this value) | `1000000` |
92
- | `max_cost` | Max cost in USD per commit (capped at this value) | `100` |
93
-
94
- Set custom bounds at install time:
95
-
96
- ```bash
97
- prism-cli bootstrapper install-git-hooks --team-id my-team --max-tokens 500000 --max-cost 50
98
- ```
99
-
100
- Values exceeding bounds are clamped to the configured maximum. The workflow (`prism-ai-metrics.yml`) applies a second layer of enforcement, discarding values above 1M tokens / $100 to zero.
101
-
102
- ## Safety
103
-
104
- - Never blocks a commit — exits 0 even if prism-cli or codeburn is missing or errors
105
- - Only appends trailers — never modifies code
106
- - Skips merge and squash commits
107
- - Won't duplicate trailers if already present