intent-prompt-graph 0.1.1 → 0.1.2
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 +28 -9
- package/package.json +1 -1
- package/src/cli.ts +56 -1
- package/src/harness/claude.ts +3 -2
- package/src/setup.ts +133 -0
package/README.md
CHANGED
|
@@ -15,8 +15,30 @@ Three parts in one npm package:
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
17
17
|
```sh
|
|
18
|
-
bun add -g intent-prompt-graph
|
|
19
|
-
omp plugin install intent-prompt-graph # adds /ipg
|
|
18
|
+
bun add -g intent-prompt-graph # puts `ipg` on PATH
|
|
19
|
+
omp plugin install intent-prompt-graph # OMP: adds /ipg
|
|
20
|
+
ipg setup claude # Claude Code: adds /ipg
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Needs [Bun](https://bun.sh) 1.0 or later. The package has no runtime
|
|
24
|
+
dependencies. The labeler is optional and needs either the `claude` command or
|
|
25
|
+
an OpenAI-compatible endpoint.
|
|
26
|
+
|
|
27
|
+
Pick the model that draws the real graph (this writes the `labeler` section of
|
|
28
|
+
the [config](#config); run it again any time to change it):
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
ipg setup labeler --provider claude-cli --model haiku
|
|
32
|
+
ipg setup labeler --provider openai --base-url https://api.example.com/v1 --model example-model --api-key-env IPG_LABELER_KEY
|
|
33
|
+
ipg setup labeler --off
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Uninstall:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
ipg uninstall # removes the Claude Code commands; --purge also deletes the config and stored graphs
|
|
40
|
+
omp plugin uninstall intent-prompt-graph
|
|
41
|
+
bun remove -g intent-prompt-graph
|
|
20
42
|
```
|
|
21
43
|
|
|
22
44
|
From a checkout instead:
|
|
@@ -60,13 +82,10 @@ slash-command and `!` shell wrappers, system reminders, task notifications,
|
|
|
60
82
|
compaction summaries and subagent conversations do not.
|
|
61
83
|
|
|
62
84
|
The slash commands are the files `integrations/claude/commands/*.md` of this
|
|
63
|
-
package.
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
mkdir -p ~/.claude/commands
|
|
68
|
-
ln -s "$PWD"/integrations/claude/commands/*.md ~/.claude/commands/
|
|
69
|
-
```
|
|
85
|
+
package. `ipg setup claude` links them into your Claude Code commands
|
|
86
|
+
directory (`~/.claude/commands/`, or `$CLAUDE_CONFIG_DIR/commands/`). A file of
|
|
87
|
+
the same name that is not its own link is left alone. To use them in one
|
|
88
|
+
project only, link the files into that project's `.claude/commands/` yourself.
|
|
70
89
|
|
|
71
90
|
- `/ipg` runs `ipg open --harness claude` and replies with the URL.
|
|
72
91
|
- `/ipg-log` writes the decision log to `/tmp/ipg-log-<session id>.md` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intent-prompt-graph",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "A live browser graph of a coding-agent conversation, grouped by intent. Standalone `ipg` CLI plus plugins for OMP and Claude Code that add /ipg.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai-agents",
|
package/src/cli.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { writeFileSync } from "node:fs";
|
|
3
|
-
import { configFile, type Config, loadConfig } from "./config";
|
|
3
|
+
import { configFile, type Config, type LabelerConfig, loadConfig } from "./config";
|
|
4
4
|
import { renderDecisionLog } from "./export";
|
|
5
5
|
import { type Harness, harnessById, type SessionRef } from "./harness/harness";
|
|
6
6
|
import { buildHeuristicGraph } from "./heuristic";
|
|
7
7
|
import type { Turn } from "./model";
|
|
8
8
|
import { APP, startDaemon } from "./server";
|
|
9
|
+
import { setupClaude, uninstall, writeLabeler } from "./setup";
|
|
9
10
|
import { openStore } from "./store";
|
|
10
11
|
import { tailJsonl } from "./tail";
|
|
11
12
|
|
|
@@ -14,6 +15,10 @@ const USAGE = [
|
|
|
14
15
|
" ipg serve [--port N]",
|
|
15
16
|
" ipg open [--harness omp|claude] [--session-file <file.jsonl>] [--no-browser] [--port N]",
|
|
16
17
|
" ipg log [--harness omp|claude] [--session-file <file.jsonl>] [--rejected] [--out <file.md>]",
|
|
18
|
+
" ipg setup claude",
|
|
19
|
+
" ipg setup labeler --provider claude-cli|openai --model <name> [--base-url <url>] [--api-key-env <VAR>] [--command <path>]",
|
|
20
|
+
" ipg setup labeler --off",
|
|
21
|
+
" ipg uninstall [--purge]",
|
|
17
22
|
].join("\n");
|
|
18
23
|
|
|
19
24
|
// The reader closed the pipe (e.g. `| head`): exit quietly, as other Unix tools do.
|
|
@@ -187,6 +192,52 @@ function openBrowser(url: string): void {
|
|
|
187
192
|
}
|
|
188
193
|
}
|
|
189
194
|
|
|
195
|
+
/** One-time setup: slash commands for Claude Code, or the labeler model in config.json. */
|
|
196
|
+
function setup(args: string[]): number {
|
|
197
|
+
const [what, ...rest] = args;
|
|
198
|
+
if (what === "claude") {
|
|
199
|
+
console.log(setupClaude().join("\n"));
|
|
200
|
+
console.log("Restart Claude Code to load the commands.");
|
|
201
|
+
return 0;
|
|
202
|
+
}
|
|
203
|
+
if (what === "labeler") {
|
|
204
|
+
let labeler: LabelerConfig | undefined;
|
|
205
|
+
if (!rest.includes("--off")) {
|
|
206
|
+
const provider = flag(rest, "--provider");
|
|
207
|
+
if (provider !== "claude-cli" && provider !== "openai") {
|
|
208
|
+
throw new Error("--provider must be claude-cli or openai (or pass --off)");
|
|
209
|
+
}
|
|
210
|
+
labeler = { provider };
|
|
211
|
+
const model = flag(rest, "--model");
|
|
212
|
+
const baseUrl = flag(rest, "--base-url");
|
|
213
|
+
const apiKeyEnv = flag(rest, "--api-key-env");
|
|
214
|
+
const command = flag(rest, "--command");
|
|
215
|
+
if (model) labeler.model = model;
|
|
216
|
+
if (baseUrl) labeler.baseUrl = baseUrl;
|
|
217
|
+
if (apiKeyEnv) labeler.apiKeyEnv = apiKeyEnv;
|
|
218
|
+
if (command) labeler.command = command;
|
|
219
|
+
}
|
|
220
|
+
const file = writeLabeler(labeler);
|
|
221
|
+
console.log(labeler ? `labeler set to ${labeler.provider} / ${labeler.model} in ${file}` : `labeler turned off in ${file}`);
|
|
222
|
+
console.log("A running page server keeps its old setting until it restarts (it exits after its idle time).");
|
|
223
|
+
return 0;
|
|
224
|
+
}
|
|
225
|
+
console.error(USAGE);
|
|
226
|
+
return 2;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Removes the Claude Code commands (and with --purge the config and stored graphs), then says what is left. */
|
|
230
|
+
function uninstallAll(args: string[]): number {
|
|
231
|
+
const purge = args.includes("--purge");
|
|
232
|
+
const done = uninstall(purge);
|
|
233
|
+
console.log(done.length > 0 ? done.join("\n") : "nothing to remove");
|
|
234
|
+
if (!purge) console.log("Config and stored graphs were kept; pass --purge to delete them too.");
|
|
235
|
+
console.log("Last steps, to remove the program itself:");
|
|
236
|
+
console.log(" omp plugin uninstall intent-prompt-graph # only if you installed the OMP plugin");
|
|
237
|
+
console.log(" bun remove -g intent-prompt-graph");
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
190
241
|
async function main(argv: string[]): Promise<number> {
|
|
191
242
|
const [cmd, ...rest] = argv;
|
|
192
243
|
try {
|
|
@@ -199,6 +250,10 @@ async function main(argv: string[]): Promise<number> {
|
|
|
199
250
|
return await open(rest);
|
|
200
251
|
case "log":
|
|
201
252
|
return await log(rest);
|
|
253
|
+
case "setup":
|
|
254
|
+
return setup(rest);
|
|
255
|
+
case "uninstall":
|
|
256
|
+
return uninstallAll(rest);
|
|
202
257
|
default:
|
|
203
258
|
console.error(USAGE);
|
|
204
259
|
return 2;
|
package/src/harness/claude.ts
CHANGED
|
@@ -22,8 +22,9 @@ const WRAPPER_RE = /^\s*<[a-z][\w-]*[\s>]/;
|
|
|
22
22
|
/** Marker Claude Code writes when the owner pressed Esc. */
|
|
23
23
|
const INTERRUPT_RE = /^\[Request interrupted by user[^\]]*\]/;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/** Claude Code's config directory: `CLAUDE_CONFIG_DIR`, else `~/.claude`. */
|
|
26
|
+
export function claudeDir(env: NodeJS.ProcessEnv = process.env): string {
|
|
27
|
+
return env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function projectsDir(): string {
|
package/src/setup.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, rmSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { configFile, isLabelerConfigured, type LabelerConfig } from "./config";
|
|
5
|
+
import { claudeDir } from "./harness/claude";
|
|
6
|
+
|
|
7
|
+
/** The Claude Code slash-command files shipped in this package. */
|
|
8
|
+
const CLAUDE_COMMANDS = join(import.meta.dir, "../integrations/claude/commands");
|
|
9
|
+
|
|
10
|
+
/** True when `path` is a symlink that points into this package's command files. */
|
|
11
|
+
function isOurLink(path: string, target: string): boolean {
|
|
12
|
+
try {
|
|
13
|
+
return lstatSync(path).isSymbolicLink() && readlinkSync(path) === target;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Links this package's slash commands into Claude Code's commands directory.
|
|
21
|
+
* A file of the same name that is not our link is left alone and reported.
|
|
22
|
+
*
|
|
23
|
+
* Args:
|
|
24
|
+
* env (NodeJS.ProcessEnv): Environment map; `CLAUDE_CONFIG_DIR` replaces `~/.claude`.
|
|
25
|
+
*
|
|
26
|
+
* Returns:
|
|
27
|
+
* string[]: One line per command file, saying what was done.
|
|
28
|
+
*/
|
|
29
|
+
export function setupClaude(env: NodeJS.ProcessEnv = process.env): string[] {
|
|
30
|
+
const dir = join(claudeDir(env), "commands");
|
|
31
|
+
mkdirSync(dir, { recursive: true });
|
|
32
|
+
return readdirSync(CLAUDE_COMMANDS)
|
|
33
|
+
.filter((f) => f.endsWith(".md"))
|
|
34
|
+
.sort()
|
|
35
|
+
.map((f) => {
|
|
36
|
+
const target = join(CLAUDE_COMMANDS, f);
|
|
37
|
+
const link = join(dir, f);
|
|
38
|
+
const name = `/${f.slice(0, -3)}`;
|
|
39
|
+
if (isOurLink(link, target)) return `${name}: already set up`;
|
|
40
|
+
let stale = false;
|
|
41
|
+
try {
|
|
42
|
+
stale = lstatSync(link).isSymbolicLink() && !existsSync(link);
|
|
43
|
+
} catch {
|
|
44
|
+
// Nothing at that path yet.
|
|
45
|
+
}
|
|
46
|
+
if (stale) unlinkSync(link);
|
|
47
|
+
else if (existsSync(link)) return `${name}: skipped, ${link} exists and is not ours`;
|
|
48
|
+
symlinkSync(target, link);
|
|
49
|
+
return `${name}: added (${link})`;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Removes the slash-command links that setupClaude created. Files that are not our links stay.
|
|
55
|
+
*
|
|
56
|
+
* Args:
|
|
57
|
+
* env (NodeJS.ProcessEnv): Environment map; `CLAUDE_CONFIG_DIR` replaces `~/.claude`.
|
|
58
|
+
*
|
|
59
|
+
* Returns:
|
|
60
|
+
* string[]: One line per removed link.
|
|
61
|
+
*/
|
|
62
|
+
export function removeClaude(env: NodeJS.ProcessEnv = process.env): string[] {
|
|
63
|
+
const dir = join(claudeDir(env), "commands");
|
|
64
|
+
const out: string[] = [];
|
|
65
|
+
for (const f of readdirSync(CLAUDE_COMMANDS)) {
|
|
66
|
+
const link = join(dir, f);
|
|
67
|
+
if (!isOurLink(link, join(CLAUDE_COMMANDS, f))) continue;
|
|
68
|
+
unlinkSync(link);
|
|
69
|
+
out.push(`removed ${link}`);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Writes the `labeler` section of config.json and keeps every other setting. `undefined` removes
|
|
76
|
+
* the section, which turns the labeler off.
|
|
77
|
+
*
|
|
78
|
+
* Args:
|
|
79
|
+
* labeler (LabelerConfig | undefined): New labeler settings, or undefined to remove them.
|
|
80
|
+
* env (NodeJS.ProcessEnv): Environment map for resolving the config file.
|
|
81
|
+
*
|
|
82
|
+
* Returns:
|
|
83
|
+
* string: Path of the config file that was written.
|
|
84
|
+
*/
|
|
85
|
+
export function writeLabeler(labeler: LabelerConfig | undefined, env: NodeJS.ProcessEnv = process.env): string {
|
|
86
|
+
if (labeler && !isLabelerConfigured(labeler)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
labeler.model ? "provider openai needs --base-url <url>" : "a labeler needs --model <name>",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const file = configFile(env);
|
|
92
|
+
let json: Record<string, unknown> = {};
|
|
93
|
+
if (existsSync(file)) {
|
|
94
|
+
const parsed: unknown = JSON.parse(readFileSync(file, "utf8"));
|
|
95
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
96
|
+
throw new Error(`${file} must hold a JSON object`);
|
|
97
|
+
}
|
|
98
|
+
json = { ...parsed };
|
|
99
|
+
}
|
|
100
|
+
if (labeler) json.labeler = labeler;
|
|
101
|
+
else delete json.labeler;
|
|
102
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
103
|
+
writeFileSync(file, `${JSON.stringify(json, null, 2)}\n`);
|
|
104
|
+
return file;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Directory holding the stored graphs of every session. */
|
|
108
|
+
export function stateDir(env: NodeJS.ProcessEnv = process.env): string {
|
|
109
|
+
return join(env.XDG_STATE_HOME || join(homedir(), ".local", "state"), "intent-prompt-graph");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Removes what this tool put on the machine outside its own package: the Claude Code command
|
|
114
|
+
* links, and with `purge` also the config file and every stored graph.
|
|
115
|
+
*
|
|
116
|
+
* Args:
|
|
117
|
+
* purge (boolean): Also delete the config directory and the stored graphs.
|
|
118
|
+
* env (NodeJS.ProcessEnv): Environment map for resolving the directories.
|
|
119
|
+
*
|
|
120
|
+
* Returns:
|
|
121
|
+
* string[]: One line per thing removed.
|
|
122
|
+
*/
|
|
123
|
+
export function uninstall(purge: boolean, env: NodeJS.ProcessEnv = process.env): string[] {
|
|
124
|
+
const out = removeClaude(env);
|
|
125
|
+
if (purge) {
|
|
126
|
+
for (const dir of [dirname(configFile(env)), stateDir(env)]) {
|
|
127
|
+
if (!existsSync(dir)) continue;
|
|
128
|
+
rmSync(dir, { recursive: true });
|
|
129
|
+
out.push(`removed ${dir}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|