owlrunkit 0.18.4 → 0.19.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +102 -4
  3. package/docs/architecture/OWLCODA_RUNKIT_0190_CONSOLIDATED_DAILY_USE_PRODUCT_DECISION_20260812.md +97 -0
  4. package/docs/architecture/OWLCODA_RUN_KIT_CONTRACT_V0_2.md +57 -0
  5. package/integrations/codex/skills/owlcoda-runkit/SKILL.md +28 -4
  6. package/integrations/codex/skills/owlcoda-runkit/assets/templates/config.json +3 -3
  7. package/integrations/codex/skills/owlcoda-runkit/references/contract-v0.2.md +57 -0
  8. package/package.json +1 -1
  9. package/packages/attest/README.md +9 -5
  10. package/packages/attest/consumer-surface-v2.json +263 -0
  11. package/packages/attest/distribution-manifest-v1.json +9 -1
  12. package/packages/attest/schemas/quick-verification-receipt-v3.schema.json +244 -0
  13. package/packages/attest/schemas/workspace-snapshot-v2.schema.json +114 -0
  14. package/packages/attest/src/dependency-environment.mjs +128 -0
  15. package/packages/attest/src/index.mjs +1 -0
  16. package/packages/attest/src/quick-receipt-contract.mjs +202 -9
  17. package/packages/attest/src/quick.mjs +40 -4
  18. package/packages/attest/src/workspace-snapshot.mjs +133 -6
  19. package/registry-release-policy-v1.json +5 -5
  20. package/sbom.spdx.json +5 -5
  21. package/scripts/runkit-contract/core-contract.mjs +21 -1
  22. package/scripts/runkit-contract/efficiency-metrics.mjs +559 -0
  23. package/scripts/runkit-contract/evidence-store.mjs +130 -0
  24. package/scripts/runkit-contract/onboarding-bootstrap.mjs +685 -0
  25. package/scripts/runkit-contract/onboarding-doctor.mjs +2 -1
  26. package/scripts/runkit-contract/outcome-presentation.mjs +171 -0
  27. package/scripts/runkit-contract/profile-onboarding.mjs +22 -2
  28. package/scripts/runkit-contract/project-cli-resolver.mjs +23 -5
  29. package/scripts/runkit-contract/quick-evidence-reuse.mjs +590 -0
  30. package/scripts/runkit-contract/quick-isolation.mjs +314 -0
  31. package/scripts/runkit-contract/quick-metrics.mjs +51 -3
  32. package/scripts/runkit-contract/quick-receipt.mjs +31 -1
  33. package/scripts/runkit-contract/quick-verify.mjs +216 -25
  34. package/scripts/runkit-contract/quick-workspace-snapshot.mjs +1 -0
  35. package/scripts/runkit-contract/runkit-bootstrap.mjs +1 -0
  36. package/scripts/runkit-contract/runkit-cli.mjs +330 -18
  37. package/scripts/runkit-contract/runtime-transition.mjs +478 -0
  38. package/scripts/runkit-contract/schemas/efficiency-event-v1.schema.json +56 -0
  39. package/scripts/runkit-contract/schemas/efficiency-metrics-v1.schema.json +220 -0
  40. package/scripts/runkit-contract/schemas/external-runtime-report-v1.schema.json +125 -0
  41. package/scripts/runkit-contract/schemas/onboarding-bootstrap-plan-v1.schema.json +168 -0
  42. package/scripts/runkit-contract/schemas/onboarding-bootstrap-receipt-v1.schema.json +130 -0
  43. package/scripts/runkit-contract/schemas/outcome-summary-v1.schema.json +83 -0
  44. package/scripts/runkit-contract/schemas/quick-evidence-reuse-plan-v1.schema.json +59 -0
  45. package/scripts/runkit-contract/schemas/quick-evidence-reuse-receipt-v1.schema.json +79 -0
  46. package/scripts/runkit-contract/schemas/runtime-transition-receipt-v1.schema.json +185 -0
  47. package/scripts/runkit-contract/schemas/team-project-event-v4.schema.json +142 -0
  48. package/scripts/runkit-contract/team-project.mjs +704 -16
  49. package/scripts/runkit-contract/verification-envelope.mjs +15 -18
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": "OwlCodaRunKitRegistryReleasePolicyV1",
3
3
  "status": "release_candidate_unpublished",
4
4
  "packageName": "owlrunkit",
5
- "candidateVersion": "0.18.4",
5
+ "candidateVersion": "0.19.0",
6
6
  "registry": "https://registry.npmjs.org",
7
7
  "registryRequiredBeforeAdoption": true,
8
8
  "exactVersionRequired": true,
@@ -23,10 +23,10 @@
23
23
  ],
