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
4 changes: 3 additions & 1 deletion .github/workflows/native-hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ jobs:
if: always()
with:
name: host-plugin-macos-results
path: ${{ runner.temp }}/crosshead-plugin-smoke/
path: |
${{ runner.temp }}/crosshead-plugin-smoke/host-plugins-result.json
${{ runner.temp }}/crosshead-plugin-smoke/logs/
include-hidden-files: true
if-no-files-found: ignore
retention-days: 7
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crosshead/runtime",
"version": "0.5.0-alpha.12",
"version": "0.5.0-alpha.13",
"description": "Crosshead local runtime: persistent memory for Claude Code, Codex, Pi, Hermes and OpenCode. CLI, daemon, host adapters and hooks.",
"license": "Apache-2.0",
"private": true,
Expand Down
20 changes: 20 additions & 0 deletions src/runtime/adapter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,43 @@ export const summarizeHotMemory = (value: unknown): string | null => {
}
try {
const parsed = JSON.parse(value) as Record<string, unknown>;
const checkpoints = Array.isArray(parsed.continuityCheckpoints)
? parsed.continuityCheckpoints.filter((entry): entry is Record<string, unknown> => Boolean(entry) && typeof entry === "object" && !Array.isArray(entry))
: null;
const latestCheckpoint = checkpoints?.sort((a, b) =>
(Date.parse(String(b.occurredAt)) || 0) - (Date.parse(String(a.occurredAt)) || 0))[0];
const fields = [
sanitizeString(parsed.currentGoal),
parsed.latestTurn && typeof parsed.latestTurn === "object" && !Array.isArray(parsed.latestTurn)
? sanitizeString((parsed.latestTurn as Record<string, unknown>).summary)
: null,
sanitizeString(parsed.summary),
sanitizeString(latestCheckpoint?.summary) ?? sanitizeString(latestCheckpoint?.goal),
].filter((entry): entry is string => entry !== null);
if (fields.length > 0) {
return fields.join(" | ").slice(0, 280);
}
if (checkpoints) return null;
} catch {
// Raw string hot-memory content is still usable.
}
const normalized = value.replace(/\s+/g, " ").trim();
return normalized.length <= 280 ? normalized : `${normalized.slice(0, 277).trimEnd()}...`;
};

export const summarizeHotMemorySnapshot = (snapshot: Record<string, unknown> | null, preferredRuntime: string): string | null => {
if (!snapshot) return null;
const entries = (Array.isArray(snapshot.scopes) ? snapshot.scopes : [snapshot])
.filter((entry): entry is Record<string, unknown> => Boolean(entry) && typeof entry === "object" && !Array.isArray(entry));
const preferred = (entry: Record<string, unknown>): boolean =>
entry.scope === preferredRuntime || String(entry.scope).startsWith(`ws-${preferredRuntime}-`);
for (const entry of [...entries.filter(preferred), ...entries.filter((candidate) => !preferred(candidate))]) {
const summary = summarizeHotMemory(entry.content);
if (summary) return summary;
}
return null;
};

export const summarizeJudgmentEntries = (value: unknown): string[] =>
Array.isArray(value)
? value
Expand Down
19 changes: 12 additions & 7 deletions src/runtime/claude-code-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ import {
parseArgs,
sanitizeString,
shellQuote,
summarizeHotMemory,
summarizeHotMemorySnapshot,
summarizeJudgmentEntries,
writeManagedFile,
} from "./adapter-utils";
import {
filterHotMemorySnapshotForWorkspace,
HostRuntimeAdapterBase,
type HostAdapterCompactEventRequest,
type HostAdapterIdentity,
Expand Down Expand Up @@ -959,28 +960,31 @@ export class ClaudeCodeRuntimeAdapter extends HostRuntimeAdapterBase {

async createHandoff(input: ClaudeCodeAdapterHandoffCreateRequest): Promise<ClaudeCodeAdapterHandoffCreateResult> {
const profileName = input.profileName ?? this.config.profileName;
const workspaceId = input.workspaceId ?? `repo:${path.resolve(input.workspaceRoot)}`;
const needsHotSummary = !input.memory?.hotSummary;
const needsWarmIds = !input.memory?.warmIds || input.memory.warmIds.length === 0;
const needsJudgment =
// Hosted warm and judgment views are profile-wide and have no trustworthy project filter.
const needsWarmIds = !this.config.workspaceOnly && (!input.memory?.warmIds || input.memory.warmIds.length === 0);
const needsJudgment = !this.config.workspaceOnly && (
!input.memory?.selfModelIds ||
input.memory.selfModelIds.length === 0 ||
!input.reasoning?.currentTheory ||
!input.reasoning?.openQuestions ||
input.reasoning.openQuestions.length === 0 ||
!input.reasoning?.rejectedPaths ||
!input.reasoning.unresolvedRisks;
!input.reasoning.unresolvedRisks);
const needsIdentity = !input.identity?.npub;
const needsPolicyRef = !input.policy?.policyRef;

const targetRuntime = input.targetRuntime ?? "codex";
const targetLabel = targetRuntime === "codex" ? "Codex" : "Claude Code";
const warnings: string[] = [];
const [hot, warm, judgment, status] = await Promise.all([
needsHotSummary ? this.client.readHotMemory(profileName) : Promise.resolve(null),
const [rawHot, warm, judgment, status] = await Promise.all([
needsHotSummary ? this.client.readHotMemory(profileName, "all") : Promise.resolve(null),
optionalHostedRead(needsWarmIds, () => this.client.listWarmMemory(profileName, { status: "active" }), "Warm memory", warnings),
optionalHostedRead(needsJudgment, () => this.client.inspectContinuityJudgment(profileName), "Continuity judgment", warnings),
needsIdentity || needsPolicyRef ? this.client.status(profileName) : Promise.resolve(null),
]);
const hot = filterHotMemorySnapshotForWorkspace(rawHot, workspaceId, this.config.workspaceOnly, this.config.legacyUnscoped, this.config.legacyBefore);

const snapshot =
judgment?.snapshot && typeof judgment.snapshot === "object" && !Array.isArray(judgment.snapshot)
Expand Down Expand Up @@ -1044,7 +1048,7 @@ export class ClaudeCodeRuntimeAdapter extends HostRuntimeAdapterBase {
nextAction: input.reasoning?.nextAction ?? null,
},
memory: {
hotSummary: input.memory?.hotSummary ?? summarizeHotMemory(hot?.content),
hotSummary: input.memory?.hotSummary ?? summarizeHotMemorySnapshot(hot, this.config.workspaceOnly ? "claude-code" : "shared"),
warmIds: input.memory?.warmIds ?? activeWarmIds,
coldChunkIds: input.memory?.coldChunkIds ?? [],
projectModelIds: input.memory?.projectModelIds ?? [],
Expand Down Expand Up @@ -1085,6 +1089,7 @@ export class ClaudeCodeRuntimeAdapter extends HostRuntimeAdapterBase {
const plainTextSummary = buildPlainTextContinuationSummary(translation, targetRuntime);
const restatementComparison = compareContinuityRestatement(materialization.startupContext, translation, targetRuntime);
const created = (await this.client.createHandoff({
profileName,
translation,
maxBytes: input.maxBytes,
})) as { handoff?: HandoffStoredRecord };
Expand Down
Loading
Loading