Skip to content

Latest commit

 

History

History
157 lines (119 loc) · 8.32 KB

codex.md

File metadata and controls

157 lines (119 loc) · 8.32 KB

Codex

Verified 2026-08-05 against codex-cli 0.146.1 (@openai/codex), connecting to lorepack mcp speaking MCP 2026-07-28.

lorepack dev ./project-context
lorepack connect codex

The first command builds and serves; the second configures the client and then proves the server answers.

Connection proof

lorepack connect verifies the intended active build and reads a known cited source before reporting success. Wrong builds and unreadable context fail verification; JSON output carries the build ID and citation without source text. Client trust remains a separate step. See the shared verification contract for bounded reads, startup ordering and the automated verification date. External-client version records here are unchanged.

Trust the project, or nothing happens

Codex reads a project's .codex/config.toml only in a project you have trusted. In an untrusted project it does not warn, does not error, and does not log: codex mcp list simply answers with an empty list, and your agent has never heard of your documents.

So lorepack connect codex says this before it writes anything, and reports it as its own verification outcome afterwards:

  Not working yet: The server answers, but Codex only reads
  /home/me/project/.codex/config.toml in a project you have trusted, and this one is not
  trusted yet. Run `codex` here once and choose to trust the folder.

That is not a failure. The file is correct and one interactive step remains. Trust is recorded in your Codex home configuration:

[projects."/home/me/project"]
trust_level = "trusted"

What it writes, and where

Scope File When
project (default) <project>/.codex/config.toml lorepack connect codex
user $CODEX_HOME/config.toml, default ~/.codex/config.toml --scope user, never implied

project is the scope architecture §6.6 calls workspace, under the name the rest of the CLI already uses. There is deliberately not a third word for it.

The project file is one people commit. That is a legitimate thing to do, and the plan says so before writing, so the choice is yours to make knowingly: anyone who checks out the repository gets this server entry.

# Managed by Lorepack. `lorepack disconnect codex` removes exactly this block.
# x-lorepack {"projectRoot":"/absolute/path","createdAt":"..."}
[mcp_servers.lorepack]
command = "lorepack"
args = ["mcp", "--project", "/absolute/path", "--ensure-current"]
cwd = "/absolute/path"

An executable plus an argument array, never a concatenated shell string, which is what keeps a project path containing a space correct on Windows. --ensure-current means a fresh clone works without a prior lorepack build.

Our tools are read-only, so no Codex write-approval setting has to change for this to work.

Why the official CLI is not used for the write

Architecture §6.6 step 5 prefers a client's own CLI when it can express the chosen scope safely. Measured against 0.146.1, codex mcp add cannot:

  • it has no scope flag, writes $CODEX_HOME/config.toml, and reports Added global MCP server 'lorepack'. Lorepack defaults to the project;
  • it offers no way to attach the ownership marker that lets lorepack disconnect remove exactly our entry and nothing else.

It is used where it is authoritative and harmless: codex --version for detection, and codex mcp list --json, run from the project directory, for verification.

Why your configuration is safe

config.toml is a file you wrote by hand, and unlike JSON it carries comments that are often the most valuable lines in it. No JavaScript TOML library preserves a comment across a parse-and-rewrite, which was measured for three of them, so Lorepack does not do that:

  • It parses to understand, and splices to write. Only the lines of the Lorepack table change. Every comment, every section, every blank line and your file's line endings survive exactly as they were.
  • Nothing is written until you have agreed to it. connect plans every client first, prints the plan, and asks Apply these changes? [y/N]. Without a terminal, in a script or CI job, it prints the plan, writes nothing and exits 1 unless you pass --yes. --dry-run prints the plan and touches nothing.
  • The file is backed up first, with a timestamp, beside the original.
  • Writes are atomic. An interrupted run leaves the old file, not half of a new one.
  • Permissions are kept. The rewritten file and its backup keep the original's mode, so a 0600 file holding tokens stays 0600. A user-scope file Lorepack creates is 0600.
  • Links are never followed out of a project. If a project configuration file, or any directory on the way to it, is a symbolic link, connect and disconnect refuse with LORE_E_PATH_ESCAPE and read, back up and write nothing: a repository could otherwise link it to your home configuration and have your tokens copied into the project. A user-scope file that is a link (a dotfile manager's) is edited at its target, and the link stays.
  • A file that will not parse is refused, not overwritten. So is one whose mcp_servers is not a table of servers, and one that declares mcp_servers.lorepack through a dotted key with no table header, because appending to that would make the whole file stop parsing.
  • The ownership comment marks what we created, so lorepack disconnect removes exactly that. A server called lorepack that you wrote yourself is left alone.

The reasoning, the measurements and the rejected alternatives are in ../architecture/adr-toml-merge.md.

Removing it

lorepack disconnect codex

Removes the Lorepack block and leaves every other server, comment and setting where they were. On a file Lorepack wrote into, connect followed by disconnect returns it byte for byte: only the block and the one blank line placed before it go, so blank lines inside a multi-line string such as developer_instructions = """ ... """ stay. Before any edit is written, the result is parsed and compared with the original; if anything other than the Lorepack entry would change, nothing is written.

In $CODEX_HOME/config.toml, which every project shares, disconnect --scope user removes only the entry this project created. One another project created is left, and the output names that project. The ownership comment is plain ASCII, so a project path holding a control character such as DEL cannot make the file unparseable.

Verified by hand

Client trust prompts cannot be automated, so the whole flow was driven by hand against the real binary. This is the record (working agreement §7).

Date Client What was driven, and what it proved
2026-10-24 codex-cli 0.164.0, macOS arm64, Node 24.21.0 In a disposable project with isolated HOME and CODEX_HOME, the packed @lorepack/cli@0.1.0 wrote only the project .codex/config.toml. connect all --yes reported the expected untrusted-project state. The isolated Codex profile stopped at first-run sign-in. A second launch of the installed client displayed its native folder-access prompt with Trust and continue and Back to Agent Command Center; I chose Back without accepting. This confirms the prompt appears, but does not verify the post-trust MCP list.
2026-08-05 codex-cli 0.146.1 A project with a hand-written config.toml holding a comment, a sandbox section and one other MCP server. --dry-run printed the plan and the trust requirement and wrote nothing. lorepack connect codex backed the file up, added the block, kept every other line, and reported the untrusted project as its own outcome rather than as success. After trusting the project, codex mcp list --json returned ['lorepack', 'notes'] and lorepack connect codex reported Verified: Answered with 7 tools on protocol 2026-07-28, plus Update the existing Lorepack server with still exactly one entry. lorepack disconnect codex left the file byte for byte identical to the pre-connect backup, and codex mcp list then returned ['notes'].

If your version is not supported

lorepack connect codex --snippet

prints the exact TOML to paste and changes nothing.

Verified against

codex-cli 0.146.1, MCP protocol 2026-07-28, verified 2026-08-05. Local version smoke saw codex-cli 0.147.0 on 2026-08-13.