jeo-code 0.6.15 → 0.6.16

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/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  The README mirrors the latest 5 entries — regenerate with `bun run changelog:sync`.
8
8
 
9
+ ## [0.6.16] - 2026-06-17
10
+ _OKF memory grows a concept cross-link graph: 1-hop search expansion, bundle lint, graphify-optional._
11
+
12
+ ### Added
13
+ - **Concept cross-link graph for the memory bundle (OKF Sprint 04).** A new zero-dependency `src/agent/memory-graph.ts` treats the OKF bundle as a first-class link graph — nodes are concept IDs, edges are the markdown links a concept's body points at another concept, and broken links are tolerated (captured for lint, never thrown). It powers `buildConceptGraph` / `expandByGraph` / `resolveLinkTarget` / `lintConceptGraph` / `graphifyAvailable`. Memory injection now applies **1-hop graph expansion**: a concept the task query directly hits lifts its link-neighbours ahead of unrelated noise (still within `MEMORY_INJECT_MAX_CHARS`). New `lintMemoryBundle(cwd)` reports orphan concepts, broken links, and duplicate-title merge candidates. The optional `graphify` tool is a best-effort enrichment layer only — every feature runs fully on the built-in graph when it is absent (graceful degradation), and `graphify update` is never run against the markdown bundle.
14
+
9
15
  ## [0.6.15] - 2026-06-17
10
16
  _Query-aware OKF memory injection with budget-priority selection, and a truthful end-of-turn Todos receipt._
11
17
 
package/README.ja.md CHANGED
@@ -158,11 +158,11 @@ CI は `.github/workflows/npm-publish.yml` で公開します — GitHub リリ
158
158
  ## 変更履歴 (Changelog)
159
159
 
160
160
  <!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
161
+ - **[0.6.16]** (2026-06-17) — OKF memory grows a concept cross-link graph: 1-hop search expansion, bundle lint, graphify-optional.
161
162
  - **[0.6.15]** (2026-06-17) — Query-aware OKF memory injection with budget-priority selection, and a truthful end-of-turn Todos receipt.
162
163
  - **[0.6.14]** (2026-06-16) — Memory distillation survives malformed model output, and stream-idle stalls retry instead of failing the turn.
163
164
  - **[0.6.13]** (2026-06-16) — `team` engine: concrete uncommitted-work reporting and stricter empty-run handling.
164
165
  - **[0.6.12]** (2026-06-16) — OKF-backed memory distillation — session learnings become structured concept files.
165
- - **[0.6.11]** (2026-06-16) — Larger reasoning budgets, and terminal capability-response sequences kept out of the prompt.
166
166
 
167
167
  See [CHANGELOG.md](CHANGELOG.md) for the full history.
168
168
  <!-- CHANGELOG:END -->
package/README.ko.md CHANGED
@@ -158,11 +158,11 @@ CI는 `.github/workflows/npm-publish.yml`로 배포합니다 — GitHub 릴리
158
158
  ## 변경 이력 (Changelog)
159
159
 
160
160
  <!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
161
+ - **[0.6.16]** (2026-06-17) — OKF memory grows a concept cross-link graph: 1-hop search expansion, bundle lint, graphify-optional.
161
162
  - **[0.6.15]** (2026-06-17) — Query-aware OKF memory injection with budget-priority selection, and a truthful end-of-turn Todos receipt.
162
163
  - **[0.6.14]** (2026-06-16) — Memory distillation survives malformed model output, and stream-idle stalls retry instead of failing the turn.
163
164
  - **[0.6.13]** (2026-06-16) — `team` engine: concrete uncommitted-work reporting and stricter empty-run handling.
164
165
  - **[0.6.12]** (2026-06-16) — OKF-backed memory distillation — session learnings become structured concept files.
165
- - **[0.6.11]** (2026-06-16) — Larger reasoning budgets, and terminal capability-response sequences kept out of the prompt.
166
166
 
167
167
  See [CHANGELOG.md](CHANGELOG.md) for the full history.
168
168
  <!-- CHANGELOG:END -->
