@namewta/speculo 2.0.5 → 2.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/README.md +3 -0
- package/THIRD-PARTY-NOTICES.md +4 -0
- package/dist/src/agent-skills.d.ts +5 -0
- package/dist/src/agent-skills.js +10 -7
- package/dist/src/agent-skills.js.map +1 -1
- package/dist/src/cli.js +17 -4
- package/dist/src/cli.js.map +1 -1
- package/dist/src/coordination.d.ts +3 -3
- package/dist/src/coordination.js +21 -4
- package/dist/src/coordination.js.map +1 -1
- package/dist/src/doctor.js +8 -1
- package/dist/src/doctor.js.map +1 -1
- package/dist/src/external-files.d.ts +4 -2
- package/dist/src/external-files.js +4 -4
- package/dist/src/external-files.js.map +1 -1
- package/dist/src/hub-catalog.d.ts +11 -0
- package/dist/src/hub-catalog.js +91 -0
- package/dist/src/hub-catalog.js.map +1 -0
- package/dist/src/hub-resources.json +1 -0
- package/dist/src/hub-skills.d.ts +53 -0
- package/dist/src/hub-skills.js +157 -0
- package/dist/src/hub-skills.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.js +48 -47
- package/dist/src/index.js.map +1 -1
- package/dist/src/install-ui.d.ts +16 -0
- package/dist/src/install-ui.js +67 -11
- package/dist/src/install-ui.js.map +1 -1
- package/dist/src/manifest.d.ts +2 -0
- package/dist/src/manifest.js +2 -0
- package/dist/src/manifest.js.map +1 -1
- package/dist/src/refresh.d.ts +1 -0
- package/dist/src/refresh.js +13 -10
- package/dist/src/refresh.js.map +1 -1
- package/dist/src/retained-workflows.d.ts +10 -0
- package/dist/src/retained-workflows.js +25 -0
- package/dist/src/retained-workflows.js.map +1 -0
- package/dist/src/runtime-entry.d.ts +1 -0
- package/dist/src/runtime-entry.js +1 -0
- package/dist/src/runtime-entry.js.map +1 -1
- package/dist/src/skill-trees.d.ts +27 -0
- package/dist/src/skill-trees.js +118 -0
- package/dist/src/skill-trees.js.map +1 -0
- package/dist/src/transaction.d.ts +3 -14
- package/dist/src/transaction.js +20 -36
- package/dist/src/transaction.js.map +1 -1
- package/dist/src/workflow-install.d.ts +15 -0
- package/dist/src/workflow-install.js +104 -0
- package/dist/src/workflow-install.js.map +1 -0
- package/package.json +4 -2
- package/skills-hub/automation/grok-bot-team-steward/CHEATSHEET.md +17 -0
- package/skills-hub/automation/grok-bot-team-steward/INSTALL.md +23 -0
- package/skills-hub/automation/grok-bot-team-steward/LICENSE +21 -0
- package/skills-hub/automation/grok-bot-team-steward/README.md +9 -0
- package/skills-hub/automation/grok-bot-team-steward/SKILL.md +52 -0
- package/skills-hub/automation/grok-bot-team-steward/agents/openai.yaml +4 -0
- package/skills-hub/automation/grok-bot-team-steward/references/00-hard-rules.md +50 -0
- package/skills-hub/automation/grok-bot-team-steward/references/01-snapshot-schema.md +84 -0
- package/skills-hub/automation/grok-bot-team-steward/references/02-export-protocol.md +57 -0
- package/skills-hub/automation/grok-bot-team-steward/references/03-restore-protocol.md +64 -0
- package/skills-hub/automation/grok-bot-team-steward/references/04-inventory.md +37 -0
- package/skills-hub/automation/grok-bot-team-steward/references/05-conversations.md +71 -0
- package/skills-hub/automation/grok-bot-team-steward/references/06-sanitizer.md +39 -0
- package/skills-hub/automation/grok-bot-team-steward/references/07-prompts.md +87 -0
- package/skills-hub/automation/grok-bot-team-steward/references/08-verification.md +30 -0
- package/skills-hub/automation/grok-bot-team-steward/references/09-sources.md +31 -0
- package/skills-hub/automation/grok-bot-team-steward/scripts/scrub.sh +17 -0
- package/skills-hub/automation/grok-bot-team-steward/scripts/snapshot-name.sh +18 -0
- package/skills-hub/automation/grok-bot-team-steward/scripts/validate-snapshot.sh +62 -0
- package/skills-hub/automation/grok-bot-team-steward/steward/ACTIVATE.md +58 -0
- package/skills-hub/automation/grok-bot-team-steward/steward/SETUP-INSTRUCTIONS.md +33 -0
- package/skills-hub/automation/grok-bot-team-steward/steward/STEWARD-PROFILE.md +28 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/CHANGELOG.md +3 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/CHARTER.md +27 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/DROP-LIST.md +10 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/GAPS.md +6 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/INIT.md +14 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/MANIFEST.md +30 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/MANIFEST.yaml +20 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/ORG.md +15 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/README.md +8 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/RESTORE.md +13 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/ROSTER.md +11 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/GAPS.md +7 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/MEMORY.md +9 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/PROFILE.md +27 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/agent-spec.md +9 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/conversations/INDEX.md +5 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/conversations/main.md +9 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/routines.md +5 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/bots/_SLUG/skills.md +5 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/connectors.md +7 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/meta/COMPLETED.md +6 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/meta/CREATED.md +6 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/meta/RESTORE-NOTES.md +13 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/meta/SANITIZER.md +7 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/meta/SOURCE.md +8 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/rooms/_ROOM.md +8 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/routines/_ROUTINE.md +12 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/shared/shared-memory.md +5 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/shared/workspace-map.md +5 -0
- package/skills-hub/automation/grok-bot-team-steward/templates/snapshot/skills/_SKILL/SKILL.md +18 -0
- package/skills-hub/automation/herdr/SKILL.md +246 -0
- package/skills-hub/automation/orca/SKILL.md +328 -0
- package/skills-hub/coding/gitea-repo/LICENSE +21 -0
- package/skills-hub/coding/gitea-repo/SKILL.md +50 -0
- package/skills-hub/coding/gitea-repo/agents/openai.yaml +4 -0
- package/skills-hub/coding/gitea-repo/references/auth-and-scopes.md +58 -0
- package/skills-hub/coding/gitea-repo/references/endpoint-map.md +80 -0
- package/skills-hub/coding/gitea-repo/references/pagination-and-errors.md +34 -0
- package/skills-hub/coding/gitea-repo/scripts/gitea_api.py +814 -0
- package/skills-hub/coding/github-repo-steward/LICENSE +21 -0
- package/skills-hub/coding/github-repo-steward/SKILL.md +48 -0
- package/skills-hub/coding/github-repo-steward/agents/openai.yaml +4 -0
- package/skills-hub/coding/github-repo-steward/references/00-auth-and-tokens.md +73 -0
- package/skills-hub/coding/github-repo-steward/references/01-inventory.md +55 -0
- package/skills-hub/coding/github-repo-steward/references/02-lifecycle.md +57 -0
- package/skills-hub/coding/github-repo-steward/references/03-stars.md +42 -0
- package/skills-hub/coding/github-repo-steward/references/04-hygiene.md +40 -0
- package/skills-hub/coding/github-repo-steward/references/05-sources.md +42 -0
- package/skills-hub/coding/github-repo-steward/scripts/inventory.sh +64 -0
- package/skills-hub/coding/vscode-fullstack/LICENSE +21 -0
- package/skills-hub/coding/vscode-fullstack/SKILL.md +47 -0
- package/skills-hub/coding/vscode-fullstack/agents/openai.yaml +4 -0
- package/skills-hub/coding/vscode-fullstack/references/extensions-and-settings.md +181 -0
- package/skills-hub/coding/vscode-fullstack/references/profiles-and-validation.md +62 -0
- package/skills-hub/coding/vscode-fullstack/references/runtime-reuse.md +52 -0
- package/skills-hub/design/photo-retouch/LICENSE +21 -0
- package/skills-hub/design/photo-retouch/SKILL.md +50 -0
- package/skills-hub/design/photo-retouch/agents/openai.yaml +4 -0
- package/skills-hub/design/photo-retouch/references/basic-retouch.md +58 -0
- package/skills-hub/design/photo-retouch/references/formal-portrait.md +57 -0
- package/skills-hub/design/photo-retouch/references/object-and-canvas.md +82 -0
- package/skills-hub/design/photo-retouch/references/product-photo.md +41 -0
- package/skills-hub/design/photo-retouch/references/repair-and-look.md +61 -0
- package/skills-hub/design/photo-retouch/references/social-effects.md +55 -0
- package/skills-hub/design/photo-retouch/references/travel-creative.md +79 -0
- package/skills-hub/system/clash-client-profile/LICENSE +21 -0
- package/skills-hub/system/clash-client-profile/SKILL.md +79 -0
- package/skills-hub/system/clash-client-profile/agents/openai.yaml +4 -0
- package/skills-hub/system/clash-client-profile/references/acceptance.md +81 -0
- package/skills-hub/system/clash-client-profile/references/browser-privacy.md +35 -0
- package/skills-hub/system/clash-client-profile/references/clash-verge.md +40 -0
- package/skills-hub/system/clash-client-profile/references/dns-workflow.md +147 -0
- package/skills-hub/system/clash-client-profile/references/flclash.md +24 -0
- package/skills-hub/system/clash-client-profile/references/network-performance.md +25 -0
- package/skills-hub/system/clash-client-profile/references/platform-dns.md +109 -0
- package/skills-hub/system/clash-client-profile/references/sources.md +46 -0
- package/skills-hub/system/clash-client-profile/references/troubleshooting.md +82 -0
- package/skills-hub/system/clash-client-profile/scripts/dns_guard.py +650 -0
- package/skills-hub/system/clash-client-profile/scripts/proxy_doctor.py +213 -0
- package/skills-hub/system/clash-client-profile/scripts/render_rules.py +34 -0
- package/skills-hub/system/clash-client-profile/templates/ai-rules.yaml +18 -0
- package/skills-hub/system/clash-client-profile/templates/dns-request.example.json +9 -0
- package/skills-hub/system/clash-client-profile/templates/dns.yaml +8 -0
- package/skills-hub/system/linux-dev-disk-cleanup/LICENSE +21 -0
- package/skills-hub/system/linux-dev-disk-cleanup/SKILL.md +42 -0
- package/skills-hub/system/linux-dev-disk-cleanup/agents/openai.yaml +4 -0
- package/skills-hub/system/linux-dev-disk-cleanup/references/linux-cleanup-workflow.md +145 -0
- package/skills-hub/system/optimize-codex-config/LICENSE +21 -0
- package/skills-hub/system/optimize-codex-config/SKILL.md +101 -0
- package/skills-hub/system/optimize-codex-config/agents/openai.yaml +4 -0
- package/skills-hub/system/optimize-codex-config/assets/capabilities.example.json +22 -0
- package/skills-hub/system/optimize-codex-config/references/cli.md +35 -0
- package/skills-hub/system/optimize-codex-config/references/configuration-contract.md +33 -0
- package/skills-hub/system/optimize-codex-config/references/optimization-method.md +38 -0
- package/skills-hub/system/optimize-codex-config/references/privacy.md +41 -0
- package/skills-hub/system/optimize-codex-config/references/sources.md +24 -0
- package/skills-hub/system/optimize-codex-config/references/statusline.md +31 -0
- package/skills-hub/system/optimize-codex-config/references/transactions.md +32 -0
- package/skills-hub/system/optimize-codex-config/references/troubleshooting.md +95 -0
- package/skills-hub/system/optimize-codex-config/scripts/adapters/claude.mjs +24 -0
- package/skills-hub/system/optimize-codex-config/scripts/adapters/codex.mjs +10 -0
- package/skills-hub/system/optimize-codex-config/scripts/ai-cli-config.mjs +67 -0
- package/skills-hub/system/optimize-codex-config/scripts/audit-codex-config.mjs +762 -0
- package/skills-hub/system/optimize-codex-config/scripts/lib/document.mjs +166 -0
- package/skills-hub/system/optimize-codex-config/scripts/lib/inspect.mjs +211 -0
- package/skills-hub/system/optimize-codex-config/scripts/lib/io.mjs +104 -0
- package/skills-hub/system/optimize-codex-config/scripts/lib/plan.mjs +79 -0
- package/skills-hub/system/optimize-codex-config/scripts/lib/transaction.mjs +205 -0
- package/skills-hub/system/optimize-codex-config/scripts/lib/writers.mjs +46 -0
- package/skills-hub/system/optimize-codex-config/scripts/statusline/claude-statusline.mjs +94 -0
- package/skills-hub/system/optimize-codex-config/scripts/vendor/THIRD-PARTY-NOTICES.txt +250 -0
- package/skills-hub/system/optimize-codex-config/scripts/vendor/build-package-lock.json +488 -0
- package/skills-hub/system/optimize-codex-config/scripts/vendor/manifest.json +14 -0
- package/skills-hub/system/optimize-codex-config/scripts/vendor/parsers.mjs +16 -0
- package/skills-hub/system/proxy-region-locale/LICENSE +21 -0
- package/skills-hub/system/proxy-region-locale/SKILL.md +42 -0
- package/skills-hub/system/proxy-region-locale/agents/openai.yaml +4 -0
- package/skills-hub/system/proxy-region-locale/references/linux.md +35 -0
- package/skills-hub/system/proxy-region-locale/references/macos.md +31 -0
- package/skills-hub/system/proxy-region-locale/references/windows.md +45 -0
- package/skills-hub/system/system-health-audit/LICENSE +21 -0
- package/skills-hub/system/system-health-audit/SKILL.md +41 -0
- package/skills-hub/system/system-health-audit/agents/openai.yaml +4 -0
- package/skills-hub/system/system-health-audit/references/platforms.md +37 -0
- package/skills-hub/system/system-health-audit/scripts/system_audit.py +41 -0
- package/skills-hub/system/windows-dev-disk-cleanup/LICENSE +21 -0
- package/skills-hub/system/windows-dev-disk-cleanup/SKILL.md +40 -0
- package/skills-hub/system/windows-dev-disk-cleanup/agents/openai.yaml +4 -0
- package/skills-hub/system/windows-dev-disk-cleanup/references/windows-cleanup-workflow.md +121 -0
- package/skills-hub/writing/.gitkeep +0 -0
- package/skills-hub/writing/job-application/LICENSE +21 -0
- package/skills-hub/writing/job-application/SKILL.md +160 -0
- package/skills-hub/writing/job-application/agents/openai.yaml +4 -0
- package/skills-hub/writing/job-application/assets/resume.css +10 -0
- package/skills-hub/writing/job-application/config.example.json +9 -0
- package/skills-hub/writing/job-application/references/company-research.md +7 -0
- package/skills-hub/writing/job-application/references/corpus-schema.md +33 -0
- package/skills-hub/writing/job-application/references/honesty-gate.md +29 -0
- package/skills-hub/writing/job-application/references/improvement-plan.md +15 -0
- package/skills-hub/writing/job-application/references/ingest-protocol.md +18 -0
- package/skills-hub/writing/job-application/references/interview-speech.md +16 -0
- package/skills-hub/writing/job-application/references/jd-parse.md +18 -0
- package/skills-hub/writing/job-application/references/persist-paths.md +34 -0
- package/skills-hub/writing/job-application/references/question-bank.md +19 -0
- package/skills-hub/writing/job-application/references/rendering.md +9 -0
- package/skills-hub/writing/job-application/references/resume-playbook.md +30 -0
- package/skills-hub/writing/job-application/scripts/README.md +12 -0
- package/skills-hub/writing/job-application/scripts/ingest_kb.py +188 -0
- package/skills-hub/writing/job-application/scripts/render_resume.py +144 -0
- package/skills-hub/writing/job-application/scripts/validate_claims.py +52 -0
- package/skills-hub/writing/job-application/scripts/write_config.py +72 -0
- package/skills-hub/writing/job-application/templates/application-index.md +10 -0
- package/skills-hub/writing/job-application/templates/brief.md +16 -0
- package/skills-hub/writing/job-application/templates/changelog.md +6 -0
- package/skills-hub/writing/job-application/templates/company-research.md +15 -0
- package/skills-hub/writing/job-application/templates/corpus.md +11 -0
- package/skills-hub/writing/job-application/templates/evidence-map.md +5 -0
- package/skills-hub/writing/job-application/templates/framings.md +6 -0
- package/skills-hub/writing/job-application/templates/improvement-plan.md +16 -0
- package/skills-hub/writing/job-application/templates/ingest-log.md +4 -0
- package/skills-hub/writing/job-application/templates/known-gaps.md +4 -0
- package/skills-hub/writing/job-application/templates/match-report.md +21 -0
- package/skills-hub/writing/job-application/templates/methodology-cache.md +10 -0
- package/skills-hub/writing/job-application/templates/persist-index.md +11 -0
- package/skills-hub/writing/job-application/templates/profile.md +21 -0
- package/skills-hub/writing/job-application/templates/questions.md +22 -0
- package/skills-hub/writing/job-application/templates/resume-original.md +10 -0
- package/skills-hub/writing/job-application/templates/resume-tailored.md +21 -0
- package/skills-hub/writing/job-application/templates/sources-index.md +6 -0
- package/skills-hub/writing/job-application/templates/speech.md +19 -0
- package/skills-hub/writing/job-application/templates/stories.md +9 -0
- package/skills-hub/writing/job-application/templates/story-bank.md +11 -0
- package/skills-hub/writing/job-application/templates/strengths.md +4 -0
- package/skills-hub/writing/job-application/templates/style-memory.md +7 -0
- package/skills-hub/writing/ste-zh/LICENSE +21 -0
- package/skills-hub/writing/ste-zh/NOTICE.md +9 -0
- package/skills-hub/writing/ste-zh/SKILL.md +130 -0
- package/skills-hub/writing/ste-zh/agents/openai.yaml +6 -0
- package/skills-hub/writing/ste-zh/examples/zh-report.md +23 -0
- package/skills-hub/writing/ste-zh/references/english-modes.md +13 -0
- package/skills-hub/writing/ste-zh/references/terminology.md +13 -0
- package/skills-hub/writing/ste-zh/references/zh-rules.md +29 -0
- package/template/.speculo/refresh-contract.json +2 -0
- package/template/canonical/canonical-specdev-goal-plan.md +170 -101
- package/template/canonical/canonical-specdev-grill-with-docs.md +346 -277
- package/template/canonical/canonical-specdev-spec.md +346 -277
- package/template/canonical/canonical-specdev-tickets.md +346 -277
- package/template/canonical/canonical-specdev-wayfinder.md +346 -277
- package/template/lib/speculo-runtime.mjs +183 -8
- package/template/references/coordination/coordination-contract.md +12 -4
- package/template/references/coordination/modes/cli.md +3 -3
- package/template/references/coordination/modes/herdr.md +11 -11
- package/template/references/coordination/modes/orca.md +14 -14
- package/template/references/coordination/project-facts.schema.json +1 -0
- package/template/references/coordination/report-template.md +18 -0
- package/template/references/coordination/result-and-recovery.md +3 -3
- package/template/references/coordination/session-files.md +49 -56
- package/template/references/coordination/task-brief.md +3 -3
- package/template/references/coordination/task-template.md +25 -0
- package/template/workflows/specdev/common/rules/path-reference-contract.md +1 -1
- package/template/workflows/specdev/common/rules/workflow-state-and-lifecycle.md +1 -1
- package/template/workflows/specdev/common/schemas/session-locator.schema.json +15 -0
- package/template/workflows/specdev/common/skills/code-review/references/review-evidence.md +1 -1
- package/template/workflows/specdev/common/tools/README.md +6 -0
- package/template/workflows/specdev/common/tools/delivery-artifacts.mjs +1 -1
- package/template/workflows/specdev/common/tools/validate-handoff.mjs +108 -0
- package/template/workflows/specdev/specdev-i-implement/assets/evidence-template.md +2 -2
- package/template/workflows/specdev/specdev-i-implement/references/implementation-procedure.md +1 -1
- package/template/workflows/specdev/specdev-i-init-setup/SKILL.md +7 -6
- package/template/workflows/specdev/specdev-i-init-setup/references/first-setup.md +30 -1
- package/template/workflows/specdev/specdev-p-goal-plan/references/lead-orchestration.md +1 -1
|
@@ -0,0 +1,762 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runtime: Node.js 22+. Read-only auditor.
|
|
3
|
+
// Exit 0: completed report or --help. Exit 2: usage or path error. Exit 1: unexpected audit failure.
|
|
4
|
+
// stdout is the report; stderr is the error line. Never reads auth.json contents or prints prompts, tool output, full URLs, or bearer tokens.
|
|
5
|
+
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { accessSync, constants, createReadStream } from "node:fs";
|
|
9
|
+
import { lstat, readFile, readdir } from "node:fs/promises";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { createInterface } from "node:readline";
|
|
12
|
+
import { delimiter, isAbsolute, join, relative, sep } from "node:path";
|
|
13
|
+
|
|
14
|
+
const MAX_SESSION_FILES = 200;
|
|
15
|
+
const MAX_SESSION_BYTES = 64 * 1024 * 1024;
|
|
16
|
+
const MAX_INCIDENTS = 100;
|
|
17
|
+
const COMMAND_TIMEOUT_MS = 20_000;
|
|
18
|
+
|
|
19
|
+
const SAFE_SETTINGS = new Set([
|
|
20
|
+
"model",
|
|
21
|
+
"model_provider",
|
|
22
|
+
"model_reasoning_effort",
|
|
23
|
+
"model_reasoning_summary",
|
|
24
|
+
"model_verbosity",
|
|
25
|
+
"plan_mode_reasoning_effort",
|
|
26
|
+
"model_auto_compact_token_limit",
|
|
27
|
+
"model_auto_compact_token_limit_scope",
|
|
28
|
+
"model_context_window",
|
|
29
|
+
"approval_policy",
|
|
30
|
+
"approvals_reviewer",
|
|
31
|
+
"sandbox_mode",
|
|
32
|
+
"default_permissions",
|
|
33
|
+
"cli_auth_credentials_store",
|
|
34
|
+
"agents.enabled",
|
|
35
|
+
"agents.max_concurrent_threads_per_session",
|
|
36
|
+
"agents.max_threads",
|
|
37
|
+
"agents.default_subagent_model",
|
|
38
|
+
"agents.default_subagent_reasoning_effort",
|
|
39
|
+
"sandbox_workspace_write.network_access",
|
|
40
|
+
"history.persistence",
|
|
41
|
+
"history.max_bytes",
|
|
42
|
+
"features.remote_compaction_v2",
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
class UsageError extends Error {}
|
|
46
|
+
|
|
47
|
+
function usage() {
|
|
48
|
+
return [
|
|
49
|
+
"Usage:",
|
|
50
|
+
" node audit-codex-config.mjs --codex-home <absolute-directory> [options]",
|
|
51
|
+
"",
|
|
52
|
+
"Options:",
|
|
53
|
+
" --codex-bin <absolute-path> Codex executable (default: resolve codex from PATH)",
|
|
54
|
+
" --since-days <number> Scan recent rollout files (default: 7, range: 1-365)",
|
|
55
|
+
" --command-probes Opt into local CLI/writer probes; review their side effects first",
|
|
56
|
+
" --no-command-probes Skip probes (the default; retained compatibility flag)",
|
|
57
|
+
" --json Emit the schema-v1 JSON report",
|
|
58
|
+
" -h, --help Show this help",
|
|
59
|
+
"",
|
|
60
|
+
"The audit is read-only. It never reads auth.json contents or emits rollout prompt/tool content.",
|
|
61
|
+
"",
|
|
62
|
+
].join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function parseArgs(argv) {
|
|
66
|
+
const options = {
|
|
67
|
+
codex_home: null,
|
|
68
|
+
codex_bin: "codex",
|
|
69
|
+
since_days: 7,
|
|
70
|
+
command_probes: false,
|
|
71
|
+
json: false,
|
|
72
|
+
help: false,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
76
|
+
const item = argv[index];
|
|
77
|
+
if (item === "--codex-home" || item === "--codex-bin" || item === "--since-days") {
|
|
78
|
+
const value = argv[index + 1];
|
|
79
|
+
if (!value || value.startsWith("--")) throw new UsageError(item + " requires a value");
|
|
80
|
+
const key = item.slice(2).replaceAll("-", "_");
|
|
81
|
+
options[key] = value;
|
|
82
|
+
index += 1;
|
|
83
|
+
} else if (item === "--command-probes") {
|
|
84
|
+
options.command_probes = true;
|
|
85
|
+
} else if (item === "--no-command-probes") {
|
|
86
|
+
options.command_probes = false;
|
|
87
|
+
} else if (item === "--json") {
|
|
88
|
+
options.json = true;
|
|
89
|
+
} else if (item === "--help" || item === "-h") {
|
|
90
|
+
options.help = true;
|
|
91
|
+
} else {
|
|
92
|
+
throw new UsageError("unknown argument: " + item);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (options.help) return options;
|
|
97
|
+
if (!options.codex_home) throw new UsageError("--codex-home is required");
|
|
98
|
+
if (!isAbsolute(options.codex_home)) throw new UsageError("--codex-home must be an absolute path");
|
|
99
|
+
if (options.codex_bin !== "codex" && !isAbsolute(options.codex_bin)) {
|
|
100
|
+
throw new UsageError("--codex-bin must be an absolute path");
|
|
101
|
+
}
|
|
102
|
+
const sinceDays = Number(options.since_days);
|
|
103
|
+
if (!Number.isInteger(sinceDays) || sinceDays < 1 || sinceDays > 365) {
|
|
104
|
+
throw new UsageError("--since-days must be an integer from 1 to 365");
|
|
105
|
+
}
|
|
106
|
+
options.since_days = sinceDays;
|
|
107
|
+
return options;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function fileMetadata(path) {
|
|
111
|
+
try {
|
|
112
|
+
const stat = await lstat(path);
|
|
113
|
+
let type = "other";
|
|
114
|
+
if (stat.isSymbolicLink()) type = "symlink";
|
|
115
|
+
else if (stat.isFile()) type = "file";
|
|
116
|
+
else if (stat.isDirectory()) type = "directory";
|
|
117
|
+
return {
|
|
118
|
+
exists: true,
|
|
119
|
+
type,
|
|
120
|
+
...(stat.isFile() ? { bytes: stat.size } : {}),
|
|
121
|
+
mode: "0" + (stat.mode & 0o777).toString(8).padStart(3, "0"),
|
|
122
|
+
mtime: stat.mtime.toISOString(),
|
|
123
|
+
};
|
|
124
|
+
} catch (error) {
|
|
125
|
+
if (error?.code === "ENOENT") return { exists: false };
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async function hashFile(path) {
|
|
131
|
+
return createHash("sha256").update(await readFile(path)).digest("hex");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function parsePrimitive(raw) {
|
|
135
|
+
const value = raw.trim();
|
|
136
|
+
const doubleQuoted = value.match(/^("(?:[^"\\]|\\.)*")\s*(?:#.*)?$/);
|
|
137
|
+
if (doubleQuoted) {
|
|
138
|
+
try {
|
|
139
|
+
return JSON.parse(doubleQuoted[1]);
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const singleQuoted = value.match(/^'([^']*)'\s*(?:#.*)?$/);
|
|
145
|
+
if (singleQuoted) return singleQuoted[1];
|
|
146
|
+
const boolean = value.match(/^(true|false)\s*(?:#.*)?$/);
|
|
147
|
+
if (boolean) return boolean[1] === "true";
|
|
148
|
+
const number = value.match(/^(-?\d+)\s*(?:#.*)?$/);
|
|
149
|
+
if (number) return Number(number[1]);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function redactConfigPath(path) {
|
|
154
|
+
const parts = path.split(".");
|
|
155
|
+
const dynamicParents = new Set(["model_providers", "mcp_servers", "profiles", "plugins", "skills"]);
|
|
156
|
+
if (dynamicParents.has(parts[0]) && parts.length > 1) parts[1] = "<id>";
|
|
157
|
+
if (parts[0] === "agents" && parts.length > 2) parts[1] = "<role>";
|
|
158
|
+
return parts.join(".");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function endpointScheme(value) {
|
|
162
|
+
if (typeof value !== "string") return "unknown";
|
|
163
|
+
const match = value.match(/^([a-z][a-z0-9+.-]*):\/\//i);
|
|
164
|
+
return match ? match[1].toLowerCase() : "unknown";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function scanConfig(text) {
|
|
168
|
+
const safeSettings = {};
|
|
169
|
+
const declaredSections = new Set();
|
|
170
|
+
const declaredKeys = new Set();
|
|
171
|
+
const providers = new Map();
|
|
172
|
+
let table = "";
|
|
173
|
+
let containsInlineSecretMaterial = false;
|
|
174
|
+
|
|
175
|
+
for (const line of text.split(/\r?\n/)) {
|
|
176
|
+
const tableMatch = line.match(/^\s*\[\[?\s*([A-Za-z0-9_.-]+)\s*\]\]?\s*(?:#.*)?$/);
|
|
177
|
+
if (tableMatch) {
|
|
178
|
+
table = tableMatch[1];
|
|
179
|
+
declaredSections.add(redactConfigPath(table));
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
const keyMatch = line.match(/^\s*([A-Za-z0-9_.-]+)\s*=\s*(.*)$/);
|
|
183
|
+
if (!keyMatch) continue;
|
|
184
|
+
const localKey = keyMatch[1];
|
|
185
|
+
const fullKey = table ? table + "." + localKey : localKey;
|
|
186
|
+
const redactedKey = redactConfigPath(fullKey);
|
|
187
|
+
const value = parsePrimitive(keyMatch[2]);
|
|
188
|
+
declaredKeys.add(redactedKey);
|
|
189
|
+
|
|
190
|
+
const lowerKey = fullKey.toLowerCase();
|
|
191
|
+
if (
|
|
192
|
+
lowerKey.includes("experimental_bearer_token") ||
|
|
193
|
+
lowerKey.includes("authorization") ||
|
|
194
|
+
lowerKey.includes("api_key") ||
|
|
195
|
+
lowerKey.includes("password") ||
|
|
196
|
+
lowerKey.includes("secret") ||
|
|
197
|
+
(lowerKey.includes("http_headers") && /bearer|basic|token/i.test(keyMatch[2]))
|
|
198
|
+
) {
|
|
199
|
+
containsInlineSecretMaterial = true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (SAFE_SETTINGS.has(fullKey) && value !== null) safeSettings[fullKey] = value;
|
|
203
|
+
|
|
204
|
+
const providerMatch = fullKey.match(/^model_providers\.([A-Za-z0-9_-]+)\.(.+)$/);
|
|
205
|
+
if (!providerMatch) continue;
|
|
206
|
+
const providerId = providerMatch[1];
|
|
207
|
+
const providerKey = providerMatch[2];
|
|
208
|
+
if (!providers.has(providerId)) providers.set(providerId, {});
|
|
209
|
+
const provider = providers.get(providerId);
|
|
210
|
+
if (providerKey === "base_url") provider.base_url_scheme = endpointScheme(value);
|
|
211
|
+
else if (providerKey === "wire_api" && typeof value === "string") provider.wire_api = value;
|
|
212
|
+
else if (providerKey === "requires_openai_auth" && typeof value === "boolean") provider.requires_openai_auth = value;
|
|
213
|
+
else if (providerKey === "env_key") provider.has_env_key = true;
|
|
214
|
+
else if (providerKey === "experimental_bearer_token") provider.has_inline_bearer_token = true;
|
|
215
|
+
else if (providerKey === "auth.command") provider.has_auth_command = true;
|
|
216
|
+
else if (providerKey === "request_max_retries" && typeof value === "number") provider.request_max_retries = value;
|
|
217
|
+
else if (providerKey === "stream_max_retries" && typeof value === "number") provider.stream_max_retries = value;
|
|
218
|
+
else if (providerKey === "stream_idle_timeout_ms" && typeof value === "number") provider.stream_idle_timeout_ms = value;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (typeof safeSettings.model_provider === "string" && providers.has(safeSettings.model_provider)) {
|
|
222
|
+
safeSettings.model_provider = "<custom-provider>";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
line_count: text.split(/\r?\n/).length,
|
|
227
|
+
declared_sections: [...declaredSections].sort(),
|
|
228
|
+
declared_keys: [...declaredKeys].sort(),
|
|
229
|
+
safe_settings: safeSettings,
|
|
230
|
+
custom_providers: [...providers.values()].map((provider, index) => ({
|
|
231
|
+
id: "provider-" + (index + 1),
|
|
232
|
+
...provider,
|
|
233
|
+
})),
|
|
234
|
+
contains_inline_secret_material: containsInlineSecretMaterial,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function redactString(value) {
|
|
239
|
+
let output = value;
|
|
240
|
+
output = output.replace(/https?:\/\/[^\s"'<>),]+/gi, (url) => {
|
|
241
|
+
const scheme = url.slice(0, url.indexOf(":"));
|
|
242
|
+
return "<redacted-url:" + scheme.toLowerCase() + ">";
|
|
243
|
+
});
|
|
244
|
+
output = output.replace(/\bsk-[A-Za-z0-9_-]{6,}\b/g, "<redacted-secret>");
|
|
245
|
+
output = output.replace(
|
|
246
|
+
/(authorization|api[_-]?key|bearer|password|secret)\s*[:=]\s*[^\s,;]+/gi,
|
|
247
|
+
"$1=<redacted>",
|
|
248
|
+
);
|
|
249
|
+
if (/^(?:\/|[A-Za-z]:[\\/])/.test(output)) return "<absolute-path>";
|
|
250
|
+
return output.length > 1_000 ? output.slice(0, 1_000) + "<truncated>" : output;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function sanitizeValue(value, key = "", depth = 0) {
|
|
254
|
+
if (depth > 12) return "<depth-limit>";
|
|
255
|
+
if (value === null || typeof value === "number" || typeof value === "boolean") return value;
|
|
256
|
+
if (typeof value === "string") {
|
|
257
|
+
if (/(password|secret|bearer|api[_-]?key|authorization|credential|headers?)/i.test(key)) {
|
|
258
|
+
return "<redacted>";
|
|
259
|
+
}
|
|
260
|
+
return redactString(value);
|
|
261
|
+
}
|
|
262
|
+
if (Array.isArray(value)) return value.slice(0, 200).map((item) => sanitizeValue(item, key, depth + 1));
|
|
263
|
+
if (typeof value === "object") {
|
|
264
|
+
const result = {};
|
|
265
|
+
for (const [childKey, childValue] of Object.entries(value).slice(0, 300)) {
|
|
266
|
+
result[childKey] = sanitizeValue(childValue, childKey, depth + 1);
|
|
267
|
+
}
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
return String(value);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function runCommand(command, args, codexHome) {
|
|
274
|
+
const result = spawnSync(command, args, {
|
|
275
|
+
encoding: "utf8",
|
|
276
|
+
timeout: COMMAND_TIMEOUT_MS,
|
|
277
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
278
|
+
env: { ...process.env, CODEX_HOME: codexHome, NO_COLOR: "1" },
|
|
279
|
+
});
|
|
280
|
+
return {
|
|
281
|
+
status: result.status,
|
|
282
|
+
stdout: result.stdout ?? "",
|
|
283
|
+
error_code: result.error?.code ?? null,
|
|
284
|
+
timed_out: result.error?.code === "ETIMEDOUT",
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function resolveExecutable(command) {
|
|
289
|
+
if (isAbsolute(command)) return command;
|
|
290
|
+
const extensions = process.platform === "win32"
|
|
291
|
+
? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";")
|
|
292
|
+
: [""];
|
|
293
|
+
const directories = [
|
|
294
|
+
...(process.env.PATH ?? "").split(delimiter).filter(Boolean),
|
|
295
|
+
join(homedir(), ".volta", "bin"),
|
|
296
|
+
join(homedir(), ".local", "bin"),
|
|
297
|
+
"/opt/homebrew/bin",
|
|
298
|
+
"/usr/local/bin",
|
|
299
|
+
];
|
|
300
|
+
for (const directory of [...new Set(directories)]) {
|
|
301
|
+
for (const extension of extensions) {
|
|
302
|
+
const candidate = join(directory, command + extension.toLowerCase());
|
|
303
|
+
try {
|
|
304
|
+
accessSync(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
305
|
+
return candidate;
|
|
306
|
+
} catch {
|
|
307
|
+
// Try the next deterministic candidate.
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return command;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function parseFeatures(text) {
|
|
315
|
+
const features = [];
|
|
316
|
+
for (const line of text.split(/\r?\n/)) {
|
|
317
|
+
const match = line.trim().match(/^(\S+)\s+(.+?)\s+(true|false)$/);
|
|
318
|
+
if (!match) continue;
|
|
319
|
+
features.push({ name: match[1], maturity: match[2].trim(), enabled: match[3] === "true" });
|
|
320
|
+
}
|
|
321
|
+
return features;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
function collectModels(value, output = [], seen = new Set()) {
|
|
325
|
+
if (output.length >= 100 || value === null || typeof value !== "object") return output;
|
|
326
|
+
if (Array.isArray(value)) {
|
|
327
|
+
for (const item of value) collectModels(item, output, seen);
|
|
328
|
+
return output;
|
|
329
|
+
}
|
|
330
|
+
const slug = typeof value.slug === "string" ? value.slug : typeof value.model === "string" ? value.model : null;
|
|
331
|
+
if (slug && !seen.has(slug)) {
|
|
332
|
+
seen.add(slug);
|
|
333
|
+
const levels = Array.isArray(value.supported_reasoning_levels)
|
|
334
|
+
? value.supported_reasoning_levels
|
|
335
|
+
.map((item) => typeof item === "string" ? item : item?.effort ?? item?.reasoning_effort)
|
|
336
|
+
.filter((item) => typeof item === "string")
|
|
337
|
+
: [];
|
|
338
|
+
output.push({
|
|
339
|
+
slug,
|
|
340
|
+
...(Number.isFinite(value.context_window) ? { context_window: value.context_window } : {}),
|
|
341
|
+
...(Number.isFinite(value.max_context_window) ? { max_context_window: value.max_context_window } : {}),
|
|
342
|
+
...(Number.isFinite(value.effective_context_window_percent)
|
|
343
|
+
? { effective_context_window_percent: value.effective_context_window_percent }
|
|
344
|
+
: {}),
|
|
345
|
+
...(levels.length ? { reasoning_efforts: levels } : {}),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
for (const child of Object.values(value)) collectModels(child, output, seen);
|
|
349
|
+
return output;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function commandProbes(codexBin, codexHome) {
|
|
353
|
+
const executable = resolveExecutable(codexBin);
|
|
354
|
+
const versionRun = runCommand(executable, ["--version"], codexHome);
|
|
355
|
+
const doctorRun = runCommand(executable, ["doctor", "--json"], codexHome);
|
|
356
|
+
const featuresRun = runCommand(executable, ["features", "list"], codexHome);
|
|
357
|
+
const modelsRun = runCommand(executable, ["debug", "models", "--bundled"], codexHome);
|
|
358
|
+
|
|
359
|
+
let doctor = null;
|
|
360
|
+
let doctorParsed = false;
|
|
361
|
+
if (doctorRun.stdout.trim()) {
|
|
362
|
+
try {
|
|
363
|
+
doctor = sanitizeValue(JSON.parse(doctorRun.stdout));
|
|
364
|
+
doctorParsed = true;
|
|
365
|
+
} catch {
|
|
366
|
+
doctor = null;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
let models = [];
|
|
371
|
+
let modelsParsed = false;
|
|
372
|
+
if (modelsRun.stdout.trim()) {
|
|
373
|
+
try {
|
|
374
|
+
models = collectModels(JSON.parse(modelsRun.stdout));
|
|
375
|
+
modelsParsed = true;
|
|
376
|
+
} catch {
|
|
377
|
+
models = [];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return {
|
|
382
|
+
version: {
|
|
383
|
+
status: versionRun.status,
|
|
384
|
+
available: versionRun.error_code !== "ENOENT",
|
|
385
|
+
value: versionRun.status === 0 ? redactString(versionRun.stdout.trim()) : null,
|
|
386
|
+
},
|
|
387
|
+
doctor: {
|
|
388
|
+
status: doctorRun.status,
|
|
389
|
+
parsed: doctorParsed,
|
|
390
|
+
report: doctor,
|
|
391
|
+
timed_out: doctorRun.timed_out,
|
|
392
|
+
},
|
|
393
|
+
features: {
|
|
394
|
+
status: featuresRun.status,
|
|
395
|
+
entries: featuresRun.status === 0 ? parseFeatures(featuresRun.stdout) : [],
|
|
396
|
+
timed_out: featuresRun.timed_out,
|
|
397
|
+
},
|
|
398
|
+
models: {
|
|
399
|
+
status: modelsRun.status,
|
|
400
|
+
parsed: modelsParsed,
|
|
401
|
+
entries: models,
|
|
402
|
+
timed_out: modelsRun.timed_out,
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function parseWritableLsofHandles(text) {
|
|
408
|
+
const writers = new Set();
|
|
409
|
+
let pid = null;
|
|
410
|
+
for (const line of text.split(/\r?\n/)) {
|
|
411
|
+
const field = line[0];
|
|
412
|
+
const value = line.slice(1);
|
|
413
|
+
if (field === "p") {
|
|
414
|
+
pid = /^\d+$/.test(value) ? Number(value) : null;
|
|
415
|
+
} else if (field === "a" && pid !== null && (value === "w" || value === "u")) {
|
|
416
|
+
writers.add(pid);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return [...writers].sort((left, right) => left - right);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function activeConfigWriters(configPath) {
|
|
423
|
+
if (process.platform === "win32") {
|
|
424
|
+
return { available: false, detected: false, count: 0, probe: "unsupported" };
|
|
425
|
+
}
|
|
426
|
+
const run = spawnSync("lsof", ["-F", "pca", "--", configPath], {
|
|
427
|
+
encoding: "utf8",
|
|
428
|
+
timeout: 5_000,
|
|
429
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
430
|
+
});
|
|
431
|
+
if (run.error?.code === "ENOENT") {
|
|
432
|
+
return { available: false, detected: false, count: 0, probe: "lsof-unavailable" };
|
|
433
|
+
}
|
|
434
|
+
if (run.status !== 0 && !(run.status === 1 && !(run.stderr ?? "").trim())) {
|
|
435
|
+
return { available: false, detected: false, count: 0, probe: "lsof-failed" };
|
|
436
|
+
}
|
|
437
|
+
const pids = parseWritableLsofHandles(run.stdout ?? "");
|
|
438
|
+
return {
|
|
439
|
+
available: true,
|
|
440
|
+
detected: pids.length > 0,
|
|
441
|
+
count: pids.length,
|
|
442
|
+
probe: "config-writable-handle",
|
|
443
|
+
pids,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
async function collectSessionFiles(root, cutoff, output = []) {
|
|
448
|
+
let entries;
|
|
449
|
+
try {
|
|
450
|
+
if (!(await lstat(root)).isDirectory()) return output;
|
|
451
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
452
|
+
} catch (error) {
|
|
453
|
+
if (error?.code === "ENOENT") return output;
|
|
454
|
+
throw error;
|
|
455
|
+
}
|
|
456
|
+
for (const entry of entries) {
|
|
457
|
+
if (entry.isSymbolicLink()) continue;
|
|
458
|
+
const path = join(root, entry.name);
|
|
459
|
+
if (entry.isDirectory()) {
|
|
460
|
+
await collectSessionFiles(path, cutoff, output);
|
|
461
|
+
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
462
|
+
const stat = await lstat(path);
|
|
463
|
+
if (stat.mtimeMs >= cutoff) output.push({ path, bytes: stat.size, mtime_ms: stat.mtimeMs });
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return output;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function finiteNumber(value) {
|
|
470
|
+
return Number.isFinite(value) ? value : null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function classifyError(message) {
|
|
474
|
+
if (typeof message !== "string") return null;
|
|
475
|
+
const statusMatch = message.match(/(?:status|HTTP(?: status)?)\s*[:=]?\s*(401|403|404|413|429)\b/i)
|
|
476
|
+
?? message.match(/\b(401|403|404|413|429)\s+(?:Unauthorized|Forbidden|Not Found|Payload Too Large|Request Entity Too Large|Too Many Requests)\b/i);
|
|
477
|
+
const status = statusMatch ? Number(statusMatch[1]) : null;
|
|
478
|
+
const remoteCompaction = /remote compact|compaction/i.test(message);
|
|
479
|
+
const proxySignatures = [
|
|
480
|
+
["nginx", /\bnginx(?:\/|\b)/i],
|
|
481
|
+
["envoy", /\benvoy(?:\/|\b)/i],
|
|
482
|
+
["haproxy", /\bhaproxy(?:\/|\b)/i],
|
|
483
|
+
["cloudflare", /\bcloudflare(?:\/|\b)/i],
|
|
484
|
+
["varnish", /\bvarnish(?:\/|\b)/i],
|
|
485
|
+
];
|
|
486
|
+
const proxy_signature = proxySignatures.find(([, pattern]) => pattern.test(message))?.[0] ?? null;
|
|
487
|
+
const schemeMatch = message.match(/\b(https?):\/\//i);
|
|
488
|
+
const endpoint_scheme = schemeMatch ? schemeMatch[1].toLowerCase() : "unknown";
|
|
489
|
+
|
|
490
|
+
let category = null;
|
|
491
|
+
let scope = null;
|
|
492
|
+
if (status === 413) {
|
|
493
|
+
category = proxy_signature ? "external_proxy_body_limit" : "request_body_limit_unattributed";
|
|
494
|
+
scope = proxy_signature ? "external_proxy" : "provider_or_proxy";
|
|
495
|
+
} else if (status === 401) {
|
|
496
|
+
category = "authentication_rejected";
|
|
497
|
+
scope = "authentication";
|
|
498
|
+
} else if (status === 403) {
|
|
499
|
+
category = "authorization_rejected";
|
|
500
|
+
scope = "authentication_or_policy";
|
|
501
|
+
} else if (status === 404) {
|
|
502
|
+
category = "endpoint_or_wire_mismatch";
|
|
503
|
+
scope = "provider_contract";
|
|
504
|
+
} else if (status === 429) {
|
|
505
|
+
category = "provider_rate_limited";
|
|
506
|
+
scope = "upstream_service";
|
|
507
|
+
} else if (/SSE|event-stream|stream (?:closed|disconnect|interruption)/i.test(message)) {
|
|
508
|
+
category = "stream_interruption";
|
|
509
|
+
scope = "provider_or_proxy";
|
|
510
|
+
} else if (/timed? out|timeout/i.test(message)) {
|
|
511
|
+
category = "provider_timeout";
|
|
512
|
+
scope = "provider_or_proxy";
|
|
513
|
+
} else if (remoteCompaction) {
|
|
514
|
+
category = "remote_compaction_failed";
|
|
515
|
+
scope = "provider_or_proxy";
|
|
516
|
+
}
|
|
517
|
+
if (!category) return null;
|
|
518
|
+
|
|
519
|
+
return {
|
|
520
|
+
category,
|
|
521
|
+
scope,
|
|
522
|
+
status,
|
|
523
|
+
operation: remoteCompaction ? "remote_compaction" : "responses_request",
|
|
524
|
+
proxy_signature,
|
|
525
|
+
endpoint_scheme,
|
|
526
|
+
evidence: [
|
|
527
|
+
...(status ? ["http_status_" + status] : []),
|
|
528
|
+
...(remoteCompaction ? ["remote_compaction"] : []),
|
|
529
|
+
...(proxy_signature ? ["proxy_generated_response"] : []),
|
|
530
|
+
],
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
async function scanSessionFile(file, codexHome, incidents, counters) {
|
|
535
|
+
let lastTokenUsage = null;
|
|
536
|
+
if (file.bytes === 0) return;
|
|
537
|
+
const input = createReadStream(file.path, { encoding: "utf8", start: 0, end: Math.min(file.bytes, MAX_SESSION_BYTES) - 1 });
|
|
538
|
+
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
539
|
+
for await (const line of lines) {
|
|
540
|
+
counters.lines_scanned += 1;
|
|
541
|
+
let event;
|
|
542
|
+
try {
|
|
543
|
+
event = JSON.parse(line);
|
|
544
|
+
} catch {
|
|
545
|
+
counters.invalid_json_lines += 1;
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (event?.type !== "event_msg") continue;
|
|
549
|
+
if (event?.payload?.type === "token_count") {
|
|
550
|
+
lastTokenUsage = {
|
|
551
|
+
input_tokens: finiteNumber(event.payload?.info?.last_token_usage?.input_tokens),
|
|
552
|
+
cached_input_tokens: finiteNumber(event.payload?.info?.last_token_usage?.cached_input_tokens),
|
|
553
|
+
output_tokens: finiteNumber(event.payload?.info?.last_token_usage?.output_tokens),
|
|
554
|
+
total_tokens: finiteNumber(event.payload?.info?.last_token_usage?.total_tokens),
|
|
555
|
+
model_context_window: finiteNumber(event.payload?.info?.model_context_window),
|
|
556
|
+
};
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
const classified = classifyError(event?.payload?.error?.message);
|
|
560
|
+
if (!classified) continue;
|
|
561
|
+
if (incidents.length >= MAX_INCIDENTS) {
|
|
562
|
+
counters.incidents_truncated = true;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
incidents.push({
|
|
566
|
+
timestamp: typeof event.timestamp === "string" ? event.timestamp : null,
|
|
567
|
+
source: relative(codexHome, file.path).split(sep).join("/"),
|
|
568
|
+
...classified,
|
|
569
|
+
token_state: lastTokenUsage,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
async function scanSessions(codexHome, sinceDays) {
|
|
575
|
+
const cutoff = Date.now() - sinceDays * 24 * 60 * 60 * 1_000;
|
|
576
|
+
const allFiles = await collectSessionFiles(join(codexHome, "sessions"), cutoff);
|
|
577
|
+
allFiles.sort((left, right) => right.mtime_ms - left.mtime_ms);
|
|
578
|
+
const selected = allFiles.slice(0, MAX_SESSION_FILES);
|
|
579
|
+
const incidents = [];
|
|
580
|
+
const counters = {
|
|
581
|
+
files_found: allFiles.length,
|
|
582
|
+
files_scanned: 0,
|
|
583
|
+
files_skipped_oversize: 0,
|
|
584
|
+
bytes_selected: 0,
|
|
585
|
+
files_skipped_budget: 0,
|
|
586
|
+
files_truncated: allFiles.length > MAX_SESSION_FILES,
|
|
587
|
+
lines_scanned: 0,
|
|
588
|
+
invalid_json_lines: 0,
|
|
589
|
+
incidents_truncated: false,
|
|
590
|
+
};
|
|
591
|
+
for (const file of selected) {
|
|
592
|
+
if (file.bytes > MAX_SESSION_BYTES) {
|
|
593
|
+
counters.files_skipped_oversize += 1;
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
if (counters.bytes_selected + file.bytes > MAX_SESSION_BYTES) {
|
|
597
|
+
counters.files_skipped_budget += 1;
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
counters.bytes_selected += file.bytes;
|
|
601
|
+
try {
|
|
602
|
+
await scanSessionFile(file, codexHome, incidents, counters);
|
|
603
|
+
counters.files_scanned += 1;
|
|
604
|
+
} catch {
|
|
605
|
+
counters.invalid_json_lines += 1;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
incidents.sort((left, right) => String(right.timestamp).localeCompare(String(left.timestamp)));
|
|
609
|
+
return { since_days: sinceDays, ...counters, incidents };
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function sameFingerprint(left, right, leftHash, rightHash) {
|
|
613
|
+
return left.exists === right.exists
|
|
614
|
+
&& left.type === right.type
|
|
615
|
+
&& left.bytes === right.bytes
|
|
616
|
+
&& left.mtime === right.mtime
|
|
617
|
+
&& leftHash === rightHash;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function buildFindings(report) {
|
|
621
|
+
const findings = [];
|
|
622
|
+
const add = (code, severity, scope) => {
|
|
623
|
+
if (!findings.some((item) => item.code === code)) findings.push({ code, severity, scope });
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
if (!report.files.config.exists) add("config_missing", "warning", "local_config");
|
|
627
|
+
if (report.files.config.type === "symlink") add("config_is_symlink", "error", "local_config");
|
|
628
|
+
if (report.files.auth.type === "symlink") add("auth_is_symlink", "error", "authentication");
|
|
629
|
+
if (process.platform !== "win32" && report.files.auth.exists && report.files.auth.mode !== "0600") {
|
|
630
|
+
add("auth_permissions_not_0600", "error", "authentication");
|
|
631
|
+
}
|
|
632
|
+
if (report.config?.contains_inline_secret_material) add("config_contains_inline_secret_material", "error", "local_config");
|
|
633
|
+
if (report.config?.custom_providers.some((provider) => provider.base_url_scheme === "http")) {
|
|
634
|
+
add("provider_transport_is_plain_http", "warning", "provider_contract");
|
|
635
|
+
}
|
|
636
|
+
if (report.runtime.config_drift_detected) add("config_changed_during_audit", "error", "local_config");
|
|
637
|
+
if (report.runtime.active_writers?.detected) add("active_codex_writer_detected", "warning", "local_config");
|
|
638
|
+
for (const incident of report.sessions.incidents) {
|
|
639
|
+
const severity = incident.status && incident.status >= 400 ? "error" : "warning";
|
|
640
|
+
add(incident.category, severity, incident.scope);
|
|
641
|
+
}
|
|
642
|
+
if (report.commands.enabled) {
|
|
643
|
+
for (const key of ["version", "doctor", "features", "models"]) {
|
|
644
|
+
if (report.commands[key].status !== 0) add("codex_" + key + "_probe_failed", "warning", "local_runtime");
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return findings;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
function humanReport(report) {
|
|
651
|
+
const counts = report.findings.reduce((result, finding) => {
|
|
652
|
+
result[finding.severity] = (result[finding.severity] ?? 0) + 1;
|
|
653
|
+
return result;
|
|
654
|
+
}, {});
|
|
655
|
+
const lines = [
|
|
656
|
+
"Codex configuration audit",
|
|
657
|
+
"config.toml: " + (report.files.config.exists ? report.files.config.type : "missing"),
|
|
658
|
+
"auth.json: " + (report.files.auth.exists ? report.files.auth.type + " mode=" + report.files.auth.mode : "missing"),
|
|
659
|
+
"rollout incidents: " + report.sessions.incidents.length,
|
|
660
|
+
"findings: " + (counts.error ?? 0) + " error, " + (counts.warning ?? 0) + " warning",
|
|
661
|
+
];
|
|
662
|
+
for (const finding of report.findings) lines.push("[" + finding.severity + "] " + finding.code + " (" + finding.scope + ")");
|
|
663
|
+
return lines.join("\n") + "\n";
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
async function audit(options) {
|
|
667
|
+
const homeMetadata = await fileMetadata(options.codex_home);
|
|
668
|
+
if (!homeMetadata.exists) throw new UsageError("--codex-home does not exist");
|
|
669
|
+
if (homeMetadata.type !== "directory") throw new UsageError("--codex-home must name a directory, not " + homeMetadata.type);
|
|
670
|
+
|
|
671
|
+
const configPath = join(options.codex_home, "config.toml");
|
|
672
|
+
const authPath = join(options.codex_home, "auth.json");
|
|
673
|
+
const configBefore = await fileMetadata(configPath);
|
|
674
|
+
const auth = await fileMetadata(authPath);
|
|
675
|
+
let config = null;
|
|
676
|
+
let configHashBefore = null;
|
|
677
|
+
let configReadError = false;
|
|
678
|
+
if (configBefore.type === "file") {
|
|
679
|
+
try {
|
|
680
|
+
const text = await readFile(configPath, "utf8");
|
|
681
|
+
config = scanConfig(text);
|
|
682
|
+
configHashBefore = createHash("sha256").update(text).digest("hex");
|
|
683
|
+
} catch {
|
|
684
|
+
configReadError = true;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
const sessions = await scanSessions(options.codex_home, options.since_days);
|
|
689
|
+
const commands = options.command_probes
|
|
690
|
+
? { enabled: true, ...commandProbes(options.codex_bin, options.codex_home) }
|
|
691
|
+
: { enabled: false };
|
|
692
|
+
const activeWriters = options.command_probes
|
|
693
|
+
? activeConfigWriters(configPath)
|
|
694
|
+
: { available: false, detected: false, count: 0, probe: "disabled" };
|
|
695
|
+
|
|
696
|
+
const configAfter = await fileMetadata(configPath);
|
|
697
|
+
let configHashAfter = null;
|
|
698
|
+
if (configAfter.type === "file") {
|
|
699
|
+
try {
|
|
700
|
+
configHashAfter = await hashFile(configPath);
|
|
701
|
+
} catch {
|
|
702
|
+
configHashAfter = null;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
const report = {
|
|
707
|
+
schema_version: 1,
|
|
708
|
+
generated_at: new Date().toISOString(),
|
|
709
|
+
scope: "local_codex_only",
|
|
710
|
+
codex_home: "<codex-home>",
|
|
711
|
+
files: {
|
|
712
|
+
config: { ...configBefore, sha256: configHashBefore },
|
|
713
|
+
auth,
|
|
714
|
+
},
|
|
715
|
+
config,
|
|
716
|
+
sessions,
|
|
717
|
+
runtime: {
|
|
718
|
+
active_writers: activeWriters,
|
|
719
|
+
config_drift_detected: !sameFingerprint(configBefore, configAfter, configHashBefore, configHashAfter),
|
|
720
|
+
config_read_error: configReadError,
|
|
721
|
+
},
|
|
722
|
+
commands,
|
|
723
|
+
findings: [],
|
|
724
|
+
};
|
|
725
|
+
report.findings = buildFindings(report);
|
|
726
|
+
if (configReadError) report.findings.push({ code: "config_read_failed", severity: "error", scope: "local_config" });
|
|
727
|
+
return report;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
async function main() {
|
|
731
|
+
let options;
|
|
732
|
+
try {
|
|
733
|
+
options = parseArgs(process.argv.slice(2));
|
|
734
|
+
} catch (error) {
|
|
735
|
+
if (error instanceof UsageError) {
|
|
736
|
+
process.stderr.write("audit-codex-config: " + error.message + "\n");
|
|
737
|
+
process.exitCode = 2;
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
throw error;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (options.help) {
|
|
744
|
+
process.stdout.write(usage());
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
try {
|
|
749
|
+
const report = await audit(options);
|
|
750
|
+
process.stdout.write(options.json ? JSON.stringify(report, null, 2) + "\n" : humanReport(report));
|
|
751
|
+
} catch (error) {
|
|
752
|
+
if (error instanceof UsageError) {
|
|
753
|
+
process.stderr.write("audit-codex-config: " + error.message + "\n");
|
|
754
|
+
process.exitCode = 2;
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
process.stderr.write("audit-codex-config: audit failed\n");
|
|
758
|
+
process.exitCode = 1;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
await main();
|