greprag 5.21.0 → 5.22.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.
- package/README.md +56 -13
- package/dist/codex-steering.d.ts +29 -0
- package/dist/codex-steering.js +168 -0
- package/dist/codex-steering.js.map +1 -0
- package/dist/commands/codex.d.ts +34 -0
- package/dist/commands/codex.js +490 -0
- package/dist/commands/codex.js.map +1 -0
- package/dist/commands/discover.d.ts +1 -1
- package/dist/commands/discover.js +1 -1
- package/dist/commands/doctor.js +3 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts +8 -2
- package/dist/commands/init.js +510 -79
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lore.d.ts +2 -0
- package/dist/commands/lore.js +83 -6
- package/dist/commands/lore.js.map +1 -1
- package/dist/commands/status.d.ts +22 -10
- package/dist/commands/status.js +159 -69
- package/dist/commands/status.js.map +1 -1
- package/dist/hook.js +120 -13
- package/dist/hook.js.map +1 -1
- package/dist/index.js +109 -25
- package/dist/index.js.map +1 -1
- package/dist/opencode-plugin.d.ts +2 -2
- package/dist/opencode-plugin.js +47 -14
- package/dist/opencode-plugin.js.map +1 -1
- package/dist/project-anchor.d.ts +11 -9
- package/dist/project-anchor.js +58 -27
- package/dist/project-anchor.js.map +1 -1
- package/package.json +4 -2
- package/scripts/postinstall.js +61 -46
- package/skill/greprag/SKILL.md +22 -4
- package/skill/greprag/docs/doctor.md +1 -1
- package/skill/greprag/docs/setup.md +98 -6
- package/skill/lore-advisor/SKILL.md +101 -43
package/dist/commands/status.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/** greprag status —
|
|
3
|
-
*
|
|
4
|
-
* Returns structured info about installation, auth, hooks, and the current
|
|
5
|
-
* project's anchor + flags. Pure local reads — no network. The agent calls
|
|
6
|
-
* this once and decides what setup steps (if any) the user needs.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* greprag status — human-readable
|
|
10
|
-
* greprag status --json — JSON for agent parsing */
|
|
2
|
+
/** greprag status — local install/auth/platform diagnostics. */
|
|
11
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
4
|
if (k2 === undefined) k2 = k;
|
|
13
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -48,41 +40,71 @@ const fs = __importStar(require("fs"));
|
|
|
48
40
|
const path = __importStar(require("path"));
|
|
49
41
|
const project_anchor_1 = require("../project-anchor");
|
|
50
42
|
const identity_1 = require("./identity");
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
return path.join(home, '.claude', 'settings.json');
|
|
43
|
+
function home() {
|
|
44
|
+
return process.env.HOME || process.env.USERPROFILE || '';
|
|
54
45
|
}
|
|
55
|
-
function
|
|
46
|
+
function claudeSettingsPath() {
|
|
47
|
+
return path.join(home(), '.claude', 'settings.json');
|
|
48
|
+
}
|
|
49
|
+
function grepragEnvPath() {
|
|
50
|
+
return path.join(home(), '.greprag', '.env');
|
|
51
|
+
}
|
|
52
|
+
function codexHooksPath() {
|
|
53
|
+
return path.join(home(), '.codex', 'hooks.json');
|
|
54
|
+
}
|
|
55
|
+
function readJson(file, fallback) {
|
|
56
56
|
try {
|
|
57
|
-
return JSON.parse(fs.readFileSync(
|
|
57
|
+
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
58
58
|
}
|
|
59
59
|
catch {
|
|
60
|
-
return
|
|
60
|
+
return fallback;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function readEnvFile(file) {
|
|
64
|
+
const out = {};
|
|
65
|
+
try {
|
|
66
|
+
for (const line of fs.readFileSync(file, 'utf-8').split(/\r?\n/)) {
|
|
67
|
+
const trimmed = line.trim();
|
|
68
|
+
if (!trimmed || trimmed.startsWith('#'))
|
|
69
|
+
continue;
|
|
70
|
+
const idx = trimmed.indexOf('=');
|
|
71
|
+
if (idx < 1)
|
|
72
|
+
continue;
|
|
73
|
+
let value = trimmed.slice(idx + 1).trim();
|
|
74
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
75
|
+
(value.startsWith("'") && value.endsWith("'")))
|
|
76
|
+
value = value.slice(1, -1);
|
|
77
|
+
out[trimmed.slice(0, idx).trim()] = value;
|
|
78
|
+
}
|
|
61
79
|
}
|
|
80
|
+
catch { /* missing env file */ }
|
|
81
|
+
return out;
|
|
62
82
|
}
|
|
63
|
-
function
|
|
64
|
-
if (!
|
|
83
|
+
function hasHook(configs, subcommand, matcher) {
|
|
84
|
+
if (!configs)
|
|
65
85
|
return false;
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
86
|
+
return configs.some(cfg => {
|
|
87
|
+
if (matcher !== undefined && (cfg.matcher ?? '') !== matcher)
|
|
88
|
+
return false;
|
|
89
|
+
return cfg.hooks?.some(h => {
|
|
90
|
+
const cmd = h.command || '';
|
|
91
|
+
return cmd.includes(`greprag-hook ${subcommand}`) || cmd.includes(`hook.js ${subcommand}`);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
71
94
|
}
|
|
72
|
-
|
|
73
|
-
* init / the skill). Fall back to process.env if not in settings yet. */
|
|
74
|
-
function getApiKey(settings) {
|
|
75
|
-
const fromSettings = settings.env?.GREPRAG_API_KEY;
|
|
76
|
-
if (fromSettings)
|
|
77
|
-
return fromSettings;
|
|
95
|
+
function apiKeyFromSources(settings) {
|
|
78
96
|
if (process.env.GREPRAG_API_KEY)
|
|
79
|
-
return process.env.GREPRAG_API_KEY;
|
|
80
|
-
|
|
97
|
+
return { key: process.env.GREPRAG_API_KEY, source: 'env' };
|
|
98
|
+
const shared = readEnvFile(grepragEnvPath()).GREPRAG_API_KEY;
|
|
99
|
+
if (shared)
|
|
100
|
+
return { key: shared, source: grepragEnvPath() };
|
|
101
|
+
const claude = settings.env?.GREPRAG_API_KEY;
|
|
102
|
+
if (claude)
|
|
103
|
+
return { key: claude, source: claudeSettingsPath() };
|
|
104
|
+
return { key: null, source: null };
|
|
81
105
|
}
|
|
82
106
|
function maskKey(key) {
|
|
83
|
-
|
|
84
|
-
return null;
|
|
85
|
-
return key.slice(0, 17) + '…'; // grp_live_ + 8 chars + ellipsis
|
|
107
|
+
return key ? key.slice(0, 17) + '...' : null;
|
|
86
108
|
}
|
|
87
109
|
function readVersion() {
|
|
88
110
|
try {
|
|
@@ -93,22 +115,49 @@ function readVersion() {
|
|
|
93
115
|
return 'unknown';
|
|
94
116
|
}
|
|
95
117
|
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
function platformFromArgs(args) {
|
|
119
|
+
if (args.includes('--claude'))
|
|
120
|
+
return 'claude';
|
|
121
|
+
if (args.includes('--codex'))
|
|
122
|
+
return 'codex';
|
|
123
|
+
if (args.includes('--opencode'))
|
|
124
|
+
return 'opencode';
|
|
125
|
+
if (args.includes('--all-platforms'))
|
|
126
|
+
return 'all';
|
|
127
|
+
return 'all';
|
|
128
|
+
}
|
|
129
|
+
function buildStatus(cwd, platform = 'all') {
|
|
130
|
+
const settingsPath = claudeSettingsPath();
|
|
131
|
+
const settings = readJson(settingsPath, {});
|
|
132
|
+
const codexHooks = readJson(codexHooksPath(), {});
|
|
133
|
+
const api = apiKeyFromSources(settings);
|
|
100
134
|
const anchor = (0, project_anchor_1.readAnchor)(cwd);
|
|
101
|
-
const
|
|
102
|
-
const identityCachePath = path.join(home, '.greprag', 'identity.json');
|
|
135
|
+
const identityCachePath = path.join(home(), '.greprag', 'identity.json');
|
|
103
136
|
const identityCache = (0, identity_1.readCache)(identityCachePath);
|
|
137
|
+
const codexSkillPath = path.join(home(), '.codex', 'skills', 'greprag');
|
|
138
|
+
const claudeSkillPath = path.join(home(), '.claude', 'skills', 'greprag');
|
|
139
|
+
const opencodePluginPath = path.join(home(), '.config', 'opencode', 'plugins', 'greprag-memory.js');
|
|
140
|
+
const claudeHooks = {
|
|
141
|
+
session_start_recap: hasHook(settings.hooks?.SessionStart, 'recap'),
|
|
142
|
+
stop_store: hasHook(settings.hooks?.Stop, 'store'),
|
|
143
|
+
pre_tool_use_spawn_check: hasHook(settings.hooks?.PreToolUse, 'pre-spawn-check'),
|
|
144
|
+
};
|
|
145
|
+
const codexHookStatus = {
|
|
146
|
+
session_start_recap: hasHook(codexHooks.hooks?.SessionStart, 'recap'),
|
|
147
|
+
session_id: hasHook(codexHooks.hooks?.SessionStart, 'session-id'),
|
|
148
|
+
user_prompt_submit: hasHook(codexHooks.hooks?.UserPromptSubmit, 'codex-notify'),
|
|
149
|
+
post_tool_use_inbox: hasHook(codexHooks.hooks?.PostToolUse, 'codex-inbox'),
|
|
150
|
+
stop_store: hasHook(codexHooks.hooks?.Stop, 'codex-store'),
|
|
151
|
+
post_compact_session_id: hasHook(codexHooks.hooks?.PostCompact, 'session-id'),
|
|
152
|
+
};
|
|
153
|
+
const opencodePluginInstalled = fs.existsSync(opencodePluginPath);
|
|
104
154
|
return {
|
|
105
155
|
installed: true,
|
|
106
156
|
version: readVersion(),
|
|
157
|
+
platform,
|
|
107
158
|
settings_path: settingsPath,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
key_prefix: maskKey(apiKey),
|
|
111
|
-
},
|
|
159
|
+
shared_env_path: grepragEnvPath(),
|
|
160
|
+
auth: { api_key_present: !!api.key, key_prefix: maskKey(api.key), source: api.source },
|
|
112
161
|
identity: {
|
|
113
162
|
handle: identityCache?.handle ?? null,
|
|
114
163
|
tenant_id: identityCache?.tenantId ?? null,
|
|
@@ -119,14 +168,39 @@ function buildStatus(cwd) {
|
|
|
119
168
|
: 'No identity cache. Run `greprag identity show` to populate.',
|
|
120
169
|
},
|
|
121
170
|
hooks: {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
171
|
+
...claudeHooks,
|
|
172
|
+
codex_user_prompt_submit: codexHookStatus.user_prompt_submit,
|
|
173
|
+
codex_post_tool_use_inbox: codexHookStatus.post_tool_use_inbox,
|
|
174
|
+
codex_stop_store: codexHookStatus.stop_store,
|
|
175
|
+
},
|
|
176
|
+
platforms: {
|
|
177
|
+
claude: {
|
|
178
|
+
configured: !!api.key && claudeHooks.session_start_recap && claudeHooks.stop_store,
|
|
179
|
+
config_path: settingsPath,
|
|
180
|
+
config_present: fs.existsSync(settingsPath),
|
|
181
|
+
skill_path: claudeSkillPath,
|
|
182
|
+
skill_installed: fs.existsSync(claudeSkillPath),
|
|
183
|
+
hooks: claudeHooks,
|
|
184
|
+
note: 'Claude Code uses command hooks plus Monitor for live inbox delivery.',
|
|
185
|
+
},
|
|
186
|
+
codex: {
|
|
187
|
+
configured: !!api.key && Object.values(codexHookStatus).every(Boolean),
|
|
188
|
+
config_path: codexHooksPath(),
|
|
189
|
+
config_present: fs.existsSync(codexHooksPath()),
|
|
190
|
+
skill_path: codexSkillPath,
|
|
191
|
+
skill_installed: fs.existsSync(codexSkillPath),
|
|
192
|
+
hooks: codexHookStatus,
|
|
193
|
+
trust_required: true,
|
|
194
|
+
note: 'Codex Desktop requires Settings -> Settings -> Hooks trust review; hooks.json existing does not prove hooks are active.',
|
|
195
|
+
},
|
|
196
|
+
opencode: {
|
|
197
|
+
configured: !!api.key && opencodePluginInstalled,
|
|
198
|
+
config_path: grepragEnvPath(),
|
|
199
|
+
config_present: fs.existsSync(grepragEnvPath()),
|
|
200
|
+
plugin_path: opencodePluginPath,
|
|
201
|
+
plugin_installed: opencodePluginInstalled,
|
|
202
|
+
note: 'OpenCode loads the GrepRAG plugin from its global plugin directory.',
|
|
203
|
+
},
|
|
130
204
|
},
|
|
131
205
|
project: {
|
|
132
206
|
cwd: path.resolve(cwd),
|
|
@@ -141,42 +215,58 @@ function buildStatus(cwd) {
|
|
|
141
215
|
},
|
|
142
216
|
};
|
|
143
217
|
}
|
|
218
|
+
function renderPlatform(name, p) {
|
|
219
|
+
const yes = (b) => b ? 'yes' : 'no';
|
|
220
|
+
const lines = [
|
|
221
|
+
`${name}:`,
|
|
222
|
+
` Configured: ${yes(p.configured)}`,
|
|
223
|
+
` Config: ${p.config_path} (${p.config_present ? 'present' : 'missing'})`,
|
|
224
|
+
];
|
|
225
|
+
if (p.skill_path)
|
|
226
|
+
lines.push(` Skill: ${p.skill_path} (${yes(p.skill_installed)})`);
|
|
227
|
+
if (p.plugin_path)
|
|
228
|
+
lines.push(` Plugin: ${p.plugin_path} (${yes(p.plugin_installed)})`);
|
|
229
|
+
if (p.hooks) {
|
|
230
|
+
lines.push(' Hooks:');
|
|
231
|
+
for (const [key, value] of Object.entries(p.hooks))
|
|
232
|
+
lines.push(` ${key}: ${yes(value)}`);
|
|
233
|
+
}
|
|
234
|
+
if (p.trust_required)
|
|
235
|
+
lines.push(' Trust: Codex Desktop: Settings -> Settings -> Hooks, then trust the 6 GrepRAG hooks');
|
|
236
|
+
return lines;
|
|
237
|
+
}
|
|
144
238
|
function renderHuman(s) {
|
|
145
|
-
const
|
|
239
|
+
const yes = (b) => b ? 'yes' : 'no';
|
|
240
|
+
const platformNames = s.platform === 'all' ? ['claude', 'codex', 'opencode'] : [s.platform];
|
|
146
241
|
return [
|
|
147
242
|
`greprag ${s.version}`,
|
|
148
|
-
`
|
|
243
|
+
`Shared env: ${s.shared_env_path}`,
|
|
149
244
|
``,
|
|
150
245
|
`Auth:`,
|
|
151
|
-
` API key present: ${
|
|
246
|
+
` API key present: ${yes(s.auth.api_key_present)}${s.auth.key_prefix ? ` (${s.auth.key_prefix})` : ''}`,
|
|
247
|
+
` Source: ${s.auth.source ?? '(none)'}`,
|
|
152
248
|
``,
|
|
153
249
|
`Identity:`,
|
|
154
|
-
` Handle: ${s.identity.handle ?? '(not cached
|
|
250
|
+
` Handle: ${s.identity.handle ?? '(not cached - run: greprag identity show)'}`,
|
|
155
251
|
` Aliases: ${s.identity.aliases.length ? s.identity.aliases.join(', ') : '(none)'}`,
|
|
156
252
|
``,
|
|
157
|
-
`
|
|
158
|
-
|
|
159
|
-
` Stop store: ${check(s.hooks.stop_store)}`,
|
|
160
|
-
` PreToolUse pre-spawn-check:${check(s.hooks.pre_tool_use_spawn_check)}`,
|
|
253
|
+
`Platforms:`,
|
|
254
|
+
...platformNames.flatMap(name => renderPlatform(name, s.platforms[name])),
|
|
161
255
|
``,
|
|
162
256
|
`Project (${s.project.cwd}):`,
|
|
163
|
-
` Anchor found: ${
|
|
257
|
+
` Anchor found: ${yes(s.project.anchor_found)}${s.project.is_deterministic_fallback ? ' (using deterministic-hash fallback)' : ''}`,
|
|
164
258
|
` Anchor path: ${s.project.anchor_path}`,
|
|
165
259
|
` Project name: ${s.project.project_name}`,
|
|
166
260
|
` Project ID: ${s.project.project_id}`,
|
|
167
|
-
` Memory capture: ${
|
|
168
|
-
` SessionStart recap: ${
|
|
261
|
+
` Memory capture: ${yes(s.project.memory_capture)}`,
|
|
262
|
+
` SessionStart recap: ${yes(s.project.session_start_recap)}`,
|
|
169
263
|
` Inbox notify: ${s.project.inbox_notify}`,
|
|
170
264
|
].join('\n');
|
|
171
265
|
}
|
|
172
266
|
async function runStatus(args) {
|
|
173
267
|
const json = args.includes('--json');
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
process.stdout.write(renderHuman(status) + '\n');
|
|
180
|
-
}
|
|
268
|
+
const platform = platformFromArgs(args);
|
|
269
|
+
const status = buildStatus(process.cwd(), platform);
|
|
270
|
+
process.stdout.write(json ? JSON.stringify(status, null, 2) + '\n' : renderHuman(status) + '\n');
|
|
181
271
|
}
|
|
182
272
|
//# sourceMappingURL=status.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":";AAAA,gEAAgE;;;;;;;;;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hook.js
CHANGED
|
@@ -50,6 +50,7 @@ const session_id_1 = require("./session-id");
|
|
|
50
50
|
// (skill bodies, continuation summaries, chip prompts) pre-LLM at capture and
|
|
51
51
|
// elide it so it never lands as a searchable turn node.
|
|
52
52
|
const turn_provenance_1 = require("./turn-provenance");
|
|
53
|
+
const codex_steering_1 = require("./codex-steering");
|
|
53
54
|
const API_URL_DEFAULT = 'https://api.greprag.com';
|
|
54
55
|
const MAX_FIELD_CHARS = 500_000; // safety cap per text field
|
|
55
56
|
// ---------- Env + config ---------------------------------------------------
|
|
@@ -77,8 +78,11 @@ function loadEnvFile(filePath) {
|
|
|
77
78
|
}
|
|
78
79
|
function ensureEnv(cwd) {
|
|
79
80
|
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
80
|
-
if (homeDir)
|
|
81
|
-
loadEnvFile(path.join(homeDir, '.env'));
|
|
81
|
+
if (homeDir) {
|
|
82
|
+
loadEnvFile(path.join(homeDir, '.greprag', '.env'));
|
|
83
|
+
if (!process.env.GREPRAG_API_KEY)
|
|
84
|
+
loadEnvFile(path.join(homeDir, '.env'));
|
|
85
|
+
}
|
|
82
86
|
if (!process.env.GREPRAG_API_KEY)
|
|
83
87
|
loadEnvFile(path.join(cwd, '.env'));
|
|
84
88
|
}
|
|
@@ -309,6 +313,67 @@ function parseLatestTurn(transcriptPath) {
|
|
|
309
313
|
provenance: (0, turn_provenance_1.classifyUserText)(userPrompt),
|
|
310
314
|
};
|
|
311
315
|
}
|
|
316
|
+
function codexCacheDir() {
|
|
317
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
318
|
+
if (!home)
|
|
319
|
+
return null;
|
|
320
|
+
return path.join(home, '.greprag', 'codex');
|
|
321
|
+
}
|
|
322
|
+
function promptCachePath(sessionId, turnId) {
|
|
323
|
+
const dir = codexCacheDir();
|
|
324
|
+
if (!dir || !sessionId)
|
|
325
|
+
return null;
|
|
326
|
+
const raw = turnId || sessionId;
|
|
327
|
+
const safe = raw.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 160);
|
|
328
|
+
return path.join(dir, `${safe}.json`);
|
|
329
|
+
}
|
|
330
|
+
function latestPromptCachePath(sessionId) {
|
|
331
|
+
const dir = codexCacheDir();
|
|
332
|
+
if (!dir || !sessionId)
|
|
333
|
+
return null;
|
|
334
|
+
const safe = sessionId.replace(/[^a-zA-Z0-9_.-]/g, '_').slice(0, 160);
|
|
335
|
+
return path.join(dir, `${safe}.latest.json`);
|
|
336
|
+
}
|
|
337
|
+
function cacheCodexPrompt(input) {
|
|
338
|
+
if (typeof input.prompt !== 'string' || !input.prompt.trim() || !input.session_id)
|
|
339
|
+
return;
|
|
340
|
+
const entry = {
|
|
341
|
+
sessionId: input.session_id,
|
|
342
|
+
turnId: input.turn_id || null,
|
|
343
|
+
prompt: input.prompt,
|
|
344
|
+
model: input.model || null,
|
|
345
|
+
cwd: input.cwd || process.cwd(),
|
|
346
|
+
createdAt: new Date().toISOString(),
|
|
347
|
+
};
|
|
348
|
+
const paths = [
|
|
349
|
+
promptCachePath(input.session_id, input.turn_id),
|
|
350
|
+
latestPromptCachePath(input.session_id),
|
|
351
|
+
].filter((p) => !!p);
|
|
352
|
+
for (const file of paths) {
|
|
353
|
+
try {
|
|
354
|
+
const dir = path.dirname(file);
|
|
355
|
+
if (!fs.existsSync(dir))
|
|
356
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
357
|
+
fs.writeFileSync(file, JSON.stringify(entry, null, 2) + '\n');
|
|
358
|
+
}
|
|
359
|
+
catch { /* prompt cache is best-effort */ }
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function readCodexPromptCache(input) {
|
|
363
|
+
const paths = [
|
|
364
|
+
promptCachePath(input.session_id, input.turn_id),
|
|
365
|
+
latestPromptCachePath(input.session_id),
|
|
366
|
+
].filter((p) => !!p);
|
|
367
|
+
for (const file of paths) {
|
|
368
|
+
try {
|
|
369
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
370
|
+
if (parsed && typeof parsed.prompt === 'string' && parsed.prompt.trim())
|
|
371
|
+
return parsed;
|
|
372
|
+
}
|
|
373
|
+
catch { /* try next */ }
|
|
374
|
+
}
|
|
375
|
+
return null;
|
|
376
|
+
}
|
|
312
377
|
/** Walk subagent transcripts under <session>/subagents/ and pull tool_use
|
|
313
378
|
* blocks that fired during the current turn. Returns flattened ToolCall[]
|
|
314
379
|
* augmented with _output where a matching tool_result exists in the same
|
|
@@ -677,7 +742,7 @@ function capField(text) {
|
|
|
677
742
|
return `${truncated}\n\n[truncated: original ${originalKb}KB]`;
|
|
678
743
|
}
|
|
679
744
|
// ---------- Store ---------------------------------------------------------
|
|
680
|
-
async function store(input) {
|
|
745
|
+
async function store(input, source = 'claude-code') {
|
|
681
746
|
const cwd = input.cwd || process.cwd();
|
|
682
747
|
const cfg = getConfig(cwd);
|
|
683
748
|
if (!cfg.enabled || !cfg.apiKey)
|
|
@@ -688,6 +753,18 @@ async function store(input) {
|
|
|
688
753
|
if (!anchor.memoryCapture)
|
|
689
754
|
return;
|
|
690
755
|
const turn = parseLatestTurn(input.transcript_path);
|
|
756
|
+
if (source === 'codex' && (!turn.userPrompt || !turn.agentResponse)) {
|
|
757
|
+
const cached = readCodexPromptCache(input);
|
|
758
|
+
if (!turn.userPrompt && cached) {
|
|
759
|
+
turn.userPrompt = cached.prompt;
|
|
760
|
+
turn.provenance = (0, turn_provenance_1.classifyUserText)(cached.prompt);
|
|
761
|
+
}
|
|
762
|
+
if (!turn.agentResponse && typeof input.last_assistant_message === 'string') {
|
|
763
|
+
turn.agentResponse = input.last_assistant_message.trim();
|
|
764
|
+
}
|
|
765
|
+
if (!turn.model)
|
|
766
|
+
turn.model = input.model || cached?.model || null;
|
|
767
|
+
}
|
|
691
768
|
// Flatten subagent tool_use blocks into the main turn so artifact detection
|
|
692
769
|
// catches commits/deploys/PRs a subagent fired. See adr/raw-turn-capture.md.
|
|
693
770
|
if (input.transcript_path && turn.userStartTime) {
|
|
@@ -738,7 +815,7 @@ async function store(input) {
|
|
|
738
815
|
filesTouched: turn.filesTouched,
|
|
739
816
|
artifacts: artifactRefs,
|
|
740
817
|
shipEvents,
|
|
741
|
-
source
|
|
818
|
+
source,
|
|
742
819
|
provenance,
|
|
743
820
|
});
|
|
744
821
|
}
|
|
@@ -1082,22 +1159,40 @@ async function isSessionArmed(apiUrl, apiKey, short) {
|
|
|
1082
1159
|
* here, so a separate SessionStart arm was pure redundancy). Reads only the
|
|
1083
1160
|
* watcher registry — no inbox content/count — so the v5.6.1 leak stays closed.
|
|
1084
1161
|
* Gated on greprag being configured. adr: adr/session-id-awareness.md */
|
|
1085
|
-
|
|
1162
|
+
function writeAdditionalContext(hookEventName, additionalContext) {
|
|
1163
|
+
process.stdout.write(JSON.stringify({
|
|
1164
|
+
hookSpecificOutput: {
|
|
1165
|
+
hookEventName,
|
|
1166
|
+
additionalContext,
|
|
1167
|
+
},
|
|
1168
|
+
}) + '\n');
|
|
1169
|
+
}
|
|
1170
|
+
async function codexInbox(input, debounce = true) {
|
|
1171
|
+
const cfg = getConfig(input.cwd || process.cwd());
|
|
1172
|
+
const context = await (0, codex_steering_1.buildCodexInboxSteering)(input, cfg, { debounce });
|
|
1173
|
+
if (!context)
|
|
1174
|
+
return;
|
|
1175
|
+
writeAdditionalContext(input.hook_event_name || 'PostToolUse', context);
|
|
1176
|
+
}
|
|
1177
|
+
async function notify(input, source = 'claude-code') {
|
|
1178
|
+
if (source === 'codex')
|
|
1179
|
+
cacheCodexPrompt(input);
|
|
1086
1180
|
const cfg = getConfig(input.cwd || process.cwd());
|
|
1087
1181
|
if (!cfg.enabled || !cfg.apiKey)
|
|
1088
1182
|
return; // unconfigured → silent
|
|
1089
1183
|
const short = (0, session_id_1.truncateSessionId)(input.session_id);
|
|
1090
1184
|
if (!short)
|
|
1091
1185
|
return; // no session id → silent
|
|
1186
|
+
if (source === 'codex') {
|
|
1187
|
+
const context = await (0, codex_steering_1.buildCodexInboxSteering)(input, cfg);
|
|
1188
|
+
if (context)
|
|
1189
|
+
writeAdditionalContext('UserPromptSubmit', context);
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1092
1192
|
const armed = await isSessionArmed(cfg.apiUrl, cfg.apiKey, short);
|
|
1093
1193
|
if (armed !== false)
|
|
1094
1194
|
return; // armed OR couldn't tell → silent
|
|
1095
|
-
|
|
1096
|
-
hookSpecificOutput: {
|
|
1097
|
-
hookEventName: 'UserPromptSubmit',
|
|
1098
|
-
additionalContext: (0, session_id_1.buildArmDirective)(short, (0, session_id_1.readIdentityAlias)()),
|
|
1099
|
-
},
|
|
1100
|
-
}) + '\n');
|
|
1195
|
+
writeAdditionalContext('UserPromptSubmit', (0, session_id_1.buildArmDirective)(short, (0, session_id_1.readIdentityAlias)()));
|
|
1101
1196
|
}
|
|
1102
1197
|
/** UserPromptSubmit PROBE / manual diagnostic — prints a per-turn readout of
|
|
1103
1198
|
* whether THIS session has a live watcher (the same isSessionArmed signal
|
|
@@ -1174,9 +1269,12 @@ function handlePreSpawnCheck(input) {
|
|
|
1174
1269
|
}
|
|
1175
1270
|
async function main() {
|
|
1176
1271
|
const subcommand = process.argv[2];
|
|
1177
|
-
const validSubs = new Set([
|
|
1272
|
+
const validSubs = new Set([
|
|
1273
|
+
'store', 'recap', 'notify', 'session-id', 'pre-spawn-check', 'armcheck',
|
|
1274
|
+
'codex-store', 'codex-notify', 'codex-inbox',
|
|
1275
|
+
]);
|
|
1178
1276
|
if (!validSubs.has(subcommand)) {
|
|
1179
|
-
process.stderr.write(`Usage: greprag-hook <store|recap|notify|session-id|pre-spawn-check|armcheck>\n`);
|
|
1277
|
+
process.stderr.write(`Usage: greprag-hook <store|recap|notify|session-id|pre-spawn-check|armcheck|codex-store|codex-notify|codex-inbox>\n`);
|
|
1180
1278
|
process.exit(1);
|
|
1181
1279
|
}
|
|
1182
1280
|
let input = {};
|
|
@@ -1198,6 +1296,12 @@ async function main() {
|
|
|
1198
1296
|
else if (subcommand === 'notify') {
|
|
1199
1297
|
await notify(input);
|
|
1200
1298
|
}
|
|
1299
|
+
else if (subcommand === 'codex-notify') {
|
|
1300
|
+
await notify(input, 'codex');
|
|
1301
|
+
}
|
|
1302
|
+
else if (subcommand === 'codex-inbox') {
|
|
1303
|
+
await codexInbox(input);
|
|
1304
|
+
}
|
|
1201
1305
|
else if (subcommand === 'session-id') {
|
|
1202
1306
|
// adr: adr/session-id-awareness.md
|
|
1203
1307
|
// SessionStart awareness only — surfaces the agent's own 8-hex session id +
|
|
@@ -1212,6 +1316,9 @@ async function main() {
|
|
|
1212
1316
|
else if (subcommand === 'armcheck') {
|
|
1213
1317
|
await armCheck(input);
|
|
1214
1318
|
}
|
|
1319
|
+
else if (subcommand === 'codex-store') {
|
|
1320
|
+
await store(input, 'codex');
|
|
1321
|
+
}
|
|
1215
1322
|
else {
|
|
1216
1323
|
await store(input);
|
|
1217
1324
|
}
|