package/README.md CHANGED
@@ -158,11 +158,11 @@ Required npm token permissions (repository secret `NPM_TOKEN`):
158
158
  ## Changelog
159
159
 
160
160
  <!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
161
+ - **[0.6.16]** (2026-06-17) — OKF memory grows a concept cross-link graph: 1-hop search expansion, bundle lint, graphify-optional.
161
162
  - **[0.6.15]** (2026-06-17) — Query-aware OKF memory injection with budget-priority selection, and a truthful end-of-turn Todos receipt.
162
163
  - **[0.6.14]** (2026-06-16) — Memory distillation survives malformed model output, and stream-idle stalls retry instead of failing the turn.
163
164
  - **[0.6.13]** (2026-06-16) — `team` engine: concrete uncommitted-work reporting and stricter empty-run handling.
164
165
  - **[0.6.12]** (2026-06-16) — OKF-backed memory distillation — session learnings become structured concept files.
165
- - **[0.6.11]** (2026-06-16) — Larger reasoning budgets, and terminal capability-response sequences kept out of the prompt.
166
166
 
167
167
  See [CHANGELOG.md](CHANGELOG.md) for the full history.
168
168
  <!-- CHANGELOG:END -->
package/README.zh.md CHANGED
@@ -158,11 +158,11 @@ CI 通过 `.github/workflows/npm-publish.yml` 发布 — GitHub 发布 release
158
158
  ## 更新日志 (Changelog)
159
159
 
160
160
  <!-- CHANGELOG:START (auto-generated from CHANGELOG.md — run `bun run changelog:sync`) -->
161
+ - **[0.6.16]** (2026-06-17) — OKF memory grows a concept cross-link graph: 1-hop search expansion, bundle lint, graphify-optional.
161
162
  - **[0.6.15]** (2026-06-17) — Query-aware OKF memory injection with budget-priority selection, and a truthful end-of-turn Todos receipt.
162
163
  - **[0.6.14]** (2026-06-16) — Memory distillation survives malformed model output, and stream-idle stalls retry instead of failing the turn.
163
164
  - **[0.6.13]** (2026-06-16) — `team` engine: concrete uncommitted-work reporting and stricter empty-run handling.
164
165
  - **[0.6.12]** (2026-06-16) — OKF-backed memory distillation — session learnings become structured concept files.
165
- - **[0.6.11]** (2026-06-16) — Larger reasoning budgets, and terminal capability-response sequences kept out of the prompt.
166
166
 
167
167
  See [CHANGELOG.md](CHANGELOG.md) for the full history.
168
168
  <!-- CHANGELOG:END -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jeo-code",
3
- "version": "0.6.15",
3
+ "version": "0.6.16",
4
4
 
5
5
  "description": "Clean, highly optimized AI coding agent using spec-first loop",
