intent-prompt-graph 0.1.0 → 0.1.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 CHANGED
@@ -6,10 +6,11 @@ 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
- Two parts in one npm package:
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
 
@@ -34,13 +35,57 @@ daemon code. A session that is not saved to disk gets a warning instead of a
34
35
  graph. The plugin entry is the `omp.extensions` field of `package.json`
35
36
  (`integrations/omp/intent-graph.ts`).
36
37
 
38
+ ## Claude Code
39
+
40
+ `ipg` reads Claude Code sessions with `--harness claude`:
41
+
42
+ ```sh
43
+ ipg open --harness claude # the session of this terminal or directory
44
+ ipg log --harness claude --session-file ~/.claude/projects/<project>/<session id>.jsonl
45
+ ```
46
+
47
+ Without `--session-file` it finds the session in two steps:
48
+
49
+ 1. It walks up its own parent processes. A running Claude Code process records
50
+ its session id in `~/.claude/sessions/<pid>.json`, so when `ipg` is started
51
+ from inside Claude Code (a slash command or the Bash tool) it gets exactly
52
+ that session.
53
+ 2. Otherwise it takes the newest session of the current directory under
54
+ `~/.claude/projects/`.
55
+
56
+ `CLAUDE_CONFIG_DIR` replaces `~/.claude` when it is set, as in Claude Code.
57
+
58
+ A message becomes an owner turn only when the owner wrote it. Tool output,
59
+ slash-command and `!` shell wrappers, system reminders, task notifications,
60
+ compaction summaries and subagent conversations do not.
61
+
62
+ The slash commands are the files `integrations/claude/commands/*.md` of this
63
+ package. Copy or link them into your Claude Code commands directory (or into
64
+ `.claude/commands/` of one project). From a checkout:
65
+
66
+ ```sh
67
+ mkdir -p ~/.claude/commands
68
+ ln -s "$PWD"/integrations/claude/commands/*.md ~/.claude/commands/
69
+ ```
70
+
71
+ - `/ipg` runs `ipg open --harness claude` and replies with the URL.
72
+ - `/ipg-log` writes the decision log to `/tmp/ipg-log-<session id>.md` and
73
+ replies with the path.
74
+ - `/ipg-rejected` puts the rejected paths into the conversation, so the agent
75
+ does not propose them again. When nothing was rejected it says so.
76
+
77
+ Each command runs `ipg` before the model sees the prompt and then costs one
78
+ short model reply. A brand-new session has no file on disk until its first
79
+ message is sent, so the commands report an error when they are the very first
80
+ thing typed.
81
+
37
82
  ## Decision log
38
83
 
39
84
  `ipg log` prints the record under the graph as markdown: the goal, what was
40
85
  chosen, what was rejected and why, the decisions and the loops.
41
86
 
42
87
  ```sh
43
- ipg log [--harness omp] [--session-file <file.jsonl>] [--rejected] [--out <file.md>]
88
+ ipg log [--harness omp|claude] [--session-file <file.jsonl>] [--rejected] [--out <file.md>]
44
89
  ```
45
90
 
46
91
  - It reads the graph the labeler already stored for the session. When there is
@@ -62,6 +107,8 @@ In OMP:
62
107
  - `/ipg-rejected` pastes the rejected block into the input editor. You review
63
108
  it and send it yourself. When nothing was rejected it says so.
64
109
 
110
+ In Claude Code the same two commands exist; see [Claude Code](#claude-code).
111
+
65
112
  ## Config
66
113
 
67
114
  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 the block is empty, reply with only "Nothing rejected yet".
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.0",
4
- "description": "A live browser graph of a coding-agent conversation, grouped by intent. Standalone `ipg` CLI plus an OMP plugin that adds /ipg.",
3
+ "version": "0.1.1",
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",
@@ -174,7 +174,7 @@ async function locate(opts: { sessionFile?: string; tty?: string; cwd: string })
174
174
  if (file) return refOf(file);
175
175
  // Falling back to another session of this directory would show the wrong conversation.
176
176
  throw new Error(
177
- `Claude Code session ${id} (pid ${pid}) has nothing saved yet; looked for ${join(projectsDir(), "*", `${id}.jsonl`)}`,
177
+ `Claude Code session ${id} (pid ${pid}) has no transcript yet (send a first message); looked for ${join(projectsDir(), "*", `${id}.jsonl`)}`,
178
178
  );
179
179
  }