24
24
  "currentPublishedRelease": {
25
25
  "packageName": "owlrunkit",
26
- "version": "0.18.3",
27
- "shasum": "f8ba5ab3d426aea21bbdd8f459fd3dd5e89ff08a",
28
- "integrity": "sha512-zcsWY8sSKW1uJpa28VDqBx9coEMYnADKix9sr0rPz+kyoV6K/NDHHRMPx+24oFDKH9zVFaNyVyq5OAgoaMm8/Q==",
29
- "tarballUrl": "https://registry.npmjs.org/owlrunkit/-/owlrunkit-0.18.3.tgz"
26
+ "version": "0.18.4",
27
+ "shasum": "8f2ef01da287b76b545eeebd6973bc40449dd302",
28
+ "integrity": "sha512-L3cFuJnU39p/EhgrRaJbEIB7gTRFxKzEpNmANw3kwNFrTe9Fe8wtwgdFOBXldX6xCJY+W44/8cw4P/dtAxiCAA==",
29
+ "tarballUrl": "https://registry.npmjs.org/owlrunkit/-/owlrunkit-0.18.4.tgz"
30
30
  },
31
31
  "registryRelease": null,
32
32
  "registryEvidenceMustBeExternal": true,
package/sbom.spdx.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "spdxVersion": "SPDX-2.3",
3
3
  "dataLicense": "CC0-1.0",
4
4
  "SPDXID": "SPDXRef-DOCUMENT",