6
6
  "type": "module",
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Concept cross-link graph for the OKF memory bundle — OKF Sprint 04 (Graph Layer).
3
+ *
4
+ * A first-class, zero-dependency link graph over the concept bundle: nodes are
5
+ * concept IDs (bundle-relative path minus `.md`), edges are the markdown links a
6
+ * concept's body points at another concept. Broken links (targets with no node)
7
+ * are TOLERATED — OKF's lenient model treats them as "knowledge not yet written"
8
+ * and the lint pass reports them rather than failing.
9
+ *
10
+ * Used to (1) strengthen Sprint 03 search by 1-hop graph expansion (a concept
11
+ * the query directly hits pulls in its neighbours as injection candidates) and
12
+ * (2) lint the bundle (orphans / broken links / duplicate-title candidates).
13
+ *
14
+ * graphify (the external graph tool) is an OPTIONAL second layer: when present
15
+ * it can enrich, but every feature here runs fully on the built-in graph so the
16
+ * bundle works with graphify absent (graceful degradation). Note: `graphify
17
+ * update` is for CODE repos only — never run it against this markdown bundle.
18
+ *
19
+ * Design contract: docs/okf_mem/sprint-04-graph-layer/index.md
20
+ */
21
+ import * as posix from "node:path/posix";
22
+ import { conceptId } from "./memory-okf";
23
+
24
+ /** Minimal shape the graph needs from a concept (a `Concept` satisfies it). */
25
+ export interface GraphConcept {
26
+ /** Bundle-relative path, e.g. `commands/bun-test.md`. */
27
+ relPath: string;
28
+ /** Markdown body; scanned for `](target)` links. */
29
+ body: string;
30
+ /** Optional concept title (for duplicate-title lint). */
31
+ title?: string;
32
+ }
33
+
34
+ /** A directed cross-link graph over concept IDs. */
35
+ export interface ConceptGraph {
36
+ /** All concept IDs present in the bundle. */
37
+ nodes: Set<string>;
38
+ /** from-ID → set of to-IDs that resolve to a real node. */
39
+ edges: Map<string, Set<string>>;
40
+ /** from-ID → set of link targets that have NO node (tolerated broken links). */
41
+ broken: Map<string, Set<string>>;
42
+ }
43
+
44
+ /** A markdown inline link `](target)` — captures the target, not the label. */
45
+ const LINK_RE = /\]\(([^)\s]+)\)/g;
46
+
47
+ function addEdge(map: Map<string, Set<string>>, from: string, to: string): void {
48
+ const set = map.get(from) ?? new Set<string>();
49
+ set.add(to);
50
+ map.set(from, set);
51
+ }
52
+
53
+ /**
54
+ * Resolve a markdown link target (as written in `from`'s body) to a concept ID,
55
+ * or `null` when it is not an in-bundle concept reference. Handles:
56
+ * - external/protocol links (`http://…`, `mailto:`) → null
57
+ * - pure anchors (`#section`) → null
58
+ * - bundle-absolute (`/commands/x.md`) → `commands/x`
59
+ * - relative (`../facts/x.md`) → resolved against `from`'s directory
60
+ * Anchors and query strings are stripped before ID normalization.
61
+ */
62
+ export function resolveLinkTarget(fromId: string, rawTarget: string): string | null {
63
+ let t = rawTarget.trim();
64
+ if (!t || t.startsWith("#") || /^[a-z][a-z0-9+.-]*:/i.test(t)) return null; // external/protocol/anchor
65
+ t = t.split("#")[0]!.split("?")[0]!.trim();
66
+ if (!t) return null;
67
+ let full: string;
68
+ if (t.startsWith("/")) {
69
+ full = t.replace(/^\/+/, "");
70
+ } else {
71
+ const slash = fromId.lastIndexOf("/");
72
+ const fromDir = slash === -1 ? "" : fromId.slice(0, slash);
73
+ full = fromDir ? posix.normalize(`${fromDir}/${t}`) : posix.normalize(t);
74
+ }
75
+ if (!full || full.startsWith("..")) return null; // escaped the bundle — not a concept ref
76
+ const id = conceptId(full);
77
+ return id || null;
78
+ }
79
+
80
+ /** Build the cross-link graph from a set of concepts. Broken links are kept
81
+ * (in `broken`) rather than dropped, so lint can surface them. */
82
+ export function buildConceptGraph(concepts: GraphConcept[]): ConceptGraph {
83
+ const nodes = new Set(concepts.map(c => conceptId(c.relPath)));
84
+ const edges = new Map<string, Set<string>>();
85
+ const broken = new Map<string, Set<string>>();
86
+ for (const c of concepts) {
87
+ const from = conceptId(c.relPath);
88
+ LINK_RE.lastIndex = 0;
89
+ let m: RegExpExecArray | null;
90
+ while ((m = LINK_RE.exec(c.body)) !== null) {
91
+ const to = resolveLinkTarget(from, m[1]!);
92
+ if (!to || to === from) continue;
93
+ if (nodes.has(to)) addEdge(edges, from, to);
94
+ else addEdge(broken, from, to);
95
+ }
96
+ }
97
+ return { nodes, edges, broken };
98
+ }
99
+
100
+ /** Undirected adjacency (links are navigable both ways for discovery). */
101
+ function undirectedAdjacency(graph: ConceptGraph): Map<string, Set<string>> {
102
+ const adj = new Map<string, Set<string>>();
103
+ for (const [from, tos] of graph.edges) {
104
+ for (const to of tos) {
105
+ addEdge(adj, from, to);
106
+ addEdge(adj, to, from);
107
+ }
108
+ }
109
+ return adj;
110
+ }
111
+
112
+ /**
113
+ * Expand a set of seed concept IDs along the (undirected) link graph by up to
114
+ * `hops` steps, returning seeds + reachable neighbours. Seeds not present as
115
+ * nodes are dropped. With `hops` 0 this is just the valid seeds.
116
+ */
117
+ export function expandByGraph(seedIds: Iterable<string>, graph: ConceptGraph, hops = 1): Set<string> {
118
+ const adj = undirectedAdjacency(graph);
119
+ const result = new Set<string>();
120
+ for (const id of seedIds) if (graph.nodes.has(id)) result.add(id);
121
+ let frontier = [...result];
122
+ for (let h = 0; h < hops && frontier.length > 0; h++) {
123
+ const next: string[] = [];
124
+ for (const id of frontier) {
125
+ for (const nb of adj.get(id) ?? []) {
126
+ if (!result.has(nb)) {
127
+ result.add(nb);
128
+ next.push(nb);
129
+ }
130
+ }
131
+ }
132
+ frontier = next;
133
+ }
134
+ return result;
135
+ }
136
+
137
+ /** A lenient lint report over the concept graph (warnings, never hard failures). */
138
+ export interface GraphLintReport {
139
+ /** Concept IDs with no incoming or outgoing edges. */
140
+ orphans: string[];
141
+ /** Links whose target resolves to no concept node. */
142
+ brokenLinks: { from: string; to: string }[];
143
+ /** Concepts that share a (case-insensitive) title — merge/contradiction candidates. */
144
+ duplicates: { title: string; ids: string[] }[];
145
+ }
146
+
147
+ /** Lint the bundle's graph: orphan concepts, broken links, duplicate titles.
148
+ * Purely advisory — mirrors llm-wiki's lint pass (broken/orphan/contradiction). */
149
+ export function lintConceptGraph(concepts: GraphConcept[], graph: ConceptGraph): GraphLintReport {
150
+ const linked = new Set<string>();
151
+ for (const [from, tos] of graph.edges) {
152
+ if (tos.size > 0) linked.add(from);
153
+ for (const to of tos) linked.add(to);
154
+ }
155
+ const orphans = [...graph.nodes].filter(id => !linked.has(id)).sort();
156
+
157
+ const brokenLinks: { from: string; to: string }[] = [];
158
+ for (const [from, tos] of graph.broken) {
159
+ for (const to of tos) brokenLinks.push({ from, to });
160
+ }
161
+ brokenLinks.sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to));
162
+
163
+ const byTitle = new Map<string, string[]>();
164
+ for (const c of concepts) {
165
+ const title = (c.title ?? "").trim();
166
+ if (!title) continue;
167
+ const key = title.toLowerCase();
168
+ const ids = byTitle.get(key) ?? [];
169
+ ids.push(conceptId(c.relPath));
170
+ byTitle.set(key, ids);
171
+ }
172
+ const duplicates: { title: string; ids: string[] }[] = [];
173
+ for (const ids of byTitle.values()) {
174
+ if (ids.length > 1) duplicates.push({ title: ids.length ? (concepts.find(c => conceptId(c.relPath) === ids[0])?.title ?? "").trim() : "", ids: ids.sort() });
175
+ }
176
+ duplicates.sort((a, b) => a.title.localeCompare(b.title));
177
+
178
+ return { orphans, brokenLinks, duplicates };
179
+ }
180
+
181
+ /**
182
+ * Whether the optional graphify tool is available on PATH. The built-in graph
183
+ * is always the primary layer; graphify is a best-effort enrichment, so callers
184
+ * degrade gracefully when this is false. `detect` is injectable for testing.
185
+ */
186
+ export function graphifyAvailable(detect: () => boolean = defaultGraphifyDetect): boolean {
187
+ try {
188
+ return detect();
189
+ } catch {
190
+ return false;
191
+ }
192
+ }
193
+
194
+ function defaultGraphifyDetect(): boolean {
195
+ // Bun.which resolves a binary on PATH without spawning it.
196
+ const which = (globalThis as { Bun?: { which?: (cmd: string) => string | null } }).Bun?.which;
197
+ return typeof which === "function" ? which("graphify") != null : false;
198
+ }
@@ -15,8 +15,9 @@ import { spawn as nodeSpawn } from "node:child_process";
15
15
  import * as path from "node:path";