180
180
  const glob = projectGlob(opts.cwd);
@@ -239,14 +239,18 @@ function claudeReader(opts: { config: Config }): Reader {
239
239
  open = null;
240
240
  };
241
241
 
242
- /** Folds text typed into the user channel: the owner's own words, or text the harness put there. */
243
- const userText = (content: unknown, origin: unknown) => {
242
+ /**
243
+ * Folds text from the user channel: the owner's own words, or text the harness put there.
244
+ * `typed` marks a prompt the owner submitted as text, as opposed to a command or its output.
245
+ */
246
+ const userText = (content: unknown, origin: unknown, typed: boolean) => {
244
247
  const blocks = textBlocks(content);
245
248
  const raw = blocks.join("\n");
246
249
  if (INTERRUPT_RE.test(raw)) return closeOpen();
247
- // Newer records name their origin; without one, a leading wrapper tag marks harness text.
250
+ // A leading wrapper tag marks harness text, unless the whole typed prompt merely starts with a tag.
251
+ const own = blocks.filter((b) => !WRAPPER_RE.test(b));
252
+ const text = (typed && own.length === 0 ? blocks : own).join("\n");
248
253
  const kind = isObj(origin) ? origin.kind : undefined;
249
- const text = (kind === "human" ? blocks : blocks.filter((b) => !WRAPPER_RE.test(b))).join("\n");
250
254
  const injected = (kind !== undefined && kind !== "human") || opts.config.harnessText.some((re) => re.test(text));
251
255
  if (!text || injected) {
252
256
  // Mid-turn injections are ignored; idle ones become the next agent turn's trigger.
@@ -270,7 +274,9 @@ function claudeReader(opts: { config: Config }): Reader {
270
274
  if (record.isMeta === true || record.isCompactSummary === true || record.isVisibleInTranscriptOnly === true) {
271
275
  return changed;
272
276
  }
273
- userText(m.content, record.origin);
277
+ // Typed, queued and SDK prompts name their source; slash commands and `!` shell lines do not.
278
+ const source = record.promptSource;
279
+ userText(m.content, record.origin, typeof source === "string" && source !== "system");
274
280
  return changed;
275
281
  }
276
282
 
@@ -322,7 +328,7 @@ function claudeReader(opts: { config: Config }): Reader {
322
328
  // A message the owner sent while the agent was working arrives as an attachment.
323
329
  if (record.type === "attachment" && isObj(record.attachment) && record.attachment.type === "queued_command") {
324
330
  const a = record.attachment;
325
- if (a.isMeta !== true) userText(a.prompt, a.origin);
331
+ if (a.isMeta !== true) userText(a.prompt, a.origin, isObj(a.origin) && a.origin.kind === "human");
326
332
  return changed;
327
333
  }
328
334
 
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
- * Places the main decision spine left-to-right across topological columns while stacking
75
- * rejected, unchosen option, and side-question branches cleanly below their parent column.
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 byId = new Map(nodes.map((n) => [n.id, n] as const));
89
- const outgoing = new Map<string, GraphEdge[]>();
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 (!byId.has(e.from) || !byId.has(e.to) || e.from === e.to) continue;
97
- outgoing.get(e.from)?.push(e);
98
- if (e.kind !== "side") {
99
- inDegree.set(e.to, (inDegree.get(e.to) ?? 0) + 1);
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
- // Assign topological column (layer) via bounded relaxation so cycles cannot loop forever.
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
- for (const n of nodes) layer.set(n.id, 0);
106
-
107
- const maxPasses = Math.min(nodes.length, 64);
108
- for (let pass = 0; pass < maxPasses; pass++) {
109
- let changed = false;
110
- for (const e of edges) {
111
- if (!byId.has(e.from) || !byId.has(e.to) || e.from === e.to) continue;
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
- if (!changed) break;
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(/&lt;img\b[^\n]*?&gt;/g, (tag) => {
90
+ const alt = /alt=&quot;(.*?)&quot;/.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">${esc(t.text || "(tool calls only)")}</div>` +
530
+ `<div class="turn-body">${transcriptHtml(t.text || "(tool calls only)")}</div>` +
516
531
  actionsHtml +
517
532
  `</div>`
518
533
  );