codex-context-map 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Han-1413141
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ <div align="center">
2
+
3
+ # Codex Context Map
4
+
5
+ **Know what your agent reads.**
6
+
7
+ An offline visual debugger for `AGENTS.md` discovery, overrides, and byte limits.
8
+
9
+ [Live demo](https://han-1413141.github.io/codex-context-map/) · [简体中文](README.zh-CN.md) · [How it works](docs/semantics.md) · [Releases](https://github.com/Han-1413141/codex-context-map/releases)
10
+
11
+ [![CI](https://github.com/Han-1413141/codex-context-map/actions/workflows/ci.yml/badge.svg)](https://github.com/Han-1413141/codex-context-map/actions/workflows/ci.yml)
12
+ [![npm](https://img.shields.io/npm/v/codex-context-map)](https://www.npmjs.com/package/codex-context-map)
13
+ ![Node](https://img.shields.io/badge/node-%3E%3D20-087f6b)
14
+ [![License: MIT](https://img.shields.io/badge/License-MIT-087f6b.svg)](LICENSE)
15
+
16
+ [![Codex Context Map showing a real, interactive instruction chain for the fictional Northstar workspace](docs/assets/preview.png)](https://han-1413141.github.io/codex-context-map/)
17
+
18
+ </div>
19
+
20
+ You added an instruction. Codex still behaves differently. Is the file outside the launch directory? Is an override hiding it? Did the byte budget cut off the last paragraph?
21
+
22
+ **Pick a directory and see the chain.** Switch directories to compare it. Lower the budget to reveal the cutoff. No account, API key, or model call required.
23
+
24
+ ## Try it in 10 seconds
25
+
26
+ Open the **[interactive demo](https://han-1413141.github.io/codex-context-map/)** and click **Hidden override**, **Budget cutoff**, or **Empty override**. You can also open a project folder: the page processes instruction files on your device.
27
+
28
+ Or inspect your repository with Node.js 20+:
29
+
30
+ ```bash
31
+ npx codex-context-map . --html context-map.html
32
+ ```
33
+
34
+ Open the generated `context-map.html` in your browser. It is a single, self-contained file that also works offline.
35
+
36
+ ```text
37
+ CODEX CONTEXT MAP · northstar
38
+
39
+ Launch directory: services/payments
40
+ Project content: 1,024 / 1,024 bytes
41
+
42
+ loaded AGENTS.md (535/535 bytes)
43
+ loaded services/AGENTS.md (264/264 bytes)
44
+ partial services/payments/AGENTS.override.md (225/748 bytes)
45
+ shadowed services/payments/AGENTS.md → project:services/payments/AGENTS.override.md
46
+ ```
47
+
48
+ This example comes from `npx codex-context-map --demo --max-bytes 1024`.
49
+
50
+ ## What you get
51
+
52
+ | Feature | What it answers |
53
+ | --- | --- |
54
+ | Directory map | Which instruction chain is discovered from this launch directory? |
55
+ | Override explanations | Which same-directory files are shadowed, including empty overrides? |
56
+ | Byte budget simulator | Which file is truncated, and how much content is lost? |
57
+ | Directory comparison | Which instruction sources are added, removed, or shared? |
58
+ | Assembled preview | What text does this discovery model produce, in order? |
59
+ | Portable HTML and JSON | Can I inspect the same snapshot offline or attach it to a bug report? |
60
+ | CI check | Does the chosen instruction chain exceed its configured budget? |
61
+
62
+ English and Chinese UI. No runtime dependencies. No background server. No telemetry or browser storage.
63
+
64
+ ## CLI examples
65
+
66
+ ```bash
67
+ # Inspect the directory containing this file
68
+ npx codex-context-map ./services/payments/handler.ts
69
+
70
+ # Compare against another launch directory, relative to the detected root
71
+ npx codex-context-map ./services/payments --compare apps/web
72
+
73
+ # Match your Codex configuration explicitly
74
+ npx codex-context-map . --max-bytes 65536 --fallback TEAM_GUIDE.md --fallback .agents.md
75
+
76
+ # Global AGENTS files are opt-in
77
+ npx codex-context-map . --global --html context-map.html
78
+
79
+ # Portable JSON with the selected result; fail CI when content is cut off
80
+ npx codex-context-map ./services/payments --json --check
81
+
82
+ # Explore the bundled fictional workspace
83
+ npx codex-context-map --demo --html demo.html
84
+ ```
85
+
86
+ Run `npx codex-context-map --help` for all options. `--check` returns **0** without a cutoff, **1** with a cutoff, and **2** for invalid input or I/O failures. It checks the selected directory. Use one invocation per critical launch directory in CI. Existing HTML files are protected unless you pass `--force`.
87
+
88
+ Without npm registry access, clone this repository and run `node bin/codex-context-map.js --demo`. No dependency installation is needed for the CLI. Release tarballs can also be installed with `npm install -g ./codex-context-map-0.1.0.tgz`.
89
+
90
+ ## A map with explicit boundaries
91
+
92
+ This is a **static discovery preview for one trusted project**, not a live view of a Codex conversation. It follows a [pinned upstream implementation](docs/semantics.md), with its assumptions visible:
93
+
94
+ - The CLI detects the nearest `.git` marker. Nested repositories form new boundaries. With no marker, only the launch directory is checked. `--root` supplies an explicit boundary.
95
+ - `AGENTS.override.md` takes priority over `AGENTS.md`, then configured fallbacks. A later directory adds to the chain; it does not erase all parent text.
96
+ - The project budget defaults to **32,768 content bytes**. Separators and optional global guidance are accounted for separately. This is not a token or billing estimate.
97
+ - **Configuration is not read automatically.** Match `--max-bytes`, `--fallback` and `--root` to your actual setup. Global guidance needs `--global`.
98
+ - Skills, MCP, hooks, account/thread instructions, system prompts, untrusted-project behavior, multiple environments and mid-session refresh are outside this model.
99
+ - Natural-language conflicts and whether a model obeys instructions cannot be proven by this tool.
100
+
101
+ The empty-file behavior in current source is more specific than the prose documentation. [See the exact rule, source reference, and test coverage.](docs/semantics.md)
102
+
103
+ ## Privacy
104
+
105
+ The CLI reads instruction filenames and directory metadata. It does not read your credentials, conversation history, or source-file contents. Global files are opt-in. The browser has `connect-src 'none'` and does not upload imported files. The initial hosted page request is handled by GitHub Pages as usual.
106
+
107
+ **Exports include instruction text and relative paths.** Review them before sharing; this tool does not redact secrets. The CLI skips symlinks with a warning. Browser folder pickers do not expose symlink metadata. Generated/dependency directories are excluded by default; use `--include-ignored` if needed. See [limits and exclusions](docs/semantics.md#scan-and-import-limits).
108
+
109
+ ## Development
110
+
111
+ ```bash
112
+ git clone https://github.com/Han-1413141/codex-context-map.git
113
+ cd codex-context-map
114
+ npm ci
115
+ npm run check
116
+ npx playwright install chromium
117
+ npm run test:browser
118
+ ```
119
+
120
+ `src/core.js` is the shared, pure discovery engine. `src/scan.js` handles filesystem input. `site/` contains the UI. `npm run build` produces the complete standalone demo at `docs/index.html`; no bundler is needed.
121
+
122
+ Contributions with reproducible discovery mismatches are especially useful. See [CONTRIBUTING.md](CONTRIBUTING.md) and the [roadmap](docs/roadmap.md).
123
+
124
+ MIT licensed. Independent project, not affiliated with or endorsed by OpenAI. Codex is a product of OpenAI.
@@ -0,0 +1,108 @@
1
+ <div align="center">
2
+
3
+ # Codex Context Map
4
+
5
+ **看清你的 Agent 读到了什么。**
6
+
7
+ 本地运行的 `AGENTS.md` 可视化调试器:加载链、覆盖关系、字节截断,一眼可见。
8
+
9
+ [在线演示](https://han-1413141.github.io/codex-context-map/) · [English](README.md) · [解析规则](docs/semantics.md) · [下载版本](https://github.com/Han-1413141/codex-context-map/releases)
10
+
11
+ [![CI](https://github.com/Han-1413141/codex-context-map/actions/workflows/ci.yml/badge.svg)](https://github.com/Han-1413141/codex-context-map/actions/workflows/ci.yml)
12
+ [![npm](https://img.shields.io/npm/v/codex-context-map)](https://www.npmjs.com/package/codex-context-map)
13
+ [![MIT](https://img.shields.io/badge/License-MIT-087f6b.svg)](LICENSE)
14
+
15
+ [![Codex Context Map 的真实界面,展示虚构 Northstar 项目的指令加载链](docs/assets/preview.png)](https://han-1413141.github.io/codex-context-map/)
16
+
17
+ </div>
18
+
19
+ 你写了指令,Codex 的行为却不符合预期:文件不在启动目录的搜索范围内?同目录有覆盖文件?最后一段被字节上限截去了?
20
+
21
+ **选一个目录,直接查看加载链。** 切换目录可比较指令来源;降低字节上限可看到截断位置。不需要账号、API Key 或模型调用。
22
+
23
+ ## 快速体验
24
+
25
+ 打开 **[在线演示](https://han-1413141.github.io/codex-context-map/)**,点击右上角「中文」,体验「隐藏的覆盖」「超出长度预算」「空覆盖文件」。也可以打开自己的项目文件夹,指令内容只在当前设备处理。
26
+
27
+ 使用 Node.js 20+ 在仓库中运行:
28
+
29
+ ```bash
30
+ npx codex-context-map . --html context-map.html
31
+ ```
32
+
33
+ 用浏览器打开生成的 `context-map.html`。这是一个完整独立的 HTML 文件,断网后也能使用。
34
+
35
+ ## 主要功能
36
+
37
+ | 功能 | 解决的问题 |
38
+ | --- | --- |
39
+ | 目录地图 | 从某目录启动时,会发现哪些指令文件? |
40
+ | 覆盖解释 | 哪个同目录文件被遮盖?空覆盖文件会怎样? |
41
+ | 字节预算模拟 | 哪个文件被截断、损失多少字节? |
42
+ | 目录对比 | 换一个启动目录,会新增、移除或共享哪些指令? |
43
+ | 合并预览 | 按此发现模型组装的指令全文是什么? |
44
+ | HTML / JSON 导出 | 如何离线检查,或附在问题报告中? |
45
+ | CI 检查 | 当前目录的指令链是否超过指定预算? |
46
+
47
+ 界面支持中英文,零运行时依赖,无后台服务、遥测或浏览器存储。
48
+
49
+ ## 命令示例
50
+
51
+ ```bash
52
+ # 检查文件所在目录
53
+ npx codex-context-map ./services/payments/handler.ts
54
+
55
+ # 与另一个目录比较;后者相对于检测到的项目根目录
56
+ npx codex-context-map ./services/payments --compare apps/web
57
+
58
+ # 显式匹配你的 Codex 配置
59
+ npx codex-context-map . --max-bytes 65536 --fallback TEAM_GUIDE.md --fallback .agents.md
60
+
61
+ # 显式包含全局 AGENTS 文件
62
+ npx codex-context-map . --global --html context-map.html
63
+
64
+ # 导出 JSON,发生截断时返回失败退出码
65
+ npx codex-context-map ./services/payments --json --check
66
+
67
+ # 使用虚构示例,无需扫描本机项目
68
+ npx codex-context-map --demo --html demo.html
69
+ ```
70
+
71
+ `--check` 对选定目录进行检查:未截断返回 **0**,发生截断返回 **1**,输入或读写错误返回 **2**。CI 可分别检查关键启动目录。HTML 默认不覆盖已有文件,需要覆盖时显式加 `--force`。完整参数见 `--help`。
72
+
73
+ 无法访问 npm 时,可以克隆仓库后直接运行 `node bin/codex-context-map.js --demo`,命令行不需要安装依赖。也可下载 Release 中的包,再运行 `npm install -g ./codex-context-map-0.1.0.tgz`。
74
+
75
+ ## 解析范围
76
+
77
+ 这是**单个可信项目的静态发现预览**,采用有版本依据的 [Codex 源码规则](docs/semantics.md),不读取正在运行的会话。
78
+
79
+ - 命令行检测最近的 `.git` 标记;嵌套仓库有自己的边界。没有标记时只检查启动目录。可用 `--root` 指定边界。
80
+ - 同目录依次选择 `AGENTS.override.md`、`AGENTS.md`、配置的备用文件名。更深目录的文件追加到加载链,不删除上级全文。
81
+ - 默认预算为 **32,768 个内容字节**;分隔符和全局指令单独统计。这里不估算 Token 或费用。
82
+ - **不会自动读取配置文件。** 请使 `--max-bytes`、`--fallback`、`--root` 与实际配置一致。全局指令需显式添加 `--global`。
83
+ - 不涵盖系统提示、技能、MCP、Hook、任务及账号指令、不可信项目、多环境或会话中途刷新,也不证明模型是否遵守了指令。
84
+
85
+ 当前源码中,空覆盖文件的行为与文档中的简述存在细节差异,工具明确展示这个情况。具体依据与限制见 [解析规则](docs/semantics.md)。
86
+
87
+ ## 隐私
88
+
89
+ CLI 只读取指定名称的指令文件和目录信息,不读取凭据、会话历史或源代码文件内容。全局指令仅在显式启用后读取。浏览器页面禁止网络连接,不上传导入文件;访问在线演示本身仍会向 GitHub Pages 发起正常页面请求。
90
+
91
+ **导出内容包含指令文本和相对路径,分享前请检查;工具不会自动脱敏。** CLI 跳过符号链接并提示,浏览器文件夹选择器不提供符号链接元数据。生成目录和依赖目录默认排除,必要时用 `--include-ignored`。完整列表见 [扫描限制](docs/semantics.md#scan-and-import-limits)。
92
+
93
+ ## 参与开发
94
+
95
+ ```bash
96
+ git clone https://github.com/Han-1413141/codex-context-map.git
97
+ cd codex-context-map
98
+ npm ci
99
+ npm run check
100
+ npx playwright install chromium
101
+ npm run test:browser
102
+ ```
103
+
104
+ 共享解析引擎在 `src/core.js`,文件系统扫描在 `src/scan.js`,界面在 `site/`。`npm run build` 生成独立演示页 `docs/index.html`,无需打包器。
105
+
106
+ 欢迎提交能复现的解析差异、测试或改进。参见 [贡献指南](CONTRIBUTING.md) 和 [路线图](docs/roadmap.md)。
107
+
108
+ MIT 协议。独立项目,与 OpenAI 无隶属关系,也未经 OpenAI 背书。Codex 是 OpenAI 的产品。
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ import { parseArgs } from "node:util";
3
+ import { writeFile, readFile } from "node:fs/promises";
4
+ import { resolve } from "node:path";
5
+ import { scanProject } from "../src/scan.js";
6
+ import { createDemo } from "../src/demo.js";
7
+ import {
8
+ resolveContext,
9
+ compareContexts,
10
+ validateBudget,
11
+ } from "../src/core.js";
12
+ import { renderReport } from "../src/report.js";
13
+
14
+ const help = `Codex Context Map — explain AGENTS.md discovery, offline.
15
+
16
+ Usage: codex-context-map [directory-or-file] [options]
17
+
18
+ --html <file> Write a self-contained interactive report
19
+ --json Print a portable snapshot and resolved context as JSON
20
+ --compare <directory> Compare another directory (relative to project root)
21
+ --max-bytes <number> Project content budget (default 32768, maximum 1048576)
22
+ --fallback <filename> Add a fallback filename; repeat to specify order
23
+ --root <directory> Explicit project boundary (otherwise nearest .git)
24
+ --global Also read AGENTS files from CODEX_HOME or ~/.codex
25
+ --codex-home <dir> Use this global directory (requires --global)
26
+ --include-ignored Traverse build/dependency folders too (.git is excluded)
27
+ --check Exit 1 if the selected chain is truncated or excluded
28
+ --force Allow overwriting the HTML output
29
+ --demo Use the bundled fictional workspace
30
+ --version Print version
31
+ --help Show this help
32
+
33
+ Examples:
34
+ npx codex-context-map . --html context-map.html
35
+ npx codex-context-map ./services/payments --compare apps/web
36
+ npx codex-context-map . --json --check
37
+
38
+ Uses an explicit static model, not a live Codex session. No network calls.
39
+ Config, skills, MCP, account/thread instructions and extra environments are not read.
40
+ Match --max-bytes, --fallback and --root to your Codex configuration.
41
+ Global instructions are opt-in. HTML/JSON exports contain instruction text.
42
+ `;
43
+
44
+ try {
45
+ const { values: v, positionals } = parseArgs({
46
+ allowPositionals: true,
47
+ options: {
48
+ html: { type: "string" },
49
+ json: { type: "boolean" },
50
+ compare: { type: "string" },
51
+ "max-bytes": { type: "string" },
52
+ fallback: { type: "string", multiple: true },
53
+ root: { type: "string" },
54
+ global: { type: "boolean" },
55
+ "codex-home": { type: "string" },
56
+ "include-ignored": { type: "boolean" },
57
+ check: { type: "boolean" },
58
+ force: { type: "boolean" },
59
+ demo: { type: "boolean" },
60
+ version: { type: "boolean" },
61
+ help: { type: "boolean", short: "h" },
62
+ },
63
+ });
64
+ if (v.help) {
65
+ console.log(help);
66
+ } else if (v.version) {
67
+ console.log(
68
+ JSON.parse(
69
+ await readFile(new URL("../package.json", import.meta.url), "utf8"),
70
+ ).version,
71
+ );
72
+ } else {
73
+ if (positionals.length > 1)
74
+ throw new Error("Provide one target directory or file.");
75
+ if (v["codex-home"] && !v.global)
76
+ throw new Error("--codex-home requires --global.");
77
+ if (v["max-bytes"] !== undefined && !/^\d+$/.test(v["max-bytes"]))
78
+ throw new Error("--max-bytes requires a nonnegative integer.");
79
+ const maxBytes =
80
+ v["max-bytes"] === undefined
81
+ ? undefined
82
+ : validateBudget(Number(v["max-bytes"]));
83
+ const snapshot = v.demo
84
+ ? createDemo()
85
+ : await scanProject(positionals[0] ?? ".", {
86
+ root: v.root,
87
+ maxBytes,
88
+ fallbackNames: v.fallback,
89
+ global: v.global,
90
+ codexHome: v["codex-home"],
91
+ includeIgnored: v["include-ignored"],
92
+ });
93
+ if (v.demo && positionals.length)
94
+ throw new Error("--demo does not accept a filesystem target.");
95
+ if (maxBytes !== undefined) snapshot.settings.maxBytes = maxBytes;
96
+ if (v.fallback) snapshot.settings.fallbackNames = v.fallback;
97
+ const result = resolveContext(snapshot);
98
+ const comparison = v.compare
99
+ ? compareContexts(result, resolveContext(snapshot, v.compare))
100
+ : undefined;
101
+ if (v.html) {
102
+ // Exclusive creation protects existing source and instruction files by default.
103
+ await writeFile(
104
+ resolve(v.html),
105
+ await renderReport(snapshot, { demo: !!v.demo }),
106
+ { encoding: "utf8", flag: v.force ? "w" : "wx" },
107
+ );
108
+ console.error(`Interactive report: ${resolve(v.html)}`);
109
+ }
110
+ if (v.json)
111
+ console.log(
112
+ JSON.stringify(
113
+ { ...snapshot, result, ...(comparison ? { comparison } : {}) },
114
+ null,
115
+ 2,
116
+ ),
117
+ );
118
+ else {
119
+ console.log(`\nCODEX CONTEXT MAP · ${snapshot.projectName}\n`);
120
+ console.log(
121
+ `Launch directory: ${result.target}\nProject content: ${result.usedBytes.toLocaleString("en-US")} / ${result.budget.toLocaleString("en-US")} bytes\n`,
122
+ );
123
+ for (const file of result.selected)
124
+ console.log(
125
+ ` ${file.status.padEnd(9)} ${file.scope === "global" ? "$CODEX_HOME/" : ""}${file.path} (${file.usedBytes}/${file.bytes} bytes)`,
126
+ );
127
+ if (!result.selected.length)
128
+ console.log(" No instruction files discovered.");
129
+ for (const f of result.records.filter((f) => f.status === "shadowed"))
130
+ console.log(` shadowed ${f.path} → ${f.shadowedBy}`);
131
+ if (comparison)
132
+ console.log(
133
+ `\nCompared with ${v.compare}:\n${JSON.stringify(comparison, null, 2)}`,
134
+ );
135
+ for (const warning of snapshot.warnings)
136
+ console.error(`Warning: ${warning}`);
137
+ console.log(
138
+ "\nStatic discovery preview. Use --help for model boundaries.",
139
+ );
140
+ }
141
+ if (v.check && result.hasCutoff) process.exitCode = 1;
142
+ }
143
+ } catch (error) {
144
+ console.error(
145
+ `codex-context-map: ${error.code === "EEXIST" ? "Output exists; choose a new filename or pass --force." : error.message}`,
146
+ );
147
+ process.exitCode = 2;
148
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "codex-context-map",
3
+ "version": "0.1.0",
4
+ "description": "See which AGENTS.md files Codex discovers, what overrides what, and where instructions get cut off. Offline CLI + interactive map.",
5
+ "type": "module",
6
+ "bin": {
7
+ "codex-context-map": "bin/codex-context-map.js"
8
+ },
9
+ "exports": {
10
+ ".": "./src/core.js",
11
+ "./scan": "./src/scan.js"
12
+ },
13
+ "files": [
14
+ "bin",
15
+ "src",
16
+ "site",
17
+ "README.md",
18
+ "README.zh-CN.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "test": "node --test test/*.test.js",
23
+ "build": "node scripts/build.js",
24
+ "test:browser": "playwright test",
25
+ "check": "npm test && npm run build",
26
+ "prepack": "npm run check"
27
+ },
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "license": "MIT",
32
+ "author": "Han-1413141",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/Han-1413141/codex-context-map.git"
36
+ },
37
+ "homepage": "https://han-1413141.github.io/codex-context-map/",
38
+ "bugs": "https://github.com/Han-1413141/codex-context-map/issues",
39
+ "keywords": [
40
+ "codex",
41
+ "agents-md",
42
+ "openai",
43
+ "developer-tools",
44
+ "context-engineering",
45
+ "cli",
46
+ "visualization",
47
+ "offline"
48
+ ],
49
+ "devDependencies": {
50
+ "@playwright/test": "1.63.0"
51
+ }
52
+ }