Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/integrations/route-intent-initial.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Provisioning choices are local enabled-only overrides, never writes to Home policy. */
import { mkdirSync } from "node:fs";
import { join } from "node:path";
import { lstatSync, mkdirSync, statSync } from "node:fs";
import { dirname, join } from "node:path";
import { atomicWriteFileNoFollow } from "../config/atomic-write";
import { readBoundedRegularFileSync } from "../lib/bounded-file-read";
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
Expand Down Expand Up @@ -61,4 +61,16 @@ export function initialRouteOutcomeMetadata(linkId: string, document: HomeRouteI
? { ...row, initialIntent: { enabled: entry.enabled }, initialRevision: entry.revision } : row;
};
}
export function clearInitialRouteIntent(linkId: string, root = routeIntentStatePath()): void { writeInitial(linkId, {}, root); }
export function clearInitialRouteIntent(linkId: string, root = routeIntentStatePath()): void {
assertNotRealHomeUnderTest(root);
const path = recordPath(linkId, root);
// ENOENT below a broken directory link is not proof that the selection is absent.
let entry = path;
while (!lstatSync(entry, { throwIfNoEntry: false })) {
const parent = dirname(entry);
if (parent === entry) break;
entry = parent;
}
if (entry !== path && statSync(entry).isDirectory()) return;
writeInitial(linkId, {}, root);
}
2 changes: 1 addition & 1 deletion structure/clients/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parsing and ownership rules below.
| `src/integrations/target.ts` | Which file one operation reads, writes and records, and whether a write there reaches the client. |
| `src/integrations/config-io.ts` | Bounded regular-file loading and parsing; production reads reject symlinks and stop after 4 MiB, and writes past the same bound are refused so a mutation cannot strand a file it cannot read back. `src/lib/bounded-file-read.ts` starts its buffer from the opened size and grows only as needed, retaining the limit-plus-one overflow probe when a file grows concurrently and returning only bytes actually read. Values that cannot round-trip through the target serializer are rejected before mutation. |
| `src/integrations/kilo-candidates.ts` | Inspects all Kilo global config candidates for unsafe files and a competing `provider.opencodex` block before status or any operation that adds or replaces a block. |
| `src/integrations/state.ts` | The single `absent` / `current` / `stale` / `conflict` / `unsafe` classifier used by status and every writer operation. `src/integrations/route-intent.ts` uses the coordinated writer for each local Home/Child client, preserving ownership and per-client failure outcomes. `src/client/route-intent-apply.ts` binds native adapters and lifecycle/runtime fences; connected sync reads the exact served model IDs, preserves native IDs, and requires the published port to agree. Aside selects userIds from a manifest snapshot verified against the enumerated profile roster and rechecked before commit. Initial provisioning choices persist locally per link until the corresponding Home client revision changes; local opt-outs remain off-only. Receipts withdraw old success before mutation and attach each attempted intent digest. Off intents reconcile before model discovery; an unavailable served roster leaves enabled clients stale. Combo identity comes from the authenticated exact-GET route-catalog projection of public selectors and canonical keys, separate from intent, and an expanded `--fast` or `--<effort>` selector takes its listed base's key; discovery-bearing management reads remain denied. Disconnect drains Link-owned file routes before credential removal, refuses malformed or missing ownership evidence, and retains pending evidence on conflict; only a link-bound proof that no route apply began for the current connection exempts standalone ownership records from the missing-receipt refusal. Explicit recovery snapshots an owned conflict through the existing private overwrite journal before disabling its keys; unowned blocks and unsafe paths are never adopted. |
| `src/integrations/state.ts` | The single `absent` / `current` / `stale` / `conflict` / `unsafe` classifier used by status and every writer operation. `src/integrations/route-intent.ts` uses the coordinated writer for each local Home/Child client, preserving ownership and per-client failure outcomes. `src/client/route-intent-apply.ts` binds native adapters and lifecycle/runtime fences; connected sync reads the exact served model IDs, preserves native IDs, and requires the published port to agree. Aside selects userIds from a manifest snapshot verified against the enumerated profile roster and rechecked before commit. Initial provisioning choices persist locally per link until the corresponding Home client revision changes; local opt-outs remain off-only. Disconnect clears a recorded initial selection atomically and leaves an absent selection unmaterialized. Receipts withdraw old success before mutation and attach each attempted intent digest. Off intents reconcile before model discovery; an unavailable served roster leaves enabled clients stale. Combo identity comes from the authenticated exact-GET route-catalog projection of public selectors and canonical keys, separate from intent, and an expanded `--fast` or `--<effort>` selector takes its listed base's key; discovery-bearing management reads remain denied. Disconnect drains Link-owned file routes before credential removal, refuses malformed or missing ownership evidence, and retains pending evidence on conflict; only a link-bound proof that no route apply began for the current connection exempts standalone ownership records from the missing-receipt refusal. Explicit recovery snapshots an owned conflict through the existing private overwrite journal before disabling its keys; unowned blocks and unsafe paths are never adopted. |
| `src/integrations/ownership.ts` | Durable ownership records: file, contribution fingerprints, exact paths, operation identity and [export naming policy](export-model-names.md). |
| `src/integrations/ownership-policy.ts` | Client-scoped declarations for fields a client is documented to derive after apply. It must never contain a broad format-wide exemption. |
| `src/integrations/writer.ts` | Apply, refresh, disable, and restore transactions, including snapshot-first ordering, compare-before-commit, and compensation. Freezing an input copies the proxy configuration and the model roster as plain data before the first await, so the plan a revalidation approves and the document that follows it read one input; an input that cannot be copied is refused rather than read twice. Aside captures the same configuration copy when its context is created, because its preference write edits the live configuration between the check and the profile writes. |
Expand Down
35 changes: 35 additions & 0 deletions tests/clients/route-intent-connect-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,41 @@ function scenario(body: string) {
} finally { rmSync(root, { recursive: true, force: true }); }
}

