Understand any codebase instantly. System intelligence for codebases, built for humans and AI.
TypeScript aiai-memoryclaude-codeclicode-analysiscode-mappingcode-memorycodebase-understandingcodexdeveloper-toolsllmopenclawpersistent-memoryprogram-analysissoftware-architecturesystem-intelligencesystem-mapping
feat: add decision linking — --affects, --supersedes, --parent flags
riley0227aad0ff71c3d6
diff --git a/ix-cli/src/cli/__tests__/decide-linking.test.ts b/ix-cli/src/cli/__tests__/decide-linking.test.tsnew file mode 100644index 00000000..7b835dd0--- /dev/null+++ b/ix-cli/src/cli/__tests__/decide-linking.test.ts@@ -0,0 +1,43 @@+import { describe, it, expect } from "vitest";+import { buildDecisionPatch } from "../commands/decide.js";++describe("buildDecisionPatch", () => {+ it("creates a patch with DECISION_AFFECTS edges", () => {+ const patch = buildDecisionPatch(+ "Use client-side patch",+ "Avoid server coupling",+ {+ affects: [+ { id: "entity-1", kind: "class", name: "IngestionService" },+ { id: "entity-2", kind: "class", name: "IxClient" },+ ],+ }+ );+ expect(patch.ops.length).toBe(3); // 1 UpsertNode + 2 UpsertEdge+ expect(patch.ops[0].type).toBe("UpsertNode");+ expect(patch.ops[0].kind).toBe("decision");+ expect(patch.ops[1].type).toBe("UpsertEdge");+ expect(patch.ops[1].predicate).toBe("DECISION_AFFECTS");+ expect(patch.ops[2].predicate).toBe("DECISION_AFFECTS");+ });++ it("creates DECISION_SUPERSEDES edge when supersedes is provided", () => {+ const patch = buildDecisionPatch("New approach", "Better", {+ supersedes: "old-decision-id",+ });+ expect(patch.ops.length).toBe(2); // 1 UpsertNode + 1 UpsertEdge+ expect(patch.ops[1].predicate).toBe("DECISION_SUPERSEDES");+ expect(patch.ops[1].src).toBe(patch.ops[0].id); // new decision → old+ expect(patch.ops[1].dst).toBe("old-decision-id");+ });++ it("creates DECISION_CHILD edge when parent is provided", () => {+ const patch = buildDecisionPatch("Sub-decision", "Detail", {+ parent: "parent-decision-id",+ });+ expect(patch.ops.length).toBe(2);+ expect(patch.ops[1].predicate).toBe("DECISION_CHILD");+ expect(patch.ops[1].src).toBe("parent-decision-id"); // parent → child+ expect(patch.ops[1].dst).toBe(patch.ops[0].id);+ });+});diff --git a/ix-cli/src/cli/commands/decide.ts b/ix-cli/src/cli/commands/decide.tsindex 8de6c32f..f613b99a 100644--- a/ix-cli/src/cli/commands/decide.ts+++ b/ix-cli/src/cli/commands/decide.ts@@ -1,6 +1,86 @@import type { Command } from "commander";import { IxClient } from "../../client/api.js";import { getEndpoint } from "../config.js";+import { resolveEntity } from "../resolve.js";+import { deterministicId } from "../github/transform.js";+import type { GraphPatchPayload, PatchOp } from "../../client/types.js";++interface DecisionLinkOpts {+ affects?: { id: string; kind: string; name: string }[];+ supersedes?: string;+ parent?: string;+}++export function buildDecisionPatch(+ title: string,+ rationale: string,+ linkOpts: DecisionLinkOpts = {}+): GraphPatchPayload {+ const now = new Date().toISOString();+ const decisionId = deterministicId(`decision:${title}:${now}`);+ const ops: PatchOp[] = [];++ // 1. UpsertNode for the decision+ ops.push({+ type: "UpsertNode",+ id: decisionId,+ kind: "decision",+ name: title,+ attrs: { rationale, created_at: now },+ });++ // 2. DECISION_AFFECTS edges+ if (linkOpts.affects) {+ for (const entity of linkOpts.affects) {+ ops.push({+ type: "UpsertEdge",+ id: deterministicId(`${decisionId}:DECISION_AFFECTS:${entity.id}`),+ src: decisionId,+ dst: entity.id,+ predicate: "DECISION_AFFECTS",+ attrs: {},+ });+ }+ }++ // 3. DECISION_SUPERSEDES edge+ if (linkOpts.supersedes) {+ ops.push({+ type: "UpsertEdge",+ id: deterministicId(`${decisionId}:DECISION_SUPERSEDES:${linkOpts.supersedes}`),+ src: decisionId,+ dst: linkOpts.supersedes,+ predicate: "DECISION_SUPERSEDES",+ attrs: {},+ });+ }++ // 4. DECISION_CHILD edge (parent → child)+ if (linkOpts.parent) {+ ops.push({+ type: "UpsertEdge",+ id: deterministicId(`${linkOpts.parent}:DECISION_CHILD:${decisionId}`),+ src: linkOpts.parent,+ dst: decisionId,+ predicate: "DECISION_CHILD",+ attrs: {},+ });+ }++ return {+ patchId: decisionId,+ actor: "ix-cli",+ timestamp: now,+ source: {+ uri: `ix://decision/${encodeURIComponent(title)}`,+ extractor: "ix-cli:decide",+ sourceType: "Decision",+ },+ baseRev: 0,+ ops,+ replaces: [],+ };+}export function registerDecideCommand(program: Command): void {program@@ -8,14 +88,70 @@ export function registerDecideCommand(program: Command): void {.description("Record a design decision").requiredOption("--rationale <text>", "Rationale for the decision").option("--intent-id <id>", "Link to an intent")+ .option("--affects <entities>", "Comma-separated entity names to link (creates DECISION_AFFECTS edges)")+ .option("--supersedes <id>", "Decision ID this supersedes")+ .option("--parent <id>", "Parent decision ID").option("--format <fmt>", "Output format (text|json)", "text")- .action(async (title: string, opts: { rationale: string; intentId?: string; format: string }) => {- const client = new IxClient(getEndpoint());- const result = await client.decide(title, opts.rationale, { intentId: opts.intentId });- if (opts.format === "json") {- console.log(JSON.stringify(result, null, 2));- } else {- console.log(`Decision recorded: ${result.nodeId} (rev ${result.rev})`);+ .action(+ async (+ title: string,+ opts: {+ rationale: string;+ intentId?: string;+ affects?: string;+ supersedes?: string;+ parent?: string;+ format: string;+ }+ ) => {+ const client = new IxClient(getEndpoint());+ const hasLinks = opts.affects || opts.supersedes || opts.parent;++ if (hasLinks) {+ // Use GraphPatch path for linked decisions+ let resolvedAffects: { id: string; kind: string; name: string }[] | undefined;++ if (opts.affects) {+ const names = opts.affects.split(",").map((s) => s.trim());+ resolvedAffects = [];+ for (const name of names) {+ const resolved = await resolveEntity(client, name, [+ "class", "module", "file", "function", "method", "trait", "object", "interface",+ ]);+ if (resolved) {+ resolvedAffects.push({ id: resolved.id, kind: resolved.kind, name: resolved.name });+ }+ }+ }++ const patch = buildDecisionPatch(title, opts.rationale, {+ affects: resolvedAffects,+ supersedes: opts.supersedes,+ parent: opts.parent,+ });++ if (opts.intentId) {+ patch.intent = opts.intentId;+ }++ const result = await client.commitPatch(patch);+ if (opts.format === "json") {+ console.log(JSON.stringify({ ...result, decisionId: patch.ops[0].id }, null, 2));+ } else {+ console.log(`Decision recorded: ${patch.ops[0].id} (rev ${result.rev})`);+ if (resolvedAffects?.length) {+ console.log(` Linked to: ${resolvedAffects.map((e) => e.name).join(", ")}`);+ }+ }+ } else {+ // Use the original backend endpoint for simple decisions+ const result = await client.decide(title, opts.rationale, { intentId: opts.intentId });+ if (opts.format === "json") {+ console.log(JSON.stringify(result, null, 2));+ } else {+ console.log(`Decision recorded: ${result.nodeId} (rev ${result.rev})`);+ }+ }}- });+ );}