vericify 0.1.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.
@@ -0,0 +1,172 @@
1
+ import { appendRunLedgerEntry } from "../store/run-ledger.js";
2
+ import { appendStatusEvent } from "../store/status-events.js";
3
+
4
+ function shouldWrite(recentWrites, key, signature, throttleMs, force) {
5
+ if (force) return true;
6
+ const previous = recentWrites.get(key);
7
+ const now = Date.now();
8
+ if (previous && previous.signature === signature && now - previous.timestamp_ms < throttleMs) {
9
+ return false;
10
+ }
11
+ recentWrites.set(key, { signature, timestamp_ms: now });
12
+ return true;
13
+ }
14
+
15
+ function targetRunId(runId) {
16
+ return runId || "workspace:current";
17
+ }
18
+
19
+ export function createRuntimeRecorder({
20
+ workspaceRoot,
21
+ traceId,
22
+ sourceModule = "vericify-hub",
23
+ isInteractive = false,
24
+ }) {
25
+ const recentWrites = new Map();
26
+ let interactive = isInteractive;
27
+
28
+ function writeRecord({
29
+ throttleKey,
30
+ signature,
31
+ throttleMs = 1200,
32
+ force = false,
33
+ runId,
34
+ view,
35
+ source = "interactive",
36
+ eventType,
37
+ status,
38
+ summary,
39
+ category,
40
+ metadata = {},
41
+ payload = {},
42
+ }) {
43
+ if (!interactive) return false;
44
+ if (!shouldWrite(recentWrites, throttleKey, signature, throttleMs, force)) return false;
45
+ const resolvedRunId = targetRunId(runId);
46
+ appendStatusEvent(workspaceRoot, {
47
+ trace_id: traceId,
48
+ source_module: sourceModule,
49
+ event_type: eventType,
50
+ status,
51
+ payload: {
52
+ summary,
53
+ run_id: resolvedRunId,
54
+ view,
55
+ source,
56
+ interactive: true,
57
+ ...payload,
58
+ },
59
+ });
60
+ appendRunLedgerEntry(workspaceRoot, {
61
+ tool: sourceModule,
62
+ category,
63
+ message: summary,
64
+ metadata: {
65
+ trace_id: traceId,
66
+ run_id: resolvedRunId,
67
+ view,
68
+ source,
69
+ interactive: true,
70
+ ...metadata,
71
+ },
72
+ });
73
+ return true;
74
+ }
75
+
76
+ return {
77
+ get isInteractive() {
78
+ return interactive;
79
+ },
80
+ setInteractive(value) {
81
+ interactive = Boolean(value);
82
+ },
83
+ recordInitialSelection(runId, view) {
84
+ if (!runId) return false;
85
+ return writeRecord({
86
+ throttleKey: "initial-selection",
87
+ signature: `${runId}:${view}`,
88
+ force: true,
89
+ runId,
90
+ view,
91
+ source: "session_start",
92
+ eventType: "HUB_RUN_FOCUSED",
93
+ status: "started",
94
+ summary: `Focused ${runId} in ${view} view.`,
95
+ category: "operator_focus",
96
+ });
97
+ },
98
+ recordFocus(runId, { view, source = "keyboard", force = false } = {}) {
99
+ if (!runId) return false;
100
+ return writeRecord({
101
+ throttleKey: "focus",
102
+ signature: `${runId}:${view ?? "hub"}`,
103
+ throttleMs: 1000,
104
+ force,
105
+ runId,
106
+ view,
107
+ source,
108
+ eventType: "HUB_RUN_FOCUSED",
109
+ status: "started",
110
+ summary: `Focused ${runId} in ${view ?? "hub"} view.`,
111
+ category: "operator_focus",
112
+ });
113
+ },
114
+ recordViewChange(view, runId, { source = "keyboard", force = false } = {}) {
115
+ return writeRecord({
116
+ throttleKey: "view",
117
+ signature: `${view}:${targetRunId(runId)}`,
118
+ throttleMs: 1000,
119
+ force,
120
+ runId,
121
+ view,
122
+ source,
123
+ eventType: "HUB_VIEW_CHANGED",
124
+ status: "started",
125
+ summary: `Switched to ${view} view${runId ? ` for ${runId}` : ""}.`,
126
+ category: "operator_view",
127
+ });
128
+ },
129
+ recordRefresh(runId, { view, source = "manual", runCount, reason } = {}) {
130
+ return writeRecord({
131
+ throttleKey: `refresh:${source}`,
132
+ signature: `${source}:${targetRunId(runId)}:${runCount ?? "-"}:${reason ?? "-"}`,
133
+ throttleMs: source === "watch" ? 2000 : 800,
134
+ runId,
135
+ view,
136
+ source,
137
+ eventType: "HUB_REFRESHED",
138
+ status: "done",
139
+ summary: source === "watch" ? "Workspace artifacts changed; hub refreshed." : "Hub refreshed.",
140
+ category: "operator_refresh",
141
+ metadata: {
142
+ run_count: runCount,
143
+ reason,
144
+ },
145
+ payload: {
146
+ run_count: runCount,
147
+ reason,
148
+ },
149
+ });
150
+ },
151
+ recordCommandWrite(actionType, runId, { view } = {}) {
152
+ return writeRecord({
153
+ throttleKey: `command:${actionType}`,
154
+ signature: `${actionType}:${targetRunId(runId)}:${view ?? "hub"}`,
155
+ throttleMs: 300,
156
+ runId,
157
+ view,
158
+ source: "command",
159
+ eventType: "HUB_COMMAND_WRITTEN",
160
+ status: "done",
161
+ summary: `Applied ${actionType} from hub command palette.`,
162
+ category: "operator_write",
163
+ metadata: {
164
+ action_type: actionType,
165
+ },
166
+ payload: {
167
+ action_type: actionType,
168
+ },
169
+ });
170
+ },
171
+ };
172
+ }