Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

feat: ix-cli HTTP client with TypeScript types for Memory Layer API

riley0227c00fdea59af4
diff --git a/ix-cli/src/client/api.ts b/ix-cli/src/client/api.ts
new file mode 100644
index 00000000..95701eee
--- /dev/null
+++ b/ix-cli/src/client/api.ts
@@ -0,0 +1,103 @@
+import type {
+ CommitResult,
+ StructuredContext,
+ GraphNode,
+ HealthResponse,
+ PatchSummary,
+} from "./types.js";
+
+export class IxClient {
+ constructor(private endpoint: string = "http://localhost:8090") {}
+
+ async query(
+ question: string,
+ opts?: { asOfRev?: number; depth?: string }
+ ): Promise<StructuredContext> {
+ return this.post("/v1/context", { query: question, ...opts });
+ }
+
+ async ingest(path: string, recursive?: boolean): Promise<CommitResult> {
+ return this.post("/v1/ingest", { path, recursive });
+ }
+
+ async decide(
+ title: string,
+ rationale: string,
+ opts?: { intentId?: string }
+ ): Promise<{ status: string; nodeId: string; rev: number }> {
+ return this.post("/v1/decide", { title, rationale, ...opts });
+ }
+
+ async search(term: string, limit?: number): Promise<GraphNode[]> {
+ return this.post("/v1/search", { term, limit });
+ }
+
+ async entity(id: string): Promise<{
+ node: GraphNode;
+ claims: unknown[];
+ edges: unknown[];
+ }> {
+ return this.get(`/v1/entity/${id}`);
+ }
+
+ async listTruth(): Promise<GraphNode[]> {
+ return this.get("/v1/truth");
+ }
+
+ async createTruth(
+ statement: string,
+ parentIntent?: string
+ ): Promise<{ status: string; nodeId: string; rev: number }> {
+ return this.post("/v1/truth", { statement, parentIntent });
+ }
+
+ async listPatches(): Promise<PatchSummary[]> {
+ return this.get("/v1/patches");
+ }
+
+ async getPatch(id: string): Promise<unknown> {
+ return this.get(`/v1/patches/${id}`);
+ }
+
+ async diff(
+ fromRev: number,
+ toRev: number,
+ entityId?: string
+ ): Promise<unknown> {
+ return this.post("/v1/diff", { fromRev, toRev, entityId });
+ }
+
+ async conflicts(): Promise<unknown[]> {
+ return this.get("/v1/conflicts");
+ }
+
+ async provenance(entityId: string): Promise<unknown> {
+ return this.post(`/v1/provenance/${entityId}`, {});
+ }
+
+ async health(): Promise<HealthResponse> {
+ return this.get("/v1/health");
+ }
+
+ private async post<T>(path: string, body: unknown): Promise<T> {
+ const resp = await fetch(`${this.endpoint}${path}`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(body),
+ });
+ if (!resp.ok) {
+ const text = await resp.text();
+ throw new Error(`${resp.status}: ${text}`);
+ }
+ return resp.json() as Promise<T>;
+ }
+
+ private async get<T>(path: string): Promise<T> {
+ const resp = await fetch(`${this.endpoint}${path}`);
+ if (!resp.ok) {
+ const text = await resp.text();
+ throw new Error(`${resp.status}: ${text}`);
+ }
+ return resp.json() as Promise<T>;
+ }
+}
diff --git a/ix-cli/src/client/types.ts b/ix-cli/src/client/types.ts
new file mode 100644
index 00000000..c28cc72b
--- /dev/null
+++ b/ix-cli/src/client/types.ts
@@ -0,0 +1,118 @@
+export interface CommitResult {
+ newRev: number;
+ status: "Ok" | "Idempotent" | "BaseRevMismatch";
+}
+
+export interface Factor {
+ value: number;
+ reason: string;
+}
+
+export interface ConfidenceBreakdown {
+ baseAuthority: Factor;
+ verification: Factor;
+ recency: Factor;
+ corroboration: Factor;
+ conflictPenalty: Factor;
+ intentAlignment: Factor;
+ score: number;
+}
+
+export interface Claim {
+ id: string;
+ entityId: string;
+ statement: string;
+ status: string;
+}
+
+export interface ScoredClaim {
+ claim: Claim;
+ confidence: ConfidenceBreakdown;
+ relevance: number;
+ finalScore: number;
+}
+
+export interface ConflictReport {
+ id: string;
+ claimA: string;
+ claimB: string;
+ reason: string;
+ recommendation: string;
+}
+
+export interface DecisionReport {
+ title: string;
+ rationale: string;
+ entityId?: string;
+ intentId?: string;
+ rev: number;
+}
+
+export interface IntentReport {
+ id: string;
+ statement: string;
+ status: string;
+ confidence: number;
+ parentIntent?: string;
+}
+
+export interface GraphNode {
+ id: string;
+ kind: string;
+ attrs: Record<string, unknown>;
+ provenance: {
+ sourceUri: string;
+ sourceHash?: string;
+ extractor: string;
+ sourceType: string;
+ observedAt: string;
+ };
+ createdRev: number;
+ deletedRev?: number;
+ createdAt: string;
+ updatedAt: string;
+}
+
+export interface GraphEdge {
+ id: string;
+ src: string;
+ dst: string;
+ predicate: string;
+ attrs: Record<string, unknown>;
+ createdRev: number;
+ deletedRev?: number;
+}
+
+export interface ContextMetadata {
+ query: string;
+ seedEntities: string[];
+ hopsExpanded: number;
+ asOfRev: number;
+ depth?: string;
+}
+
+export interface StructuredContext {
+ claims: ScoredClaim[];
+ conflicts: ConflictReport[];
+ decisions: DecisionReport[];
+ intents: IntentReport[];
+ nodes: GraphNode[];
+ edges: GraphEdge[];
+ metadata: ContextMetadata;
+}
+
+export interface SearchResult {
+ nodes: GraphNode[];
+}
+
+export interface PatchSummary {
+ patch_id: string;
+ rev: number;
+ intent?: string;
+ source_uri?: string;
+ timestamp?: string;
+}
+
+export interface HealthResponse {
+ status: string;
+}
diff --git a/ix-cli/test/client.test.ts b/ix-cli/test/client.test.ts
new file mode 100644
index 00000000..1b0664b0
--- /dev/null
+++ b/ix-cli/test/client.test.ts
@@ -0,0 +1,14 @@
+import { describe, it, expect } from "vitest";
+import { IxClient } from "../src/client/api.js";
+
+describe("IxClient", () => {
+ it("should construct with default endpoint", () => {
+ const client = new IxClient();
+ expect(client).toBeDefined();
+ });
+
+ it("should construct with custom endpoint", () => {
+ const client = new IxClient("http://localhost:9090");
+ expect(client).toBeDefined();
+ });
+});