5
- "name": "owlrunkit-0.18.4",
6
- "documentNamespace": "https://owlcoda.com/spdx/owlrunkit/0.18.4",
5
+ "name": "owlrunkit-0.19.0",
6
+ "documentNamespace": "https://owlcoda.com/spdx/owlrunkit/0.19.0",
7
7
  "creationInfo": {
8
8
  "created": "2026-07-29T00:00:00Z",
9
9
  "creators": [
@@ -14,8 +14,8 @@
14
14
  {
15
15
  "name": "owlrunkit",
16
16
  "SPDXID": "SPDXRef-Package-OwlRunKit",
17
- "versionInfo": "0.18.4",
18
- "downloadLocation": "https://registry.npmjs.org/owlrunkit/-/owlrunkit-0.18.4.tgz",
17
+ "versionInfo": "0.19.0",
18
+ "downloadLocation": "https://registry.npmjs.org/owlrunkit/-/owlrunkit-0.19.0.tgz",
19
19
  "filesAnalyzed": false,
20
20
  "licenseConcluded": "GPL-3.0-or-later",
21
21
  "licenseDeclared": "GPL-3.0-or-later",
@@ -24,7 +24,7 @@
24
24
  {
25
25
  "referenceCategory": "PACKAGE-MANAGER",
26
26
  "referenceType": "purl",
27
- "referenceLocator": "pkg:npm/owlrunkit@0.18.4"
27
+ "referenceLocator": "pkg:npm/owlrunkit@0.19.0"
28
28
  }
29
29
  ]
30
30
  }
@@ -14,7 +14,7 @@ import { fileURLToPath } from "node:url";
14
14
  import { parseProjectControlState } from "./project-control-parser.mjs";
15
15
 
16
16
  export const CONTRACT_VERSION = "0.2";
17
- export const CORE_VERSION = "0.18.4";
17
+ export const CORE_VERSION = "0.19.0";
18
18
  export const RUNTIME_ROOT = ".owlcoda/runkit";
19
19
 
20
20
  const CORE_FILES = [
@@ -26,6 +26,7 @@ const CORE_FILES = [
26
26
  "delivery-create.mjs",
27
27
  "delivery-selection.mjs",
28
28
  "deployment-workflow.mjs",
29
+ "efficiency-metrics.mjs",
29
30
  "fleet-discovery.mjs",
30
31
  "finalize.mjs",
31
32
  "formal-workflow.mjs",
@@ -35,7 +36,9 @@ const CORE_FILES = [
35
36
  "lease-lifecycle.mjs",
36
37
  "lifecycle-orchestration.mjs",
37
38
  "offline-store.mjs",
39
+ "outcome-presentation.mjs",
38
40
  "onboarding-doctor.mjs",
41
+ "onboarding-bootstrap.mjs",
39
42
  "owner-authority-trust.mjs",
40
43
  "owner-deployment-decision.mjs",
41
44
  "profile-impact.mjs",
@@ -47,8 +50,12 @@ const CORE_FILES = [
47
50
  "provenance-common.mjs",
48
51
  "quick-attest.mjs",
49
52
  "quick-canonical.mjs",
53
+ "quick-isolation.mjs",
50
54
  "quick-metrics.mjs",
51
55
  "quick-receipt.mjs",
56
+ "quick-evidence-reuse.mjs",
57
+ "evidence-store.mjs",
58
+ "runtime-transition.mjs",
52
59
  "quick-verify.mjs",
53
60
  "quick-workspace-snapshot.mjs",
54
61
  "ready-for-commit.mjs",
@@ -89,6 +96,8 @@ const CORE_FILES = [
89
96
  "schemas/deployment-execute-request-v1.schema.json",
90
97
  "schemas/deployment-lineage-v1.schema.json",
91
98
  "schemas/deployment-prepare-receipt-v1.schema.json",
99
+ "schemas/efficiency-event-v1.schema.json",
100
+ "schemas/efficiency-metrics-v1.schema.json",
92
101
  "schemas/engine-pin.schema.json",
93
102
  "schemas/engine-pin-v2.schema.json",
94
103
  "schemas/evidence-coverage-index-v1.schema.json",
@@ -96,6 +105,9 @@ const CORE_FILES = [
96
105
  "schemas/fleet-manifest-v1.schema.json",
97
106
  "schemas/fleet-root-registry-v1.schema.json",
98
107
  "schemas/human-status-v1.schema.json",
108
+ "schemas/onboarding-bootstrap-plan-v1.schema.json",
109
+ "schemas/onboarding-bootstrap-receipt-v1.schema.json",
110
+ "schemas/outcome-summary-v1.schema.json",
99
111
  "schemas/owner-authority-trust-v1.schema.json",
100
112
  "schemas/owner-migration-authority-v1.schema.json",
101
113
  "schemas/owner-migration-authority-v2.schema.json",
@@ -122,6 +134,10 @@ const CORE_FILES = [
122
134
  "schemas/finalize-request-v1.schema.json",
123
135
  "schemas/ready-for-commit-v1.schema.json",
124
136
  "schemas/ready-for-commit-v2.schema.json",
137
+ "schemas/quick-evidence-reuse-plan-v1.schema.json",
138
+ "schemas/quick-evidence-reuse-receipt-v1.schema.json",
139
+ "schemas/external-runtime-report-v1.schema.json",
140
+ "schemas/runtime-transition-receipt-v1.schema.json",
125
141
  "schemas/snapshot-v1.schema.json",
126
142
  "schemas/source-candidate-v2.schema.json",
127
143
  "schemas/visual-smoke-request-v1.schema.json",
@@ -131,6 +147,7 @@ const CORE_FILES = [
131
147
  "schemas/team-project-event-v1.schema.json",
132
148
  "schemas/team-project-event-v2.schema.json",
133
149
  "schemas/team-project-event-v3.schema.json",
150
+ "schemas/team-project-event-v4.schema.json",
134
151
  "schemas/team-project-successor-receipt-v1.schema.json",
135
152
  "schemas/team-project-status-v1.schema.json",
136
153
  "schemas/team-project-status-v2.schema.json",
@@ -167,7 +184,10 @@ const CORE_FILES = [
167
184
  ];
168
185
 
169
186
  const CORE_DEPENDENCY_FILES = [
187
+ "packages/attest/src/dependency-environment.mjs",
170
188
  "packages/attest/schemas/workspace-snapshot-v1.schema.json",
189
+ "packages/attest/schemas/workspace-snapshot-v2.schema.json",
190
+ "packages/attest/schemas/quick-verification-receipt-v3.schema.json",
171
191
  "packages/attest/src/formal.mjs",
172
192
  "packages/attest/src/offline-bundle.mjs",
173
193
  "packages/attest/src/quick-receipt-contract.mjs",
@@ -0,0 +1,559 @@
1
+ import {
2
+ existsSync,
3
+ lstatSync,
4
+ mkdirSync,
5
+ readdirSync,
6
+ realpathSync,
7
+ rmSync,
8
+ } from "node:fs";
9
+ import path from "node:path";
10
+
11
+ import {
12
+ decodeUtf8Strict,
13
+ parseJsonStrict,
14
+ readFileBytesBounded,
15
+ } from "../../packages/attest/src/formal.mjs";
16
+ import {
17
+ canonicalJson,
18
+ sha256Canonical,
19
+ } from "./quick-canonical.mjs";
20
+ import { readTrustedQuickReceiptHistory } from "./quick-metrics.mjs";
21
+ import {
22
+ relativeToWorkspace,
23
+ safeIdentifier,
24
+ writeJsonExclusiveAtomically,
25
+ } from "./provenance-common.mjs";
26
+ import { readTeamProjectHandoffWaitV1 } from "./team-project.mjs";
27
+
28
+ const EFFICIENCY_ROOT = ".owlcoda/runkit/efficiency";
29
+ const EVENT_ROOT = `${EFFICIENCY_ROOT}/events`;
30
+ const EVENT_SCHEMA = "OwlCodaRunKitEfficiencyEventV1";
31
+ const EVENT_KINDS = new Set([
32
+ "workflow_started",
33
+ "false_block_confirmed",
34
+ "manual_intervention",
35
+ "acceptable_result_reached",
36
+ ]);
37
+ const EVENT_KEYS = [
38
+ "schemaVersion",
39
+ "eventId",
40
+ "kind",
41
+ "occurredAt",
42
+ "workflowId",
43
+ "summary",
44
+ "evidenceRefs",
45
+ "authorizationGranted",
46
+ ];
47
+
48
+ function compareIdentifiers(left, right) {
49
+ return left < right ? -1 : left > right ? 1 : 0;
50
+ }
51
+
52
+ function validateTimestamp(value) {
53
+ if (typeof value !== "string"
54
+ || !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u.test(value)
55
+ || Number.isNaN(Date.parse(value))
56
+ || new Date(value).toISOString() !== value) {
57
+ throw new Error("Efficiency event --at must be an ISO-8601 UTC timestamp.");
58
+ }
59
+ return value;
60
+ }
61
+
62
+ function normalizeEvent(value) {
63
+ if (!value || typeof value !== "object" || Array.isArray(value)
64
+ || Object.keys(value).sort(compareIdentifiers).join("\0")
65
+ !== [...EVENT_KEYS].sort(compareIdentifiers).join("\0")) {
66
+ throw new Error("Efficiency event must use the exact V1 fields.");
67
+ }
68
+ if (value.schemaVersion !== EVENT_SCHEMA) {
69
+ throw new Error("Efficiency event schemaVersion is unsupported.");
70
+ }
71
+ safeIdentifier(value.eventId, "efficiency eventId");
72
+ safeIdentifier(value.workflowId, "efficiency workflowId");
73
+ if (value.eventId.length > 128 || value.workflowId.length > 128) {
74
+ throw new Error("Efficiency event and workflow identifiers must not exceed 128 characters.");
75
+ }
76
+ if (!EVENT_KINDS.has(value.kind)) throw new Error("Efficiency event kind is unsupported.");
77
+ validateTimestamp(value.occurredAt);
78
+ if (typeof value.summary !== "string"
79
+ || value.summary.trim().length === 0
80
+ || value.summary.length > 2_000) {
81
+ throw new Error("Efficiency event summary must contain 1 to 2000 characters.");
82
+ }
83
+ if (!Array.isArray(value.evidenceRefs)
84
+ || value.evidenceRefs.length > 100
85
+ || value.evidenceRefs.some(ref => typeof ref !== "string" || ref.trim().length === 0)
86
+ || value.evidenceRefs.some(ref => Buffer.byteLength(ref, "utf8") > 2_048)
87
+ || new Set(value.evidenceRefs).size !== value.evidenceRefs.length) {
88
+ throw new Error("Efficiency event evidenceRefs must be a unique string array.");
89
+ }
90
+ if (value.authorizationGranted !== false) {
91
+ throw new Error("Efficiency events cannot grant authority.");
92
+ }
93
+ return {
94
+ schemaVersion: EVENT_SCHEMA,
95
+ eventId: value.eventId,
96
+ kind: value.kind,
97
+ occurredAt: value.occurredAt,
98
+ workflowId: value.workflowId,
99
+ summary: value.summary.trim(),
100
+ evidenceRefs: [...value.evidenceRefs].sort(compareIdentifiers),
101
+ authorizationGranted: false,
102
+ };
103
+ }
104
+
105
+ function ensureDirectory(root, current, label, { create }) {
106
+ if (!existsSync(current)) {
107
+ if (!create) return false;
108
+ try {
109
+ mkdirSync(current);
110
+ } catch (error) {
111
+ if (error?.code !== "EEXIST") throw error;
112
+ }
113
+ }
114
+ const stat = lstatSync(current);
115
+ if (stat.isSymbolicLink() || !stat.isDirectory() || realpathSync(current) !== current) {
116
+ throw new Error(`${label} must be a real project-local directory tree.`);
117
+ }
118
+ const relative = path.relative(root, current);
119
+ if (relative === ".." || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
120
+ throw new Error(`${label} escapes the project workspace.`);
121
+ }
122
+ return true;
123
+ }
124
+
125
+ function efficiencyRootState(workspaceRoot, { create = false } = {}) {
126
+ const root = realpathSync(workspaceRoot);
127
+ let current = root;
128
+ for (const segment of EFFICIENCY_ROOT.split("/")) {
129
+ current = path.join(current, segment);
130
+ if (!ensureDirectory(root, current, "Efficiency event store", { create })) {
131
+ return {
132
+ status: "missing",
133
+ root,
134
+ efficiencyRoot: path.join(root, EFFICIENCY_ROOT),
135
+ };
136
+ }
137
+ }
138
+ return { status: "valid", root, efficiencyRoot: current };
139
+ }
140
+
141
+ function eventRootState(workspaceRoot, { create = false } = {}) {
142
+ const efficiency = efficiencyRootState(workspaceRoot, { create });
143
+ const eventRoot = path.join(efficiency.root, EVENT_ROOT);
144
+ if (efficiency.status === "missing"
145
+ || !ensureDirectory(efficiency.root, eventRoot, "Efficiency event store", { create })) {
146
+ return { status: "missing", root: efficiency.root, eventRoot };
147
+ }
148
+ return { status: "valid", root: efficiency.root, eventRoot };
149
+ }
150
+
151
+ function withEfficiencyLock(workspaceRoot, operation) {
152
+ const selected = efficiencyRootState(workspaceRoot, { create: true });
153
+ const lockPath = path.join(selected.efficiencyRoot, "control.lock");
154
+ try {
155
+ mkdirSync(lockPath);
156
+ } catch (error) {
157
+ if (error?.code === "EEXIST") {
158
+ throw new Error("Another efficiency event transaction is active.");
159
+ }
160
+ throw error;
161
+ }
162
+ try {
163
+ return operation(selected.root);
164
+ } finally {
165
+ rmSync(lockPath, { recursive: true, force: true });
166
+ }
167
+ }
168
+
169
+ function readStoredEvent(eventPath) {
170
+ const stat = lstatSync(eventPath);
171
+ if (stat.isSymbolicLink() || !stat.isFile()) {
172
+ throw new Error("Efficiency event must be a regular non-symlink file.");
173
+ }
174
+ const { bytes } = readFileBytesBounded(eventPath);
175
+ const parsed = parseJsonStrict(decodeUtf8Strict(bytes));
176
+ const normalized = normalizeEvent(parsed);
177
+ if (canonicalJson(parsed) !== canonicalJson(normalized)) {
178
+ throw new Error("Efficiency event bytes do not match the canonical V1 event.");
179
+ }
180
+ return normalized;
181
+ }
182
+
183
+ function readEvents(workspaceRoot) {
184
+ const selected = eventRootState(workspaceRoot);
185
+ if (selected.status === "missing") return { root: selected.root, events: [], inputRefs: [] };
186
+ const entries = readdirSync(selected.eventRoot, { withFileTypes: true })
187
+ .sort((left, right) => compareIdentifiers(left.name, right.name));
188
+ const events = [];
189
+ const inputRefs = [];
190
+ for (const entry of entries) {
191
+ if (!entry.isFile() || entry.isSymbolicLink() || !entry.name.endsWith(".json")) {
192
+ throw new Error("Efficiency event store contains an unsupported entry.");
193
+ }
194
+ const eventId = entry.name.slice(0, -".json".length);
195
+ safeIdentifier(eventId, "efficiency event filename");
196
+ const eventPath = path.join(selected.eventRoot, entry.name);
197
+ const event = readStoredEvent(eventPath);
198
+ if (event.eventId !== eventId) throw new Error("Efficiency event filename does not match eventId.");
199
+ events.push(event);
200
+ inputRefs.push(relativeToWorkspace(selected.root, eventPath));
201
+ }
202
+ events.sort((left, right) => (
203
+ compareIdentifiers(left.occurredAt, right.occurredAt)
204
+ || compareIdentifiers(left.eventId, right.eventId)
205
+ ));
206
+ const workflows = new Map();
207
+ for (const event of events) {
208
+ const rows = workflows.get(event.workflowId) ?? [];
209
+ rows.push(event);
210
+ workflows.set(event.workflowId, rows);
211
+ }
212
+ for (const [workflowId, rows] of workflows) {
213
+ const starts = rows.filter(row => row.kind === "workflow_started");
214
+ const results = rows.filter(row => row.kind === "acceptable_result_reached");
215
+ if (starts.length > 1) {
216
+ throw new Error(`Efficiency workflow ${workflowId} has multiple workflow_started events.`);
217
+ }
218
+ if (results.length > 1) {
219
+ throw new Error(`Efficiency workflow ${workflowId} has multiple acceptable_result_reached events.`);
220
+ }
221
+ if (results.length === 1 && starts.length !== 1) {
222
+ throw new Error(`Efficiency workflow ${workflowId} has an acceptable result without workflow_started.`);
223
+ }
224
+ if (results.length === 1 && results[0].occurredAt < starts[0].occurredAt) {
225
+ throw new Error(`Efficiency workflow ${workflowId} has an acceptable result before workflow_started.`);
226
+ }
227
+ }
228
+ return { root: selected.root, events, inputRefs };
229
+ }
230
+
231
+ function validateEventAgainstHistory(history, event) {
232
+ const existing = history.events.find(row => row.eventId === event.eventId);
233
+ if (existing) {
234
+ if (canonicalJson(existing) !== canonicalJson(event)) {
235
+ throw new Error(`Efficiency event ${event.eventId} is immutable and differs.`);
236
+ }
237
+ return { existing };
238
+ }
239
+ const workflowEvents = history.events.filter(row => row.workflowId === event.workflowId);
240
+ const workflowStart = workflowEvents.find(row => row.kind === "workflow_started");
241
+ if (event.kind === "workflow_started" && workflowStart) {
242
+ throw new Error(`Efficiency workflow ${event.workflowId} already has a workflow_started event.`);
243
+ }
244
+ if (event.kind === "acceptable_result_reached") {
245
+ if (!workflowStart) {
246
+ throw new Error("acceptable_result_reached requires an earlier workflow_started event.");
247
+ }
248
+ if (workflowEvents.some(row => row.kind === "acceptable_result_reached")) {
249
+ throw new Error(`Efficiency workflow ${event.workflowId} already reached an acceptable result.`);
250
+ }
251
+ if (event.occurredAt < workflowStart.occurredAt) {
252
+ throw new Error("acceptable_result_reached cannot precede workflow_started.");
253
+ }
254
+ }
255
+ return { existing: null };
256
+ }
257
+
258
+ export function recordEfficiencyEventV1({
259
+ workspaceRoot,
260
+ eventId,
261
+ occurredAt,
262
+ kind,
263
+ workflowId,
264
+ summary,
265
+ evidenceRefs = [],
266
+ }) {
267
+ const event = normalizeEvent({
268
+ schemaVersion: EVENT_SCHEMA,
269
+ eventId,
270
+ kind,
271
+ occurredAt,
272
+ workflowId,
273
+ summary,
274
+ evidenceRefs,
275
+ authorizationGranted: false,
276
+ });
277
+ const history = readEvents(workspaceRoot);
278
+ const eventPath = path.join(history.root, EVENT_ROOT, `${event.eventId}.json`);
279
+ const initial = validateEventAgainstHistory(history, event);
280
+ if (initial.existing) {
281
+ return {
282
+ status: "efficiency_event_recorded",
283
+ exitCode: 0,
284
+ eventId: event.eventId,
285
+ eventPath: relativeToWorkspace(history.root, eventPath),
286
+ eventSha256: sha256Canonical(event),
287
+ resumed: true,
288
+ authorizationGranted: false,
289
+ };
290
+ }
291
+ return withEfficiencyLock(history.root, (root) => {
292
+ const refreshed = readEvents(root);
293
+ const current = validateEventAgainstHistory(refreshed, event);
294
+ const lockedEventPath = path.join(root, EVENT_ROOT, `${event.eventId}.json`);
295
+ if (current.existing) {
296
+ return {
297
+ status: "efficiency_event_recorded",
298
+ exitCode: 0,
299
+ eventId: event.eventId,
300
+ eventPath: relativeToWorkspace(root, lockedEventPath),
301
+ eventSha256: sha256Canonical(event),
302
+ resumed: true,
303
+ authorizationGranted: false,
304
+ };
305
+ }
306
+ const selected = eventRootState(root, { create: true });
307
+ writeJsonExclusiveAtomically(lockedEventPath, event);
308
+ return {
309
+ status: "efficiency_event_recorded",
310
+ exitCode: 0,
311
+ eventId: event.eventId,
312
+ eventPath: relativeToWorkspace(selected.root, lockedEventPath),
313
+ eventSha256: sha256Canonical(event),
314
+ resumed: false,
315
+ authorizationGranted: false,
316
+ };
317
+ });
318
+ }
319
+
320
+ function dependencyFingerprint(receipt) {
321
+ return receipt.executionIsolation?.dependencyEnvironment?.fingerprint ?? null;
322
+ }
323
+
324
+ function commandBinding(receipt) {
325
+ return {
326
+ executable: receipt.exactCommand.executable,
327
+ argv: receipt.exactCommand.argv,
328
+ workspaceSnapshotFingerprint: receipt.workspaceBefore.sourceFingerprint,
329
+ ignoredPathsFingerprint: receipt.workspaceBefore.ignoredPathsFingerprint ?? null,
330
+ stdinSha256: receipt.inputArtifacts?.stdin?.sha256 ?? null,
331
+ dependencyEnvironmentFingerprint: dependencyFingerprint(receipt),
332
+ };
333
+ }
334
+
335
+ function duplicateCommandMetrics(root, history) {
336
+ const groups = new Map();
337
+ for (const { receiptPath, receipt } of history.receipts) {
338
+ const bindingFingerprint = sha256Canonical(commandBinding(receipt));
339
+ const group = groups.get(bindingFingerprint) ?? {
340
+ bindingFingerprint,
341
+ executions: 0,
342
+ inputRefs: [],
343
+ };
344
+ group.executions += 1;
345
+ group.inputRefs.push(relativeToWorkspace(root, receiptPath));
346
+ groups.set(bindingFingerprint, group);
347
+ }
348
+ const repeated = [...groups.values()]
349
+ .filter(group => group.executions > 1)
350
+ .sort((left, right) => compareIdentifiers(left.bindingFingerprint, right.bindingFingerprint));
351
+ return {
352
+ summary: {
353
+ repeatedExecutions: repeated.reduce((total, group) => total + group.executions - 1, 0),
354
+ groupCount: repeated.length,
355
+ basis: "quick_receipts_same_command_candidate_input_and_dependency",
356
+ },
357
+ groups: repeated,
358
+ };
359
+ }
360
+
361
+ function workflowMetrics(events) {
362
+ const byWorkflow = new Map();
363
+ for (const event of events) {
364
+ const rows = byWorkflow.get(event.workflowId) ?? [];
365
+ rows.push(event);
366
+ byWorkflow.set(event.workflowId, rows);
367
+ }
368
+ const durations = [];
369
+ for (const [workflowId, rows] of byWorkflow) {
370
+ const started = rows.find(event => event.kind === "workflow_started");
371
+ if (!started) continue;
372
+ const completed = rows.find(event => (
373
+ event.kind === "acceptable_result_reached"
374
+ && event.occurredAt >= started.occurredAt
375
+ ));
376
+ if (!completed) continue;
377
+ durations.push({
378
+ workflowId,
379
+ startedAt: started.occurredAt,
380
+ acceptableResultAt: completed.occurredAt,
381
+ durationMs: Date.parse(completed.occurredAt) - Date.parse(started.occurredAt),
382
+ });
383
+ }
384
+ durations.sort((left, right) => (
385
+ compareIdentifiers(left.acceptableResultAt, right.acceptableResultAt)
386
+ || compareIdentifiers(left.workflowId, right.workflowId)
387
+ ));
388
+ if (durations.length === 0) {
389
+ return {
390
+ summary: {
391
+ status: "not_observed",
392
+ completedWorkflows: 0,
393
+ totalMs: 0,
394
+ averageMs: 0,
395
+ minMs: 0,
396
+ maxMs: 0,
397
+ latestMs: 0,
398
+ },
399
+ durations,
400
+ };
401
+ }
402
+ const totalMs = durations.reduce((total, row) => total + row.durationMs, 0);
403
+ return {
404
+ summary: {
405
+ status: "observed",
406
+ completedWorkflows: durations.length,
407
+ totalMs,
408
+ averageMs: Math.round(totalMs / durations.length),
409
+ minMs: Math.min(...durations.map(row => row.durationMs)),
410
+ maxMs: Math.max(...durations.map(row => row.durationMs)),
411
+ latestMs: durations.at(-1).durationMs,
412
+ },
413
+ durations,
414
+ };
415
+ }
416
+
417
+ function emptyHandoffWait() {
418
+ return {
419
+ completedHandoffs: 0,
420
+ unresolvedHandoffs: 0,
421
+ staleHandoffs: 0,
422
+ totalMs: 0,
423
+ averageMs: 0,
424
+ maxMs: 0,
425
+ };
426
+ }
427
+
428
+ export function readEfficiencyMetricsV1({ workspaceRoot, verbose = false }) {
429
+ const root = realpathSync(workspaceRoot);
430
+ try {
431
+ const eventHistory = readEvents(root);
432
+ const quickHistory = readTrustedQuickReceiptHistory(root);
433
+ if (quickHistory.status === "invalid") {
434
+ throw new Error("Quick receipt store is invalid.");
435
+ }
436
+ const duplicateCommands = duplicateCommandMetrics(root, quickHistory);
437
+ const workflows = workflowMetrics(eventHistory.events);
438
+ const handoff = readTeamProjectHandoffWaitV1({ workspaceRoot: root });
439
+ const issueCodes = quickHistory.invalidCount > 0
440
+ ? ["invalid_quick_receipts_excluded"]
441
+ : [];
442
+ return {
443
+ schemaVersion: "OwlCodaRunKitEfficiencyMetricsV1",
444
+ status: "efficiency_metrics",
445
+ exitCode: 0,
446
+ telemetry: false,
447
+ networkRequests: 0,
448
+ duplicateCommands: duplicateCommands.summary,
449
+ confirmedFalseBlocks: {
450
+ count: eventHistory.events.filter(event => event.kind === "false_block_confirmed").length,
451
+ basis: "explicit_events",
452
+ },
453
+ manualInterventions: {
454
+ count: eventHistory.events.filter(event => event.kind === "manual_intervention").length,
455
+ basis: "explicit_events",
456
+ },
457
+ handoffWait: {
458
+ completedHandoffs: handoff.completedHandoffs,
459
+ unresolvedHandoffs: handoff.unresolvedHandoffs,
460
+ staleHandoffs: handoff.staleHandoffs,
461
+ totalMs: handoff.totalMs,
462
+ averageMs: handoff.averageMs,
463
+ maxMs: handoff.maxMs,
464
+ },
465
+ timeToAcceptableResult: workflows.summary,
466
+ ...(verbose
467
+ ? {
468
+ details: {
469
+ duplicateCommandGroups: duplicateCommands.groups,
470
+ workflowDurations: workflows.durations,
471
+ handoffSamples: handoff.samples,
472
+ inputRefs: [...new Set([
473
+ ...eventHistory.inputRefs,
474
+ ...quickHistory.receiptPaths.map(receiptPath => relativeToWorkspace(root, receiptPath)),
475
+ ...handoff.inputRefs,
476
+ ])].sort(compareIdentifiers),
477
+ },
478
+ }
479
+ : {}),
480
+ issueCodes,
481
+ issues: [],
482
+ authorizationGranted: false,
483
+ };
484
+ } catch (error) {
485
+ return {
486
+ schemaVersion: "OwlCodaRunKitEfficiencyMetricsV1",
487
+ status: "efficiency_metrics_invalid",
488
+ exitCode: 3,
489
+ telemetry: false,
490
+ networkRequests: 0,
491
+ duplicateCommands: {
492
+ repeatedExecutions: 0,
493
+ groupCount: 0,
494
+ basis: "quick_receipts_same_command_candidate_input_and_dependency",
495
+ },
496
+ confirmedFalseBlocks: { count: 0, basis: "explicit_events" },
497
+ manualInterventions: { count: 0, basis: "explicit_events" },
498
+ handoffWait: emptyHandoffWait(),
499
+ timeToAcceptableResult: {
500
+ status: "not_observed",
501
+ completedWorkflows: 0,
502
+ totalMs: 0,
503
+ averageMs: 0,
504
+ minMs: 0,
505
+ maxMs: 0,
506
+ latestMs: 0,
507
+ },
508
+ issueCodes: ["efficiency_input_store_invalid"],
509
+ issues: [error instanceof Error ? error.message : String(error)],
510
+ authorizationGranted: false,
511
+ };
512
+ }
513
+ }
514
+
515
+ function duration(value, observed) {
516
+ if (!observed) return "not observed";
517
+ if (value === 0) return "0ms";
518
+ if (value >= 60_000) {
519
+ const minutes = Math.round((value / 60_000) * 10) / 10;
520
+ return `${minutes}m`;
521
+ }
522
+ if (value >= 1_000) {
523
+ const seconds = Math.round((value / 1_000) * 10) / 10;
524
+ return `${seconds}s`;
525
+ }
526
+ return `${value}ms`;
527
+ }
528
+
529
+ export function formatEfficiencyMetricsHumanV1(metrics) {
530
+ if (metrics.status !== "efficiency_metrics") {
531
+ return [
532
+ "RunKit friction: unavailable because a project-local input store is invalid.",
533
+ `Issue: ${metrics.issues.join("; ")}`,
534
+ "Next: repair the invalid local evidence store before using these metrics.",
535
+ "Authority: no Git, release, deployment, production, or business authority granted.",
536
+ ].join("\n");
537
+ }
538
+ return [
539
+ "RunKit friction: "
540
+ + `${metrics.duplicateCommands.repeatedExecutions} repeated Quick command executions; `
541
+ + `${metrics.confirmedFalseBlocks.count} confirmed false blocks; `
542
+ + `${metrics.manualInterventions.count} manual interventions.`,
543
+ `Repeated Quick command executions: ${metrics.duplicateCommands.repeatedExecutions} `
544
+ + `(same command, candidate, input, and dependency binding).`,
545
+ `Confirmed false blocks: ${metrics.confirmedFalseBlocks.count}; `
546
+ + `Manual interventions: ${metrics.manualInterventions.count} (explicit marks only).`,
547
+ `Handoff wait: ${metrics.handoffWait.completedHandoffs} completed, `
548
+ + `${duration(metrics.handoffWait.averageMs, metrics.handoffWait.completedHandoffs > 0)} average; `
549
+ + `${metrics.handoffWait.unresolvedHandoffs} unresolved; `
550
+ + `${metrics.handoffWait.staleHandoffs} stale.`,
551
+ `Time to acceptable result: ${duration(
552
+ metrics.timeToAcceptableResult.averageMs,
553
+ metrics.timeToAcceptableResult.status === "observed",
554
+ )} `
555
+ + `across ${metrics.timeToAcceptableResult.completedWorkflows} observed workflows.`,
556
+ "Basis: project-local receipts and explicit events only; telemetry and network requests are disabled.",
557
+ "Authority: no Git, release, deployment, production, or business authority granted.",
558
+ ].join("\n");
559
+ }