16
16
  import { callLlm, type Message } from "./loop";
17
17
  import { jeoEnv } from "../util/env";
18
- import { parseConcept, serializeConcept, slugify, isReservedFile } from "./memory-okf";
18
+ import { parseConcept, serializeConcept, slugify, isReservedFile, conceptId } from "./memory-okf";
19
19
  import { tryExtractJsonObject } from "./json";
20
+ import { buildConceptGraph, expandByGraph, lintConceptGraph, type GraphLintReport } from "./memory-graph";
20
21
 
21
22
  /** On-disk document cap — the distill prompt instructs the model to stay under it. */
22
23
  export const MEMORY_MAX_CHARS = 6_000;
@@ -82,6 +83,14 @@ export async function loadConcepts(cwd: string): Promise<Concept[]> {
82
83
  return loadConceptsFromBundle(path.join(cwd, ".jeo", "memory"));
83
84
  }
84
85
 
86
+ /** Lint the concept bundle's cross-link graph (Sprint 04): orphan concepts,
87
+ * broken links, and duplicate-title merge candidates. Advisory only — mirrors
88
+ * llm-wiki's lint pass. Returns empty lists for an empty/absent bundle. */
89
+ export async function lintMemoryBundle(cwd: string): Promise<GraphLintReport> {
90
+ const concepts = await loadConcepts(cwd);
91
+ return lintConceptGraph(concepts, buildConceptGraph(concepts));
92
+ }
93
+
85
94
  async function loadConceptsFromBundle(bundleDir: string): Promise<Concept[]> {
86
95
  const files = await findMarkdownFiles(bundleDir);
87
96
  const concepts: Concept[] = [];
@@ -146,14 +155,31 @@ export function searchConcepts(concepts: Concept[], query: string): { concept: C
146
155
  }
147
156
 
148
157
  /** Priority order for injection: high-confidence "core" concepts first, then by
149
- * query relevance (descending), preserving input order as a stable tiebreak. */
158
+ * query relevance (descending), then concepts the relevant ones LINK TO (1-hop
159
+ * graph expansion — Sprint 04: a directly-hit concept pulls its neighbours in as
160
+ * context ahead of unrelated noise), preserving input order as a stable tiebreak. */
150
161
  function priorityOrder(concepts: Concept[], query?: string): Concept[] {
151
162
  const tokens = tokenize(query);
163
+ // 1-hop graph expansion: seed from concepts the query directly hits, then mark
164
+ // their link-neighbours as "related" so they outrank unrelated zero-score noise.
165
+ const related = new Set<string>();
166
+ if (tokens.length > 0) {
167
+ const graph = buildConceptGraph(concepts);
168
+ const seeds = concepts.filter(c => scoreConcept(c, tokens) > 0).map(c => conceptId(c.relPath));
169
+ for (const id of expandByGraph(seeds, graph, 1)) related.add(id);
170
+ }
152
171
  return concepts
153
- .map((concept, i) => ({ concept, i, core: concept.confidence === "high", score: scoreConcept(concept, tokens) }))
172
+ .map((concept, i) => ({
173
+ concept,
174
+ i,
175
+ core: concept.confidence === "high",
176
+ score: scoreConcept(concept, tokens),
177
+ related: related.has(conceptId(concept.relPath)),
178
+ }))
154
179
  .sort((a, b) => {
155
180
  if (a.core !== b.core) return a.core ? -1 : 1;
156
181
  if (b.score !== a.score) return b.score - a.score;
182
+ if (a.related !== b.related) return a.related ? -1 : 1;
157
183
  return a.i - b.i;
158
184
  })
159
185
  .map(s => s.concept);