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
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ suite detects the missing binary, prints a clear skip message, and exits 0
logical units; a PR is a series of reviewed, individually sensible commits,
not one giant diff.

## Release workflow

- `package.json`'s `version` is the single source of truth for release
identity. `docker/Dockerfile` documents the image tag policy: images are
published to `ghcr.io/capsize-games/headlesscode`, tagged with the exact
`package.json` version plus a floating `latest` (versioned tag for
reproducibility, `latest` for local experimentation only).
- Cut a release by pushing a `v<version>` tag whose version matches
`package.json` exactly — `.github/workflows/publish.yml` requires the
tag's `package.json` version to match the pushed `v*` tag. Do not retag or
move an existing tag.
- `npm run check-version` verifies every tracked in-repo image/tag reference
matches `package.json` (historical examples stay allow-listed with reasons
in `scripts/check-version-sync.mjs`). It must pass before tagging.

## Code of conduct

All contributors and maintainers are expected to follow our
Expand Down
28 changes: 18 additions & 10 deletions docs/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,27 @@ other servers; failures are included in the system prompt and logger. Tool
errors are returned as tool errors. Server clients are closed when the session
ends, including setup-error paths.

Supported: tool calls (per-server function tools) and resources.
Supported: tool calls (per-server function tools), resources, and prompts.
`mcp_list_resources` lists the resources one connected server advertises;
`access_mcp_resource` reads a single resource URI through a named connected
server (at most 100 resources per server). Both are exposed to modes in the
`mcp` tool group, respecting `allowedMcpServers`, and are registered only for
unrestricted sessions (an explicit `tools` list never gains them). Safety
bounds: the URI is only ever resolved BY the named configured server — naming
an unconnected server fails instead of reaching any other server or host, and
bare paths or overlong URIs are rejected. Every read is truncated to 64K
characters with the cut named. Server clients (tools and resources alike) are
closed when the session ends, including setup-error paths.
server (at most 100 resources per server). `mcp_list_prompts` lists the
prompts one connected server advertises (name, description, arguments —
metadata only, never template text); `mcp_get_prompt` renders one prompt
through a named connected server with string arguments given as a JSON
object (at most 100 prompts per server). All four are exposed to modes in
the `mcp` tool group, respecting `allowedMcpServers`, and are registered
only for unrestricted sessions (an explicit `tools` list never gains them).
Prompt templates are a read-only discovery surface: the model sees metadata
first and fetches a full template only on explicit request — prompt text is
never spliced into the system prompt automatically. Safety
bounds: the server name is the allow-list everywhere — naming
an unconnected server fails instead of reaching any other server or host; prompt
argument values must be strings, and required arguments are validated
before any server call. Every resource read and every rendered prompt is truncated to 64K
characters with the cut named. Server clients (tools, resources, and
prompts alike) are closed when the session ends, including setup-error paths.

MCP prompts, OAuth setup, per-tool approval, and interactive controls for
MCP OAuth setup, per-tool approval, and interactive controls for
enabling servers are not implemented.
Configured server tools may read or change data according to that server's
capabilities. HeadlessCode's own default command execution also runs with the
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"coverage": "node scripts/coverage.mjs",
"check-standards": "node scripts/check-code-standards.mjs",
"check-architecture": "tsx scripts/check-architecture.mjs",
"check-version": "node scripts/check-version-sync.mjs",
"prepublishOnly": "npm ci && npm test"
},
"dependencies": {
Expand Down
116 changes: 116 additions & 0 deletions scripts/check-version-sync.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Version-sync check (#190): the package.json version is the single source
// of truth for release identity. docker/Dockerfile documents tagging images
// with the exact package.json version plus a floating `latest`, but nothing
// enforced it, so pins drifted silently (1.9.16 vs npm 1.3.0 vs image
// 0.1.0). This script fails when any TRACKED in-repo image/tag reference
// names a version that does not match package.json, unless the reference is
// an explicit historical/example allow-list entry below.
//
// Usage: node scripts/check-version-sync.mjs [--root <dir>]
// Exit 0 when in sync; exit 1 naming the offending file(s). No network:
// published npm/ghcr lag between releases is expected and not checked.
import { execFileSync } from "node:child_process"
import fs from "node:fs"
import path from "node:path"
import { fileURLToPath } from "node:url"

const repoRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)))

