magic-context icon indicating copy to clipboard operation
magic-context copied to clipboard

Historian artifacts are written into the project directory, but they are temporary files and a session is not tied to a project

Open zapadinsky opened this issue 2 weeks ago • 2 comments

Short description

Historian artifacts are written to <project>/.cortexkit/magic-context although they are temporary files of a session, not project data

What happened?

Every historian pass leaves its intermediate output inside the working tree:

<project>/.cortexkit/magic-context/historian/ses_<id>-recomp-ses_<id>-804-968-pass-5-initial-<ts>.xml

The path is hardcoded:

function getProjectMagicContextDir(directory) {
  return path.join(directory, ".cortexkit", "magic-context");
}
function getProjectMagicContextHistorianDir(directory) {
  return path.join(getProjectMagicContextDir(directory), "historian");
}
function historianResponseDumpDir(directory) {
  return getProjectMagicContextHistorianDir(directory);
}
function dumpHistorianResponse(sessionId, directory, label, text) {
  try {
    const dumpDir = historianResponseDumpDir(directory);
    mkdirSync(dumpDir, { recursive: true });
    ensureCortexKitArtifactGitignore(directory);
    const safeSessionId = sanitizeDumpName(sessionId);
    const safeLabel = sanitizeDumpName(label);
    const dumpPath = join3(dumpDir, `${safeSessionId}-${safeLabel}-${Date.now()}.xml`);
    writeFileSync2(dumpPath, text, "utf8");
    sessionLog2(sessionId, "compartment agent: historian response dumped", { label, dumpPath });
    return dumpPath;
  } catch (error) { ... return; }
}

These files are temporary: written once for a single pass, read once, afterwards useful only for debugging. The filename already carries the session id, the compartment range and the pass number — nothing in them is addressed by project path. The plugin already puts its own scratch output where it belongs, e.g. MAGIC_CONTEXT_LOG_PATH defaults to <os.tmpdir()>/<harness>/magic-context/magic-context.log, and doc-diff scratch files go to mc-doc-diff-* in the same temporary directory. Historian dumps should follow that, i.e. live in the OS temporary directory, not in a repository.

A session is not tied to a project: its current project is a mutable variable and can change at any moment. Session history belongs to the session, not to whatever directory happened to be current when the pass ran. Today, moving a session to another directory leaves orphaned dumps in the old tree and starts writing new ones into the new one, splitting one logical chain of work across unrelated projects — even though project membership is already modelled in the store (session_projects, workspaces, project_state), so per-project files are not needed for it.

It also breaks on working trees we do not own: shared corporate storage, read-only checkouts, containers, CI worktrees, or a project that itself lives in the temporary directory. Creating a writable directory there is either impossible or unwanted for everyone sharing that tree.

What I expected: historian artifacts under the OS temporary directory, keyed by session, for example

<os.tmpdir()>/cortexkit/magic-context/<session-id>/historian/<file>.xml

An explicit override (e.g. MAGIC_CONTEXT_TEMP_DIR) would be welcome for machines where the temporary directory is unsuitable.

Note on docs-update-proposals/: it is a separate matter. Those files target the project's ARCHITECTURE.md / STRUCTURE.md, so keeping them project-scoped may be intentional; that decision should not force historian dumps into the working tree.

Diagnostics


Plugin version

0.49.52

OpenCode version

2.2.1

Platform

No response

Client

OpenCode TUI (CLI)

Log output (optional)


zapadinsky avatar Nov 16 '26 20:11 zapadinsky

Thanks for the clear report, and you're right.

These files went into the project on purpose at first: the historian used to read some of its own files back with its Read tool, and OpenCode asks for permission before reading anything outside the project. The response dumps you found are not read by the model at all. They are kept only when a historian pass fails its checks, for debugging, so there's no reason for them to live in the working tree.

The fix moves them to the OS temporary directory, per session, next to Magic Context's log: <temp dir>/<harness>/magic-context/historian/<session-id>/. Nothing is written into the project for them any more. The temporary directory follows the OS settings (TMPDIR on Linux and macOS, TEMP on Windows), so you can point it elsewhere that way. doctor and issue bundles will read both the new place and the old one. Existing dumps in your projects aren't touched; the folder is git-ignored and safe to delete.

Docs-update proposals stay in the project, as you guessed, since they are meant for the project's own docs.

This will ship in the next 0.49 patch, and I'll post here when it's out.

magic-alfonso[bot] avatar Nov 16 '26 20:11 magic-alfonso[bot]

The fix shipped in v0.49.59. New historian response dumps go to the machine's temp folder, one folder per session, next to Magic Context's log, and no longer into the project. Files already under .cortexkit/magic-context/historian/ in a project are left as they are and are safe to delete; doctor lists both places.

magic-alfonso[bot] avatar Nov 17 '26 04:11 magic-alfonso[bot]