test("clearing an absent initial selection leaves the Link state directory untouched", () => {
const result = scenario(`
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { clearInitialRouteIntent, readInitialRouteIntent } from './src/integrations/route-intent-initial';
import { routeIntentStatePath } from './src/integrations/route-intent-state';
const root = routeIntentStatePath();
const link = 'lnk_0123456789abcdef';
clearInitialRouteIntent(link, root);
const createdRoot = existsSync(root);
mkdirSync(root, { recursive: true });
writeFileSync(join(root, 'unrelated'), 'keep');
clearInitialRouteIntent(link, root);
console.log(JSON.stringify({ createdRoot, entries: readdirSync(root), selection: readInitialRouteIntent(link, root) }));
`);
expect(result).toEqual({ createdRoot: false, entries: ["unrelated"], selection: {} });
});

test("clearing an initial selection reports an unreachable state directory", () => {
const result = scenario(`
import { throws } from 'node:assert/strict';
import { lstatSync, mkdirSync, rmdirSync, symlinkSync } from 'node:fs';
import { join } from 'node:path';
import { clearInitialRouteIntent } from './src/integrations/route-intent-initial';
const target = join(process.env.HOME, 'original');
const alias = join(process.env.HOME, 'alias');
mkdirSync(target);
symlinkSync(target, alias, process.platform === 'win32' ? 'junction' : 'dir');
rmdirSync(target);
throws(() => clearInitialRouteIntent('lnk_0123456789abcdef', join(alias, 'route-intent')));
console.log(JSON.stringify({ aliasRetained: lstatSync(alias).isSymbolicLink() }));
`);
expect(result.aliasRetained).toBe(true);
});

const cliSetup = `
import { mock } from 'bun:test';
import { Readable } from 'node:stream';
Expand Down
Loading