greprag 5.68.0 → 5.69.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/dist/capture-manifest.d.ts +5 -2
- package/dist/capture-manifest.js +9 -5
- package/dist/capture-manifest.js.map +1 -1
- package/dist/hook.js +9 -59
- package/dist/hook.js.map +1 -1
- package/dist/inline-atom-episode.d.ts +72 -0
- package/dist/inline-atom-episode.js +380 -0
- package/dist/inline-atom-episode.js.map +1 -0
- package/dist/inline-atom-hook.d.ts +19 -0
- package/dist/inline-atom-hook.js +89 -0
- package/dist/inline-atom-hook.js.map +1 -0
- package/dist/inline-atom.d.ts +13 -13
- package/dist/inline-atom.js +15 -62
- package/dist/inline-atom.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Inline-Atom episode journal and artifact lifecycle reducer.
|
|
2
|
+
* adr: adr/capture-episodes.md */
|
|
3
|
+
import { type InlineAtomSchema } from './inline-atom';
|
|
4
|
+
export type InlineAtomEpisodeDisposition = 'ignore' | 'open' | 'close';
|
|
5
|
+
export type InlineAtomReplayOutcome = 'none' | 'worked' | 'failed' | 'unclear';
|
|
6
|
+
export interface InlineAtomEpisodeObservation {
|
|
7
|
+
atom: string;
|
|
8
|
+
episode: InlineAtomEpisodeDisposition;
|
|
9
|
+
replay: InlineAtomReplayOutcome;
|
|
10
|
+
friction?: string;
|
|
11
|
+
endpoint?: string;
|
|
12
|
+
query?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface InlineAtomEpisodeEvidence {
|
|
15
|
+
user: string;
|
|
16
|
+
assistant: string;
|
|
17
|
+
tools: string[];
|
|
18
|
+
}
|
|
19
|
+
export type InlineAtomEpisodeState = 'open' | 'closed';
|
|
20
|
+
export type InlineAtomDistillationState = 'pending' | 'learned' | 'skipped';
|
|
21
|
+
export interface InlineAtomEpisode {
|
|
22
|
+
id: string;
|
|
23
|
+
atom: string;
|
|
24
|
+
state: InlineAtomEpisodeState;
|
|
25
|
+
friction: string;
|
|
26
|
+
query: string;
|
|
27
|
+
endpoint?: string;
|
|
28
|
+
trigger: InlineAtomEpisodeEvidence;
|
|
29
|
+
closure?: InlineAtomEpisodeEvidence;
|
|
30
|
+
openedAt: string;
|
|
31
|
+
updatedAt: string;
|
|
32
|
+
closedAt?: string;
|
|
33
|
+
distillation: InlineAtomDistillationState;
|
|
34
|
+
distillationReason?: string;
|
|
35
|
+
distilledAt?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface InlineAtomEpisodeStore {
|
|
38
|
+
version: string;
|
|
39
|
+
episodes: InlineAtomEpisode[];
|
|
40
|
+
}
|
|
41
|
+
export interface InlineAtomReplayRecord {
|
|
42
|
+
atom: string;
|
|
43
|
+
injection: string;
|
|
44
|
+
status: string;
|
|
45
|
+
replayedAt: string;
|
|
46
|
+
}
|
|
47
|
+
export interface InlineAtomDistillation {
|
|
48
|
+
worthy: boolean;
|
|
49
|
+
injection?: string;
|
|
50
|
+
triggers?: string[];
|
|
51
|
+
reason?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ApplyInlineAtomObservationResult {
|
|
54
|
+
opened: InlineAtomEpisode[];
|
|
55
|
+
closed: InlineAtomEpisode[];
|
|
56
|
+
replayWorked: number;
|
|
57
|
+
replayFailed: number;
|
|
58
|
+
}
|
|
59
|
+
export declare function inlineAtomEpisodePath(projectId: string, sessionId?: string | null): string;
|
|
60
|
+
export declare function inlineAtomReplayPath(projectId: string, sessionId?: string | null): string;
|
|
61
|
+
export declare function readInlineAtomEpisodeStore(projectId: string, sessionId?: string | null): InlineAtomEpisodeStore;
|
|
62
|
+
export declare function readOpenInlineAtomEpisodes(projectId: string, sessionId?: string | null): InlineAtomEpisode[];
|
|
63
|
+
export declare function readPendingInlineAtomDistillations(projectId: string, sessionId?: string | null): InlineAtomEpisode[];
|
|
64
|
+
export declare function applyInlineAtomEpisodeObservations(params: {
|
|
65
|
+
projectId: string;
|
|
66
|
+
sessionId?: string | null;
|
|
67
|
+
observations: InlineAtomEpisodeObservation[];
|
|
68
|
+
evidence: InlineAtomEpisodeEvidence;
|
|
69
|
+
}): ApplyInlineAtomObservationResult;
|
|
70
|
+
export declare function writeInlineAtomReplayRecords(projectId: string, sessionId: string | null | undefined, schemas: InlineAtomSchema[]): void;
|
|
71
|
+
export declare function readAndClearInlineAtomReplayRecords(projectId: string, sessionId?: string | null): InlineAtomReplayRecord[];
|
|
72
|
+
export declare function applyInlineAtomDistillation(projectId: string, sessionId: string | null | undefined, episodeIdToApply: string, distillation: InlineAtomDistillation): 'learned' | 'skipped' | 'invalid' | 'missing';
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** Inline-Atom episode journal and artifact lifecycle reducer.
|
|
3
|
+
* adr: adr/capture-episodes.md */
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.inlineAtomEpisodePath = inlineAtomEpisodePath;
|
|
39
|
+
exports.inlineAtomReplayPath = inlineAtomReplayPath;
|
|
40
|
+
exports.readInlineAtomEpisodeStore = readInlineAtomEpisodeStore;
|
|
41
|
+
exports.readOpenInlineAtomEpisodes = readOpenInlineAtomEpisodes;
|
|
42
|
+
exports.readPendingInlineAtomDistillations = readPendingInlineAtomDistillations;
|
|
43
|
+
exports.applyInlineAtomEpisodeObservations = applyInlineAtomEpisodeObservations;
|
|
44
|
+
exports.writeInlineAtomReplayRecords = writeInlineAtomReplayRecords;
|
|
45
|
+
exports.readAndClearInlineAtomReplayRecords = readAndClearInlineAtomReplayRecords;
|
|
46
|
+
exports.applyInlineAtomDistillation = applyInlineAtomDistillation;
|
|
47
|
+
const crypto_1 = require("crypto");
|
|
48
|
+
const fs = __importStar(require("fs"));
|
|
49
|
+
const path = __importStar(require("path"));
|
|
50
|
+
const inline_atom_1 = require("./inline-atom");
|
|
51
|
+
const STORE_VERSION = '1';
|
|
52
|
+
const MAX_EPISODES = 24;
|
|
53
|
+
const MAX_OPEN_EPISODES = 3;
|
|
54
|
+
function stateDir() {
|
|
55
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
56
|
+
return path.join(home, '.greprag', 'state');
|
|
57
|
+
}
|
|
58
|
+
function safeId(s) {
|
|
59
|
+
return s.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 160);
|
|
60
|
+
}
|
|
61
|
+
function oneLine(s) {
|
|
62
|
+
return (s || '').replace(/\s+/g, ' ').trim();
|
|
63
|
+
}
|
|
64
|
+
function sessionSuffix(sessionId) {
|
|
65
|
+
return sessionId ? `-${safeId(sessionId)}` : '';
|
|
66
|
+
}
|
|
67
|
+
function inlineAtomEpisodePath(projectId, sessionId) {
|
|
68
|
+
return path.join(stateDir(), `inline-atom-episodes-${safeId(projectId)}${sessionSuffix(sessionId)}.json`);
|
|
69
|
+
}
|
|
70
|
+
function inlineAtomReplayPath(projectId, sessionId) {
|
|
71
|
+
return path.join(stateDir(), `inline-atom-replay-${safeId(projectId)}${sessionSuffix(sessionId)}.json`);
|
|
72
|
+
}
|
|
73
|
+
function boundedEvidence(evidence) {
|
|
74
|
+
return {
|
|
75
|
+
user: oneLine(evidence.user).slice(0, 1_800),
|
|
76
|
+
assistant: oneLine(evidence.assistant).slice(0, 3_200),
|
|
77
|
+
tools: (evidence.tools || []).map(oneLine).filter(Boolean).slice(0, 8).map(t => t.slice(0, 300)),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function episodeId(atom, evidence) {
|
|
81
|
+
return (0, crypto_1.createHash)('sha256')
|
|
82
|
+
.update(`${atom.toLowerCase()}\0${evidence.user}\0${evidence.assistant}\0${evidence.tools.join('\0')}`)
|
|
83
|
+
.digest('hex')
|
|
84
|
+
.slice(0, 20);
|
|
85
|
+
}
|
|
86
|
+
function writeEpisodeStore(projectId, sessionId, store) {
|
|
87
|
+
const file = inlineAtomEpisodePath(projectId, sessionId);
|
|
88
|
+
const dir = path.dirname(file);
|
|
89
|
+
if (!fs.existsSync(dir))
|
|
90
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
91
|
+
const open = store.episodes.filter(e => e.state === 'open');
|
|
92
|
+
const closed = store.episodes.filter(e => e.state === 'closed')
|
|
93
|
+
.slice(-(MAX_EPISODES - Math.min(open.length, MAX_EPISODES)));
|
|
94
|
+
const episodes = [...closed, ...open]
|
|
95
|
+
.sort((a, b) => a.openedAt.localeCompare(b.openedAt))
|
|
96
|
+
.slice(-MAX_EPISODES);
|
|
97
|
+
fs.writeFileSync(file, JSON.stringify({ version: STORE_VERSION, episodes }, null, 2) + '\n');
|
|
98
|
+
}
|
|
99
|
+
function legacyRecords(projectId, sessionId) {
|
|
100
|
+
const files = [
|
|
101
|
+
(0, inline_atom_1.inlineAtomPendingPath)(projectId, sessionId),
|
|
102
|
+
sessionId ? (0, inline_atom_1.inlineAtomPendingPath)(projectId, null) : null,
|
|
103
|
+
].filter((p) => !!p);
|
|
104
|
+
const records = [];
|
|
105
|
+
const found = [];
|
|
106
|
+
for (const file of files) {
|
|
107
|
+
try {
|
|
108
|
+
const raw = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
109
|
+
if (Array.isArray(raw.records))
|
|
110
|
+
records.push(...raw.records);
|
|
111
|
+
found.push(file);
|
|
112
|
+
}
|
|
113
|
+
catch { /* missing/corrupt legacy file */ }
|
|
114
|
+
}
|
|
115
|
+
return { records, files: found };
|
|
116
|
+
}
|
|
117
|
+
function readInlineAtomEpisodeStore(projectId, sessionId) {
|
|
118
|
+
let store = { version: STORE_VERSION, episodes: [] };
|
|
119
|
+
try {
|
|
120
|
+
const parsed = JSON.parse(fs.readFileSync(inlineAtomEpisodePath(projectId, sessionId), 'utf-8'));
|
|
121
|
+
if (parsed && Array.isArray(parsed.episodes)) {
|
|
122
|
+
store = { version: parsed.version || STORE_VERSION, episodes: parsed.episodes };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch { /* missing/corrupt = empty */ }
|
|
126
|
+
const legacy = legacyRecords(projectId, sessionId);
|
|
127
|
+
let migrated = false;
|
|
128
|
+
for (const record of legacy.records) {
|
|
129
|
+
if (store.episodes.some(e => e.state === 'open' && e.atom.toLowerCase() === record.atom.toLowerCase()))
|
|
130
|
+
continue;
|
|
131
|
+
const evidence = boundedEvidence({ user: '', assistant: '', tools: [] });
|
|
132
|
+
store.episodes.push({
|
|
133
|
+
id: episodeId(`${record.atom}:${record.createdAt}`, evidence),
|
|
134
|
+
atom: record.atom,
|
|
135
|
+
state: 'open',
|
|
136
|
+
friction: record.reason,
|
|
137
|
+
query: record.query,
|
|
138
|
+
trigger: evidence,
|
|
139
|
+
openedAt: record.createdAt,
|
|
140
|
+
updatedAt: record.createdAt,
|
|
141
|
+
distillation: 'pending',
|
|
142
|
+
});
|
|
143
|
+
migrated = true;
|
|
144
|
+
}
|
|
145
|
+
if (migrated)
|
|
146
|
+
writeEpisodeStore(projectId, sessionId, store);
|
|
147
|
+
if (migrated) {
|
|
148
|
+
for (const file of legacy.files) {
|
|
149
|
+
try {
|
|
150
|
+
fs.unlinkSync(file);
|
|
151
|
+
}
|
|
152
|
+
catch { /* already gone */ }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return store;
|
|
156
|
+
}
|
|
157
|
+
function readOpenInlineAtomEpisodes(projectId, sessionId) {
|
|
158
|
+
return readInlineAtomEpisodeStore(projectId, sessionId).episodes.filter(e => e.state === 'open');
|
|
159
|
+
}
|
|
160
|
+
function readPendingInlineAtomDistillations(projectId, sessionId) {
|
|
161
|
+
return readInlineAtomEpisodeStore(projectId, sessionId).episodes
|
|
162
|
+
.filter(e => e.state === 'closed' && e.distillation === 'pending' && !!e.endpoint && !!e.closure);
|
|
163
|
+
}
|
|
164
|
+
function openIndex(episodes, atom) {
|
|
165
|
+
const key = atom.toLowerCase();
|
|
166
|
+
for (let i = episodes.length - 1; i >= 0; i--) {
|
|
167
|
+
if (episodes[i].state === 'open' && episodes[i].atom.toLowerCase() === key)
|
|
168
|
+
return i;
|
|
169
|
+
}
|
|
170
|
+
return -1;
|
|
171
|
+
}
|
|
172
|
+
function applyReplayOutcomes(projectId, observations) {
|
|
173
|
+
let store = (0, inline_atom_1.readInlineAtomSchemaStore)(projectId);
|
|
174
|
+
let changed = false;
|
|
175
|
+
let worked = 0;
|
|
176
|
+
let failed = 0;
|
|
177
|
+
for (const observation of observations) {
|
|
178
|
+
if (observation.replay !== 'worked' && observation.replay !== 'failed')
|
|
179
|
+
continue;
|
|
180
|
+
const schema = store.schemas.find(s => s.atom.toLowerCase() === observation.atom.toLowerCase());
|
|
181
|
+
if (!schema)
|
|
182
|
+
continue;
|
|
183
|
+
const status = observation.replay === 'worked' ? 'confirmed' : 'stale';
|
|
184
|
+
if (schema.status === status)
|
|
185
|
+
continue;
|
|
186
|
+
store = (0, inline_atom_1.upsertInlineAtomSchema)(store, { ...schema, status });
|
|
187
|
+
changed = true;
|
|
188
|
+
if (observation.replay === 'worked')
|
|
189
|
+
worked++;
|
|
190
|
+
else
|
|
191
|
+
failed++;
|
|
192
|
+
}
|
|
193
|
+
if (changed)
|
|
194
|
+
(0, inline_atom_1.writeInlineAtomSchemaStore)(projectId, store);
|
|
195
|
+
return { worked, failed };
|
|
196
|
+
}
|
|
197
|
+
function applyInlineAtomEpisodeObservations(params) {
|
|
198
|
+
const evidence = boundedEvidence(params.evidence);
|
|
199
|
+
const store = readInlineAtomEpisodeStore(params.projectId, params.sessionId);
|
|
200
|
+
const opened = [];
|
|
201
|
+
const closed = [];
|
|
202
|
+
const replay = applyReplayOutcomes(params.projectId, params.observations);
|
|
203
|
+
let changed = false;
|
|
204
|
+
const now = new Date().toISOString();
|
|
205
|
+
for (const observation of params.observations) {
|
|
206
|
+
const atom = oneLine(observation.atom).slice(0, 120);
|
|
207
|
+
if (!atom)
|
|
208
|
+
continue;
|
|
209
|
+
let disposition = observation.episode;
|
|
210
|
+
if (observation.replay === 'failed' && disposition === 'ignore')
|
|
211
|
+
disposition = 'open';
|
|
212
|
+
const existingIndex = openIndex(store.episodes, atom);
|
|
213
|
+
if (disposition === 'open') {
|
|
214
|
+
if (existingIndex >= 0) {
|
|
215
|
+
const existing = store.episodes[existingIndex];
|
|
216
|
+
const friction = oneLine(observation.friction || existing.friction).slice(0, 240);
|
|
217
|
+
const query = oneLine(observation.query || existing.query).slice(0, 240);
|
|
218
|
+
if (friction !== existing.friction || query !== existing.query) {
|
|
219
|
+
store.episodes[existingIndex] = { ...existing, friction, query, updatedAt: now };
|
|
220
|
+
changed = true;
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (store.episodes.filter(e => e.state === 'open').length >= MAX_OPEN_EPISODES)
|
|
225
|
+
continue;
|
|
226
|
+
const friction = oneLine(observation.friction || (observation.replay === 'failed' ? 'replayed schema did not resolve the atom' : '')).slice(0, 240);
|
|
227
|
+
if (!friction)
|
|
228
|
+
continue;
|
|
229
|
+
const episode = {
|
|
230
|
+
id: episodeId(atom, evidence),
|
|
231
|
+
atom,
|
|
232
|
+
state: 'open',
|
|
233
|
+
friction,
|
|
234
|
+
query: oneLine(observation.query || `${atom} friction solution`).slice(0, 240),
|
|
235
|
+
trigger: evidence,
|
|
236
|
+
openedAt: now,
|
|
237
|
+
updatedAt: now,
|
|
238
|
+
distillation: 'pending',
|
|
239
|
+
};
|
|
240
|
+
if (!store.episodes.some(e => e.id === episode.id)) {
|
|
241
|
+
store.episodes.push(episode);
|
|
242
|
+
opened.push(episode);
|
|
243
|
+
changed = true;
|
|
244
|
+
}
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (disposition === 'close') {
|
|
248
|
+
const endpoint = oneLine(observation.endpoint || '').slice(0, 700);
|
|
249
|
+
if (!endpoint)
|
|
250
|
+
continue;
|
|
251
|
+
if (existingIndex >= 0) {
|
|
252
|
+
const existing = store.episodes[existingIndex];
|
|
253
|
+
const episode = {
|
|
254
|
+
...existing,
|
|
255
|
+
state: 'closed',
|
|
256
|
+
friction: oneLine(observation.friction || existing.friction).slice(0, 240),
|
|
257
|
+
endpoint,
|
|
258
|
+
closure: evidence,
|
|
259
|
+
updatedAt: now,
|
|
260
|
+
closedAt: now,
|
|
261
|
+
distillation: 'pending',
|
|
262
|
+
};
|
|
263
|
+
store.episodes[existingIndex] = episode;
|
|
264
|
+
closed.push(episode);
|
|
265
|
+
changed = true;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const friction = oneLine(observation.friction || '').slice(0, 240);
|
|
269
|
+
if (!friction)
|
|
270
|
+
continue;
|
|
271
|
+
const episode = {
|
|
272
|
+
id: episodeId(atom, evidence),
|
|
273
|
+
atom,
|
|
274
|
+
state: 'closed',
|
|
275
|
+
friction,
|
|
276
|
+
query: oneLine(observation.query || `${atom} friction solution`).slice(0, 240),
|
|
277
|
+
endpoint,
|
|
278
|
+
trigger: evidence,
|
|
279
|
+
closure: evidence,
|
|
280
|
+
openedAt: now,
|
|
281
|
+
updatedAt: now,
|
|
282
|
+
closedAt: now,
|
|
283
|
+
distillation: 'pending',
|
|
284
|
+
};
|
|
285
|
+
if (!store.episodes.some(e => e.id === episode.id)) {
|
|
286
|
+
store.episodes.push(episode);
|
|
287
|
+
closed.push(episode);
|
|
288
|
+
changed = true;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (changed)
|
|
293
|
+
writeEpisodeStore(params.projectId, params.sessionId, store);
|
|
294
|
+
if (opened.length > 0) {
|
|
295
|
+
(0, inline_atom_1.writeInlineAtomFrictionRecords)(params.projectId, params.sessionId, opened.map(e => ({ atom: e.atom, reason: e.friction, query: e.query, createdAt: e.openedAt })));
|
|
296
|
+
}
|
|
297
|
+
return { opened, closed, replayWorked: replay.worked, replayFailed: replay.failed };
|
|
298
|
+
}
|
|
299
|
+
function writeInlineAtomReplayRecords(projectId, sessionId, schemas) {
|
|
300
|
+
if (schemas.length === 0)
|
|
301
|
+
return;
|
|
302
|
+
const file = inlineAtomReplayPath(projectId, sessionId);
|
|
303
|
+
const dir = path.dirname(file);
|
|
304
|
+
if (!fs.existsSync(dir))
|
|
305
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
306
|
+
const now = new Date().toISOString();
|
|
307
|
+
const records = schemas.slice(0, 3).map(schema => ({
|
|
308
|
+
atom: schema.atom,
|
|
309
|
+
injection: schema.injection,
|
|
310
|
+
status: schema.status,
|
|
311
|
+
replayedAt: now,
|
|
312
|
+
}));
|
|
313
|
+
fs.writeFileSync(file, JSON.stringify({ records }, null, 2) + '\n');
|
|
314
|
+
}
|
|
315
|
+
function readAndClearInlineAtomReplayRecords(projectId, sessionId) {
|
|
316
|
+
const files = [
|
|
317
|
+
inlineAtomReplayPath(projectId, sessionId),
|
|
318
|
+
sessionId ? inlineAtomReplayPath(projectId, null) : null,
|
|
319
|
+
].filter((p) => !!p);
|
|
320
|
+
const records = [];
|
|
321
|
+
for (const file of files) {
|
|
322
|
+
try {
|
|
323
|
+
const raw = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
324
|
+
if (Array.isArray(raw.records))
|
|
325
|
+
records.push(...raw.records);
|
|
326
|
+
}
|
|
327
|
+
catch { /* missing/corrupt = silent */ }
|
|
328
|
+
try {
|
|
329
|
+
fs.unlinkSync(file);
|
|
330
|
+
}
|
|
331
|
+
catch { /* already gone */ }
|
|
332
|
+
}
|
|
333
|
+
const unique = new Map(records.map(r => [r.atom.toLowerCase(), r]));
|
|
334
|
+
return [...unique.values()].slice(0, 3);
|
|
335
|
+
}
|
|
336
|
+
function applyInlineAtomDistillation(projectId, sessionId, episodeIdToApply, distillation) {
|
|
337
|
+
const store = readInlineAtomEpisodeStore(projectId, sessionId);
|
|
338
|
+
const index = store.episodes.findIndex(e => e.id === episodeIdToApply && e.state === 'closed');
|
|
339
|
+
if (index < 0)
|
|
340
|
+
return 'missing';
|
|
341
|
+
const episode = store.episodes[index];
|
|
342
|
+
const now = new Date().toISOString();
|
|
343
|
+
if (!distillation.worthy) {
|
|
344
|
+
store.episodes[index] = {
|
|
345
|
+
...episode,
|
|
346
|
+
distillation: 'skipped',
|
|
347
|
+
distillationReason: oneLine(distillation.reason || 'not durable').slice(0, 180),
|
|
348
|
+
distilledAt: now,
|
|
349
|
+
updatedAt: now,
|
|
350
|
+
};
|
|
351
|
+
writeEpisodeStore(projectId, sessionId, store);
|
|
352
|
+
return 'skipped';
|
|
353
|
+
}
|
|
354
|
+
const injection = oneLine(distillation.injection || '').slice(0, 500);
|
|
355
|
+
if (!injection || injection.includes('[REDACTED:'))
|
|
356
|
+
return 'invalid';
|
|
357
|
+
const triggers = [episode.atom, ...(distillation.triggers || [])]
|
|
358
|
+
.map(t => oneLine(t).replace(/^`|`$/g, '').slice(0, 120))
|
|
359
|
+
.filter(Boolean);
|
|
360
|
+
const uniqueTriggers = [...new Map(triggers.map(t => [t.toLowerCase(), t])).values()].slice(0, 8);
|
|
361
|
+
let schemaStore = (0, inline_atom_1.readInlineAtomSchemaStore)(projectId);
|
|
362
|
+
schemaStore = (0, inline_atom_1.upsertInlineAtomSchema)(schemaStore, {
|
|
363
|
+
atom: episode.atom,
|
|
364
|
+
triggers: uniqueTriggers,
|
|
365
|
+
injection,
|
|
366
|
+
status: 'learned',
|
|
367
|
+
source: 'episode-distiller',
|
|
368
|
+
});
|
|
369
|
+
(0, inline_atom_1.writeInlineAtomSchemaStore)(projectId, schemaStore);
|
|
370
|
+
store.episodes[index] = {
|
|
371
|
+
...episode,
|
|
372
|
+
distillation: 'learned',
|
|
373
|
+
distillationReason: oneLine(distillation.reason || '').slice(0, 180) || undefined,
|
|
374
|
+
distilledAt: now,
|
|
375
|
+
updatedAt: now,
|
|
376
|
+
};
|
|
377
|
+
writeEpisodeStore(projectId, sessionId, store);
|
|
378
|
+
return 'learned';
|
|
379
|
+
}
|
|
380
|
+
//# sourceMappingURL=inline-atom-episode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-atom-episode.js","sourceRoot":"","sources":["../src/inline-atom-episode.ts"],"names":[],"mappings":";AAAA;kCACkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGlC,sDAKC;AAED,oDAKC;AAsDD,gEAqCC;AAED,gEAKC;AAED,gFAMC;AAiCD,gFA6GC;AAED,oEAiBC;AAED,kFAkBC;AAED,kEAiDC;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AI,SAAS;QACjF,WAAW,EAAE,GAAG;QAChB,SAAS,EAAE,GAAG;KACf,CAAC;IACF,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface InlineAtomHookConfig {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
}
|
|
5
|
+
interface InlineAtomProject {
|
|
6
|
+
projectId: string;
|
|
7
|
+
projectName: string;
|
|
8
|
+
}
|
|
9
|
+
interface InlineAtomToolCall {
|
|
10
|
+
name: string;
|
|
11
|
+
target?: string;
|
|
12
|
+
brief?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function observeInlineAtoms(cfg: InlineAtomHookConfig, anchor: InlineAtomProject, sessionId: string | undefined, userPrompt: string, agentResponse: string, toolCalls: InlineAtomToolCall[]): Promise<void>;
|
|
15
|
+
export declare function buildPendingInlineAtomContext(input: {
|
|
16
|
+
cwd?: string;
|
|
17
|
+
prompt?: string;
|
|
18
|
+
}, short: string): string | null;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.observeInlineAtoms = observeInlineAtoms;
|
|
4
|
+
exports.buildPendingInlineAtomContext = buildPendingInlineAtomContext;
|
|
5
|
+
const project_anchor_1 = require("./project-anchor");
|
|
6
|
+
const session_id_1 = require("./session-id");
|
|
7
|
+
const inline_atom_1 = require("./inline-atom");
|
|
8
|
+
const inline_atom_episode_1 = require("./inline-atom-episode");
|
|
9
|
+
async function observeInlineAtoms(cfg, anchor, sessionId, userPrompt, agentResponse, toolCalls) {
|
|
10
|
+
// Provider policy:
|
|
11
|
+
// - auto/greprag: portable command-hook path, costed to GrepRAG Flash-Lite.
|
|
12
|
+
// - harness: reserved for Claude Code's native Haiku prompt-hook bridge. Until
|
|
13
|
+
// that bridge can write the same local state file, fall back to GrepRAG.
|
|
14
|
+
// - off: disable the detector.
|
|
15
|
+
const provider = (process.env.GREPRAG_INLINE_ATOM_JUDGE || 'auto').toLowerCase();
|
|
16
|
+
if (provider === 'off')
|
|
17
|
+
return;
|
|
18
|
+
const short = (0, session_id_1.truncateSessionId)(sessionId) || null;
|
|
19
|
+
const atoms = (0, inline_atom_1.mergeInlineAtoms)(userPrompt, agentResponse);
|
|
20
|
+
const openEpisodes = (0, inline_atom_episode_1.readOpenInlineAtomEpisodes)(anchor.projectId, short);
|
|
21
|
+
const replayedSchemas = (0, inline_atom_episode_1.readAndClearInlineAtomReplayRecords)(anchor.projectId, short);
|
|
22
|
+
const evidence = {
|
|
23
|
+
user: userPrompt,
|
|
24
|
+
assistant: agentResponse,
|
|
25
|
+
tools: toolCalls.slice(0, 8).map(tc => [tc.name, tc.target, tc.brief].filter((v) => !!v).join(': ')),
|
|
26
|
+
};
|
|
27
|
+
if (atoms.length > 0 || openEpisodes.length > 0 || replayedSchemas.length > 0) {
|
|
28
|
+
try {
|
|
29
|
+
const res = await fetch(`${cfg.apiUrl}/v1/inline-atom/${anchor.projectId}/judge`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { 'Authorization': `Bearer ${cfg.apiKey}`, 'Content-Type': 'application/json' },
|
|
32
|
+
body: JSON.stringify({
|
|
33
|
+
projectName: anchor.projectName,
|
|
34
|
+
user: userPrompt,
|
|
35
|
+
assistant: agentResponse,
|
|
36
|
+
atoms,
|
|
37
|
+
openEpisodes: openEpisodes.map(e => ({ atom: e.atom, friction: e.friction })),
|
|
38
|
+
replayedSchemas,
|
|
39
|
+
provider: provider === 'harness' ? 'greprag-fallback' : 'greprag',
|
|
40
|
+
}),
|
|
41
|
+
});
|
|
42
|
+
if (res.ok) {
|
|
43
|
+
const data = await res.json();
|
|
44
|
+
const observations = Array.isArray(data.observations) ? data.observations : [];
|
|
45
|
+
(0, inline_atom_episode_1.applyInlineAtomEpisodeObservations)({
|
|
46
|
+
projectId: anchor.projectId,
|
|
47
|
+
sessionId: short,
|
|
48
|
+
observations,
|
|
49
|
+
evidence,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch { /* episode observation is best-effort */ }
|
|
54
|
+
}
|
|
55
|
+
for (const episode of (0, inline_atom_episode_1.readPendingInlineAtomDistillations)(anchor.projectId, short).slice(0, 3)) {
|
|
56
|
+
try {
|
|
57
|
+
const res = await fetch(`${cfg.apiUrl}/v1/inline-atom/${anchor.projectId}/distill`, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: { 'Authorization': `Bearer ${cfg.apiKey}`, 'Content-Type': 'application/json' },
|
|
60
|
+
body: JSON.stringify({ projectName: anchor.projectName, episode }),
|
|
61
|
+
});
|
|
62
|
+
if (!res.ok)
|
|
63
|
+
continue;
|
|
64
|
+
const data = await res.json();
|
|
65
|
+
if (data.distillation) {
|
|
66
|
+
(0, inline_atom_episode_1.applyInlineAtomDistillation)(anchor.projectId, short, episode.id, data.distillation);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch { /* closure distillation retries on a later Stop */ }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function buildPendingInlineAtomContext(input, short) {
|
|
73
|
+
try {
|
|
74
|
+
const anchor = (0, project_anchor_1.readAnchor)(input.cwd || process.cwd());
|
|
75
|
+
if (!anchor.projectId)
|
|
76
|
+
return null;
|
|
77
|
+
const records = (0, inline_atom_1.readAndClearInlineAtomFriction)(anchor.projectId, short);
|
|
78
|
+
const prompt = typeof input.prompt === 'string' ? input.prompt : '';
|
|
79
|
+
const prepared = (0, inline_atom_1.prepareInlineAtomContext)({ projectId: anchor.projectId, prompt, records });
|
|
80
|
+
if (prepared.schemas.length > 0) {
|
|
81
|
+
(0, inline_atom_episode_1.writeInlineAtomReplayRecords)(anchor.projectId, short, prepared.schemas);
|
|
82
|
+
}
|
|
83
|
+
return prepared.text;
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=inline-atom-hook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-atom-hook.js","sourceRoot":"","sources":["../src/inline-atom-hook.ts"],"names":[],"mappings":";;AAoCA,gDAsEC;AAED,sEAiBC;AA7HD,qDAA8C;AAC9C,6CAAiD;AACjD,+CAIuB;AACvB,+DAS+B;AAoBxB,KAAK,UAAU,kBAAkB,CACtC,GAAyB,EACzB,MAAyB,EACzB,SAA6B,EAC7B,UAAkB,EAClB,aAAqB,EACrB,SAA+B;IAE/B,mBAAmB;IACnB,4EAA4E;IAC5E,+EAA+E;IAC/E,2EAA2E;IAC3E,+BAA+B;IAC/B,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IACjF,IAAI,QAAQ,KAAK,KAAK;QAAE,OAAO;IAE/B,MAAM,KAAK,GAAG,IAAA,8BAAiB,EAAC,SAAS,CAAC,IAAI,IAAI,CAAC;IACnD,MAAM,KAAK,GAAG,IAAA,8BAAgB,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAC1D,MAAM,YAAY,GAAG,IAAA,gDAA0B,EAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzE,MAAM,eAAe,GAAG,IAAA,yDAAmC,EAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACrF,MAAM,QAAQ,GAAG;QACf,IAAI,EAAE,UAAU;QAChB,SAAS,EAAE,aAAa;QACxB,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CACpC,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK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AAC,SAAS;YAAE,OAAO,IAAI,CAAC;QACnC,MAAM,OAAO,GAAG,IAAA,4CAA8B,EAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAA,sCAAwB,EAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;QAC5F,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,IAAA,kDAA4B,EAAC,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/inline-atom.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
/** Inline-Atom
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
export interface InlineAtomVerdict {
|
|
5
|
-
atom: string;
|
|
6
|
-
label: InlineAtomLabel;
|
|
7
|
-
reason?: string;
|
|
8
|
-
query?: string;
|
|
9
|
-
schema?: string;
|
|
10
|
-
}
|
|
1
|
+
/** Inline-Atom Episode Capture — detector, schema registry, and injection.
|
|
2
|
+
* Episode lifecycle state lives in inline-atom-episode.ts.
|
|
3
|
+
* adr: adr/capture-episodes.md */
|
|
11
4
|
export interface InlineAtomFrictionRecord {
|
|
12
5
|
atom: string;
|
|
13
6
|
reason: string;
|
|
@@ -20,7 +13,7 @@ export interface InlineAtomSchema {
|
|
|
20
13
|
triggers: string[];
|
|
21
14
|
injection: string;
|
|
22
15
|
status: InlineAtomSchemaStatus;
|
|
23
|
-
source: 'seeded' | 'resolution-span' | 'operator';
|
|
16
|
+
source: 'seeded' | 'episode-distiller' | 'resolution-span' | 'operator';
|
|
24
17
|
createdAt: string;
|
|
25
18
|
updatedAt: string;
|
|
26
19
|
}
|
|
@@ -33,7 +26,7 @@ export declare function inlineAtomPendingPath(projectId: string, sessionId?: str
|
|
|
33
26
|
export declare function inlineAtomSchemaPath(projectId: string): string;
|
|
34
27
|
export declare function extractInlineAtoms(text: string): string[];
|
|
35
28
|
export declare function mergeInlineAtoms(...texts: string[]): string[];
|
|
36
|
-
export declare function
|
|
29
|
+
export declare function writeInlineAtomFrictionRecords(projectId: string, sessionId: string | null | undefined, records: InlineAtomFrictionRecord[]): void;
|
|
37
30
|
export declare function readAndClearInlineAtomFriction(projectId: string, sessionId?: string | null): InlineAtomFrictionRecord[];
|
|
38
31
|
export declare function readInlineAtomSchemaStore(projectId: string): InlineAtomSchemaStore;
|
|
39
32
|
export declare function writeInlineAtomSchemaStore(projectId: string, store: InlineAtomSchemaStore): void;
|
|
@@ -41,10 +34,17 @@ export declare function upsertInlineAtomSchema(store: InlineAtomSchemaStore, sch
|
|
|
41
34
|
createdAt?: string;
|
|
42
35
|
updatedAt?: string;
|
|
43
36
|
}): InlineAtomSchemaStore;
|
|
44
|
-
export declare function promoteInlineAtomResolutions(projectId: string, sessionId: string | null | undefined, verdicts: InlineAtomVerdict[]): number;
|
|
45
37
|
export declare function matchInlineAtomSchemas(prompt: string, store: InlineAtomSchemaStore): InlineAtomSchema[];
|
|
46
38
|
export declare function buildInlineAtomSchemaInjection(schemas: InlineAtomSchema[]): string | null;
|
|
47
39
|
export declare function buildInlineAtomFrictionInjection(records: InlineAtomFrictionRecord[]): string | null;
|
|
40
|
+
export declare function prepareInlineAtomContext(params: {
|
|
41
|
+
projectId: string;
|
|
42
|
+
prompt: string;
|
|
43
|
+
records: InlineAtomFrictionRecord[];
|
|
44
|
+
}): {
|
|
45
|
+
text: string | null;
|
|
46
|
+
schemas: InlineAtomSchema[];
|
|
47
|
+
};
|
|
48
48
|
export declare function buildInlineAtomContext(params: {
|
|
49
49
|
projectId: string;
|
|
50
50
|
prompt: string;
|