intent-prompt-graph 0.1.0 → 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 +71 -5
- package/integrations/claude/commands/ipg-rejected.md +1 -1
- package/package.json +2 -2
- package/src/cli.ts +56 -1
- package/src/harness/claude.ts +16 -9
- package/src/setup.ts +133 -0
- package/web/layout.ts +26 -35
- package/web/style.css +7 -0
- package/web/view.ts +16 -1
package/README.md
CHANGED
|
@@ -6,16 +6,39 @@ Without a `labeler` you get a basic outline, not the real decision graph: node t
|
|
|
6
6
|
|
|
7
7
|
## What it is
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Three parts in one npm package:
|
|
10
10
|
|
|
11
|
-
- `ipg`: a standalone CLI and local daemon (needs [Bun](https://bun.sh)). Works from any shell.
|
|
11
|
+
- `ipg`: a standalone CLI and local daemon (needs [Bun](https://bun.sh)). Works from any shell. It reads sessions of two harnesses: OMP (`--harness omp`, the default) and Claude Code (`--harness claude`).
|
|
12
12
|
- An OMP plugin that adds the `/ipg` slash command (a thin wrapper around `ipg open`).
|
|
13
|
+
- Claude Code slash commands that do the same there (see [Claude Code](#claude-code)).
|
|
13
14
|
|
|
14
15
|
## Install
|
|
15
16
|
|
|
16
17
|
```sh
|
|
17
|
-
bun add -g intent-prompt-graph
|
|
18
|
-
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
|
|
19
42
|
```
|
|
20
43
|
|
|
21
44
|
From a checkout instead:
|
|
@@ -34,13 +57,54 @@ daemon code. A session that is not saved to disk gets a warning instead of a
|
|
|
34
57
|
graph. The plugin entry is the `omp.extensions` field of `package.json`
|
|
35
58
|
(`integrations/omp/intent-graph.ts`).
|
|
36
59
|
|
|
60
|
+
## Claude Code
|
|
61
|
+
|
|
62
|
+
`ipg` reads Claude Code sessions with `--harness claude`:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
ipg open --harness claude # the session of this terminal or directory
|
|
66
|
+
ipg log --harness claude --session-file ~/.claude/projects/<project>/<session id>.jsonl
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Without `--session-file` it finds the session in two steps:
|
|
70
|
+
|
|
71
|
+
1. It walks up its own parent processes. A running Claude Code process records
|
|
72
|
+
its session id in `~/.claude/sessions/<pid>.json`, so when `ipg` is started
|
|
73
|
+
from inside Claude Code (a slash command or the Bash tool) it gets exactly
|
|
74
|
+
that session.
|
|
75
|
+
2. Otherwise it takes the newest session of the current directory under
|
|
76
|
+
`~/.claude/projects/`.
|
|
77
|
+
|
|
78
|
+
`CLAUDE_CONFIG_DIR` replaces `~/.claude` when it is set, as in Claude Code.
|
|
79
|
+
|
|
80
|
+
A message becomes an owner turn only when the owner wrote it. Tool output,
|
|
81
|
+
slash-command and `!` shell wrappers, system reminders, task notifications,
|
|
82
|
+
compaction summaries and subagent conversations do not.
|
|
83
|
+
|
|
84
|
+
The slash commands are the files `integrations/claude/commands/*.md` of this
|
|
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.
|
|
89
|
+
|
|
90
|
+
- `/ipg` runs `ipg open --harness claude` and replies with the URL.
|
|
91
|
+
- `/ipg-log` writes the decision log to `/tmp/ipg-log-<session id>.md` and
|
|
92
|
+
replies with the path.
|
|
93
|
+
- `/ipg-rejected` puts the rejected paths into the conversation, so the agent
|
|
94
|
+
does not propose them again. When nothing was rejected it says so.
|
|
95
|
+
|
|
96
|
+
Each command runs `ipg` before the model sees the prompt and then costs one
|
|
97
|
+
short model reply. A brand-new session has no file on disk until its first
|
|
98
|
+
message is sent, so the commands report an error when they are the very first
|
|
99
|
+
thing typed.
|
|
100
|
+
|
|
37
101
|
## Decision log
|
|
38
102
|
|
|
39
103
|
`ipg log` prints the record under the graph as markdown: the goal, what was
|
|
40
104
|
chosen, what was rejected and why, the decisions and the loops.
|
|
41
105
|
|
|
42
106
|
```sh
|
|
43
|
-
ipg log [--harness omp] [--session-file <file.jsonl>] [--rejected] [--out <file.md>]
|
|
107
|
+
ipg log [--harness omp|claude] [--session-file <file.jsonl>] [--rejected] [--out <file.md>]
|
|
44
108
|
```
|
|
45
109
|
|
|
46
110
|
- It reads the graph the labeler already stored for the session. When there is
|
|
@@ -62,6 +126,8 @@ In OMP:
|
|
|
62
126
|
- `/ipg-rejected` pastes the rejected block into the input editor. You review
|
|
63
127
|
it and send it yourself. When nothing was rejected it says so.
|
|
64
128
|
|
|
129
|
+
In Claude Code the same two commands exist; see [Claude Code](#claude-code).
|
|
130
|
+
|
|
65
131
|
## Config
|
|
66
132
|
|
|
67
133
|
Optional file: `$XDG_CONFIG_HOME/intent-prompt-graph/config.json`, or
|
|
@@ -7,4 +7,4 @@ Paths rejected earlier in this session:
|
|
|
7
7
|
|
|
8
8
|
!`ipg log --harness claude --rejected`
|
|
9
9
|
|
|
10
|
-
Show the block above to the user as it is. Treat every path listed in it as already rejected: do not propose it again in this session. If
|
|
10
|
+
Show the block above to the user as it is. Treat every path listed in it as already rejected: do not propose it again in this session. If no rejected paths are listed above, reply with only "Nothing rejected yet". If an error is printed above instead, show the error as it is.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "intent-prompt-graph",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "A live browser graph of a coding-agent conversation, grouped by intent. Standalone `ipg` CLI plus
|
|
3
|
+
"version": "0.1.2",
|
|
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",
|
|
7
7
|
"coding-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 {
|
|
@@ -174,7 +175,7 @@ async function locate(opts: { sessionFile?: string; tty?: string; cwd: string })
|
|
|
174
175
|
if (file) return refOf(file);
|
|
175
176
|
// Falling back to another session of this directory would show the wrong conversation.
|
|
176
177
|
throw new Error(
|
|
177
|
-
`Claude Code session ${id} (pid ${pid}) has
|
|
178
|
+
`Claude Code session ${id} (pid ${pid}) has no transcript yet (send a first message); looked for ${join(projectsDir(), "*", `${id}.jsonl`)}`,
|
|
178
179
|
);
|
|
179
180
|
}
|
|
180
181
|
const glob = projectGlob(opts.cwd);
|
|
@@ -239,14 +240,18 @@ function claudeReader(opts: { config: Config }): Reader {
|
|
|
239
240
|
open = null;
|
|
240
241
|
};
|
|
241
242
|
|
|
242
|
-
/**
|
|
243
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Folds text from the user channel: the owner's own words, or text the harness put there.
|
|
245
|
+
* `typed` marks a prompt the owner submitted as text, as opposed to a command or its output.
|
|
246
|
+
*/
|
|
247
|
+
const userText = (content: unknown, origin: unknown, typed: boolean) => {
|
|
244
248
|
const blocks = textBlocks(content);
|
|
245
249
|
const raw = blocks.join("\n");
|
|
246
250
|
if (INTERRUPT_RE.test(raw)) return closeOpen();
|
|
247
|
-
//
|
|
251
|
+
// A leading wrapper tag marks harness text, unless the whole typed prompt merely starts with a tag.
|
|
252
|
+
const own = blocks.filter((b) => !WRAPPER_RE.test(b));
|
|
253
|
+
const text = (typed && own.length === 0 ? blocks : own).join("\n");
|
|
248
254
|
const kind = isObj(origin) ? origin.kind : undefined;
|
|
249
|
-
const text = (kind === "human" ? blocks : blocks.filter((b) => !WRAPPER_RE.test(b))).join("\n");
|
|
250
255
|
const injected = (kind !== undefined && kind !== "human") || opts.config.harnessText.some((re) => re.test(text));
|
|
251
256
|
if (!text || injected) {
|
|
252
257
|
// Mid-turn injections are ignored; idle ones become the next agent turn's trigger.
|
|
@@ -270,7 +275,9 @@ function claudeReader(opts: { config: Config }): Reader {
|
|
|
270
275
|
if (record.isMeta === true || record.isCompactSummary === true || record.isVisibleInTranscriptOnly === true) {
|
|
271
276
|
return changed;
|
|
272
277
|
}
|
|
273
|
-
|
|
278
|
+
// Typed, queued and SDK prompts name their source; slash commands and `!` shell lines do not.
|
|
279
|
+
const source = record.promptSource;
|
|
280
|
+
userText(m.content, record.origin, typeof source === "string" && source !== "system");
|
|
274
281
|
return changed;
|
|
275
282
|
}
|
|
276
283
|
|
|
@@ -322,7 +329,7 @@ function claudeReader(opts: { config: Config }): Reader {
|
|
|
322
329
|
// A message the owner sent while the agent was working arrives as an attachment.
|
|
323
330
|
if (record.type === "attachment" && isObj(record.attachment) && record.attachment.type === "queued_command") {
|
|
324
331
|
const a = record.attachment;
|
|
325
|
-
if (a.isMeta !== true) userText(a.prompt, a.origin);
|
|
332
|
+
if (a.isMeta !== true) userText(a.prompt, a.origin, isObj(a.origin) && a.origin.kind === "human");
|
|
326
333
|
return changed;
|
|
327
334
|
}
|
|
328
335
|
|
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
|
+
}
|
package/web/layout.ts
CHANGED
|
@@ -71,8 +71,11 @@ const KIND_PRIORITY: Record<NodeKind, number> = {
|
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Computes collision-free top-left (x, y) coordinates for every node in a Decision & Path Graph.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* Columns follow time along the spine: a spine node is never placed left of a spine node that
|
|
75
|
+
* happened before it. A node sits one column right of its parent (same column for a side question);
|
|
76
|
+
* a node with no earlier parent starts after the latest spine node instead of restarting at the far
|
|
77
|
+
* left. Rejected, unchosen option, and side-question branches stay beside the node they branch from
|
|
78
|
+
* and stack below the spine in their column.
|
|
76
79
|
*
|
|
77
80
|
* Args:
|
|
78
81
|
* nodes (readonly GraphNode[]): Graph nodes to place.
|
|
@@ -85,43 +88,32 @@ export function layoutGraph(nodes: readonly GraphNode[], edges: readonly GraphEd
|
|
|
85
88
|
const pos = new Map<string, Point>();
|
|
86
89
|
if (nodes.length === 0) return pos;
|
|
87
90
|
|
|
88
|
-
const
|
|
89
|
-
const
|
|
90
|
-
const inDegree = new Map<string, number>();
|
|
91
|
-
for (const n of nodes) {
|
|
92
|
-
outgoing.set(n.id, []);
|
|
93
|
-
inDegree.set(n.id, 0);
|
|
94
|
-
}
|
|
91
|
+
const orderIndex = new Map(nodes.map((n, i) => [n.id, i] as const));
|
|
92
|
+
const incoming = new Map<string, GraphEdge[]>();
|
|
95
93
|
for (const e of edges) {
|
|
96
|
-
if (!
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
94
|
+
if (!orderIndex.has(e.from) || !orderIndex.has(e.to) || e.from === e.to) continue;
|
|
95
|
+
const list = incoming.get(e.to) ?? [];
|
|
96
|
+
list.push(e);
|
|
97
|
+
incoming.set(e.to, list);
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
//
|
|
100
|
+
// Walk the nodes oldest first. Only parents already placed constrain a node, so an edge that
|
|
101
|
+
// points back in time (or closes a cycle) cannot pull anything left.
|
|
102
|
+
const byTime = [...nodes].sort((a, b) => a.at - b.at || (orderIndex.get(a.id) ?? 0) - (orderIndex.get(b.id) ?? 0));
|
|
104
103
|
const layer = new Map<string, number>();
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const fromL = layer.get(e.from) ?? 0;
|
|
113
|
-
const toL = layer.get(e.to) ?? 0;
|
|
114
|
-
if (e.kind === "side") {
|
|
115
|
-
if (toL < fromL) {
|
|
116
|
-
layer.set(e.to, fromL);
|
|
117
|
-
changed = true;
|
|
118
|
-
}
|
|
119
|
-
} else if (toL < fromL + 1) {
|
|
120
|
-
layer.set(e.to, fromL + 1);
|
|
121
|
-
changed = true;
|
|
122
|
-
}
|
|
104
|
+
let spineMax = 0;
|
|
105
|
+
for (const n of byTime) {
|
|
106
|
+
let col = -1;
|
|
107
|
+
for (const e of incoming.get(n.id) ?? []) {
|
|
108
|
+
const fromL = layer.get(e.from);
|
|
109
|
+
if (fromL === undefined) continue;
|
|
110
|
+
col = Math.max(col, e.kind === "side" ? fromL : fromL + 1);
|
|
123
111
|
}
|
|
124
|
-
|
|
112
|
+
const spine = isSpineKind(n.kind);
|
|
113
|
+
if (col < 0) col = layer.size === 0 ? 0 : spine ? spineMax + 1 : spineMax;
|
|
114
|
+
else if (spine) col = Math.max(col, spineMax);
|
|
115
|
+
layer.set(n.id, col);
|
|
116
|
+
if (spine) spineMax = col;
|
|
125
117
|
}
|
|
126
118
|
|
|
127
119
|
// Group nodes into columns and sort each column so the main spine stays on row 0.
|
|
@@ -133,7 +125,6 @@ export function layoutGraph(nodes: readonly GraphNode[], edges: readonly GraphEd
|
|
|
133
125
|
columns.set(col, list);
|
|
134
126
|
}
|
|
135
127
|
|
|
136
|
-
const orderIndex = new Map(nodes.map((n, i) => [n.id, i] as const));
|
|
137
128
|
for (const [col, list] of columns) {
|
|
138
129
|
list.sort((a, b) => {
|
|
139
130
|
const pDiff = KIND_PRIORITY[a.kind] - KIND_PRIORITY[b.kind];
|
package/web/style.css
CHANGED
|
@@ -631,6 +631,13 @@ html, body {
|
|
|
631
631
|
max-height: 360px;
|
|
632
632
|
overflow-y: auto;
|
|
633
633
|
}
|
|
634
|
+
.turn-body code {
|
|
635
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
636
|
+
font-size: 11px;
|
|
637
|
+
background: var(--inset);
|
|
638
|
+
border-radius: 3px;
|
|
639
|
+
padding: 1px 4px;
|
|
640
|
+
}
|
|
634
641
|
.turn-actions {
|
|
635
642
|
margin: 0;
|
|
636
643
|
padding-left: 16px;
|
package/web/view.ts
CHANGED
|
@@ -80,6 +80,21 @@ function esc(s: string): string {
|
|
|
80
80
|
return s.replace(/[&<>"']/g, (ch) => ENTITIES[ch] ?? ch);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Escapes transcript text and renders the little markdown agents write: `**bold**`, `` `code` ``,
|
|
85
|
+
* `# headings`, and `<img alt="…">` tags (shown as "[image: …]"). Everything else stays plain text.
|
|
86
|
+
*/
|
|
87
|
+
export function transcriptHtml(text: string): string {
|
|
88
|
+
return esc(text)
|
|
89
|
+
.replace(/<img\b[^\n]*?>/g, (tag) => {
|
|
90
|
+
const alt = /alt="(.*?)"/.exec(tag)?.[1];
|
|
91
|
+
return alt ? `[image: ${alt}]` : "[image]";
|
|
92
|
+
})
|
|
93
|
+
.replace(/`([^`\n]+)`/g, "<code>$1</code>")
|
|
94
|
+
.replace(/\*\*([^*\n]+)\*\*/g, "<b>$1</b>")
|
|
95
|
+
.replace(/^#{1,6} +(.+)$/gm, "<b>$1</b>");
|
|
96
|
+
}
|
|
97
|
+
|
|
83
98
|
/** Replaces an element's content only when it changed, so scroll position and hover survive repaints. */
|
|
84
99
|
function setHtml(el: Element, html: string): void {
|
|
85
100
|
if (painted.get(el) === html) return;
|
|
@@ -512,7 +527,7 @@ export function paintInspector(s: State, els: Els): void {
|
|
|
512
527
|
return (
|
|
513
528
|
`<div class="turn-card">` +
|
|
514
529
|
`<div class="turn-who"><span>${whoLabel}</span><span>${esc(clock(t.at))}</span></div>` +
|
|
515
|
-
`<div class="turn-body">${
|
|
530
|
+
`<div class="turn-body">${transcriptHtml(t.text || "(tool calls only)")}</div>` +
|
|
516
531
|
actionsHtml +
|
|
517
532
|
`</div>`
|
|
518
533
|
);
|