function argValue(flag) {
const i = process.argv.indexOf(flag)
return i >= 0 ? process.argv[i + 1] : undefined
}

const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/

const IMAGE_TAG = /(?:headlesscode|ghcr\.io\/capsize-games\/headlesscode):([A-Za-z0-9_][A-Za-z0-9_.-]*)/g
const TAG_VERSION_LIKE = /^v?\d+\.\d+\.\d+/

// Tracked references that intentionally name a different version, each with
// a reason. Tightly scoped (file + the exact pinned text found in that
// file), so a NEW stale pin elsewhere still fails.
const ALLOW_LIST = [
{
file: "docker/Dockerfile",
match: "headlesscode:0.1.0",
reason: "illustrative build example + version-policy doc, not a pinned release tag",
},
{
file: "scripts/docker-smoke.sh",
match: 'TAG="${1:-headlesscode:0.1.0}"',
reason: "smoke-script default local tag; caller may override via argv",
},
]

// The checker (and its self-test) carry allow-listed pin strings as data,
// so they are never scanned as candidate pins themselves.
const SELF_FILES = new Set(["scripts/check-version-sync.mjs", "scripts/check-version-sync.test.mjs"])

function isAllowed(file, fileText) {
return ALLOW_LIST.some((entry) => entry.file === file && fileText.includes(entry.match))
}

function listTrackedFiles(root) {
try {
const out = execFileSync("git", ["ls-files", "-z"], { cwd: root, encoding: "utf8" })
return out.split("\0").filter(Boolean)
} catch {
return walkFiles(root)
}
}

function walkFiles(root) {
const out = []
const walk = (dir) => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
if (entry.name === "node_modules" || entry.name === ".git") continue
const full = path.join(dir, entry.name)
if (entry.isDirectory()) walk(full)
else if (entry.isFile()) out.push(path.relative(root, full))
}
}
walk(root)
return out
}

function checkTree(root) {
const pkgRaw = fs.readFileSync(path.join(root, "package.json"), "utf8")
const pkg = JSON.parse(pkgRaw)
const version = pkg.version
if (typeof version !== "string" || !SEMVER.test(version)) {
return { ok: false, errors: [`package.json version ${JSON.stringify(version)} is not valid semver`] }
}
const errors = []
for (const file of listTrackedFiles(root)) {
if (file.startsWith(".git/") || file.includes("node_modules")) continue
if (SELF_FILES.has(file)) continue
let text
try {
text = fs.readFileSync(path.join(root, file), "utf8")
} catch {
continue
}
if (text.includes("\0")) continue
for (const match of text.matchAll(IMAGE_TAG)) {
const tag = match[1]
if (!TAG_VERSION_LIKE.test(tag)) continue
const bare = tag.startsWith("v") ? tag.slice(1) : tag
if (bare === version) continue
if (isAllowed(file, text)) continue
errors.push(`${file}: image tag '${match[0]}' does not match package.json version ${version}`)
}
}
return { ok: errors.length === 0, errors, version }
}

function main() {
const root = path.resolve(repoRoot, argValue("--root") ?? ".")
const { ok, errors, version } = checkTree(root)
if (!ok) {
for (const error of errors) process.stdout.write(`version-sync: ${error}\n`)
process.exit(1)
}
process.stdout.write(`version-sync: ok (package.json ${version})\n`)
}

main()
84 changes: 84 additions & 0 deletions scripts/check-version-sync.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Self-test for scripts/check-version-sync.mjs (#190): builds fixture trees
// with a copied package.json + scripts/check-version-sync.mjs layout, and
// asserts happy/sad/bad behavior. Exit 1 on mismatch. Pure node, no network.
import { execFileSync } from "node:child_process"
import fs from "node:fs"
import os from "node:os"
import path from "node:path"
import { fileURLToPath } from "node:url"

const repoRoot = path.dirname(path.dirname(fileURLToPath(import.meta.url)))

function fail(message) {
console.error(`FAIL version-sync-selftest: ${message}`)
process.exit(1)
}

function run(root, extraArgs = []) {
try {
const out = execFileSync("node", ["scripts/check-version-sync.mjs", "--root", root, ...extraArgs], {
cwd: repoRoot, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"],
})
return { status: 0, out }
} catch (error) {
return { status: error.status ?? 1, out: `${error.stdout ?? ""}${error.stderr ?? ""}` }
}
}

function fixtureTree(files) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "headlesscode-version-sync-"))
fs.mkdirSync(path.join(dir, "scripts"), { recursive: true })
fs.copyFileSync(
path.join(repoRoot, "scripts", "check-version-sync.mjs"),
path.join(dir, "scripts", "check-version-sync.mjs"),
)
for (const [name, content] of Object.entries(files)) {
const full = path.join(dir, name)
fs.mkdirSync(path.dirname(full), { recursive: true })
fs.writeFileSync(full, content)
}
return dir
}

// Happy: current tree passes.
const happy = run(repoRoot)
if (happy.status !== 0) fail(`current tree failed:\n${happy.out}`)

// Sad: fixture with a mismatched pin and no allow-list entry fails naming the file.
const sadDir = fixtureTree({
"package.json": JSON.stringify({ version: "9.9.9" }),
"deploy/compose.yml": "image: ghcr.io/capsize-games/headlesscode:1.2.3\n",
"docker/Dockerfile": "# -t headlesscode:0.1.0\n",
})
try {
const sad = run(sadDir)
if (sad.status !== 1) fail(`mismatched-pin fixture exited ${sad.status}, want 1`)
if (!sad.out.includes("deploy/compose.yml")) fail(`mismatch did not name the file:\n${sad.out}`)
} finally {
fs.rmSync(sadDir, { recursive: true, force: true })
}

// Sad (bump simulation): the same fixture passes when the pin matches.
const bumpDir = fixtureTree({
"package.json": JSON.stringify({ version: "1.2.3" }),
"deploy/compose.yml": "image: ghcr.io/capsize-games/headlesscode:1.2.3\n",
})
try {
const bumped = run(bumpDir)
if (bumped.status !== 0) fail(`matching-pin fixture failed:\n${bumped.out}`)
} finally {
fs.rmSync(bumpDir, { recursive: true, force: true })
}

// Bad: malformed semver fails with a clear message, not a stack.
const badDir = fixtureTree({ "package.json": JSON.stringify({ version: "1.9" }) })
try {
const bad = run(badDir)
if (bad.status !== 1) fail(`malformed-semver fixture exited ${bad.status}, want 1`)
if (!bad.out.includes("not valid semver")) fail(`malformed semver lacked a clear message:\n${bad.out}`)
if (bad.out.includes("at ") && bad.out.includes("node:internal")) fail(`malformed semver leaked a stack:\n${bad.out}`)
} finally {
fs.rmSync(badDir, { recursive: true, force: true })
}

console.log(" ok version-sync-selftest: current tree passes, mismatch fails naming the file, malformed semver is clean")
2 changes: 1 addition & 1 deletion scripts/run-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function removeOwnedTempRoot(root) {
* remembered to invoke it separately — the only DIRECT check that the
* vendored Zoo Code prompt builder still imports and runs headlessly.
*/
const EXTRA_FILES = ["scripts/check-page-script.mjs", "scripts/check-tmpdir-project-store.mjs", "scripts/coverage.test.mjs", "scripts/check-code-standards.test.mjs", "scripts/check-architecture.test.mjs", "src/vendor/tests/smoke.ts"]
const EXTRA_FILES = ["scripts/check-page-script.mjs", "scripts/check-tmpdir-project-store.mjs", "scripts/coverage.test.mjs", "scripts/check-code-standards.test.mjs", "scripts/check-architecture.test.mjs", "scripts/check-version-sync.test.mjs", "src/vendor/tests/smoke.ts"]

function findTestFiles(dir) {
const found = []
Expand Down
Loading