@smthrs/std 1.0.0-rc.3 → 1.0.0-rc.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"GitWorktree.js","sourceRoot":"","sources":["../../../src/internal/GitWorktree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAA;AAC1C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,MAAM,MAAM,GAAG,CAAC,OAAe,EAAE,OAAsB,gBAAgB,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAA;AAEpH;;;;GAIG;AACH,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,0BAA0B,EAAE,IAAI,EAAE,sBAAsB,CAAU,CAAA;AAEjG,qFAAqF;AACrF,MAAM,QAAQ,GAAG,EAAE,mBAAmB,EAAE,GAAG,EAAE,iBAAiB,EAAE,WAAW,EAAW,CAAA;AAEtF;;;;GAIG;AACH,MAAM,YAAY,GAAG,gFAAgF,CAAA;AAErG,oFAAoF;AACpF,MAAM,QAAQ,GAAG,kBAAkB,CAAA;AAEnC,MAAM,GAAG,GAAG,CAAC,OAAe,EAAE,IAA2B,EAAE,GAAsC,EAAE,EAAE,CACnG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,CACtE,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,OAAO,mBAA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AAI,CACf,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CACrB,MAAM,CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAC3D,CACF,CACF,CACJ,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAA","sourcesContent":["/**\n * Detached checkouts shared by checkpoint reads and baseline test runs.\n *\n * ## Host git never reads a file the agent can write that names a program\n *\n * The repository is the workspace's, and an agent can write its `.git`: a\n * containerised agent writes it through the bind mount. Git reads programs out\n * of that directory in more places than any list of `-c` overrides can close.\n * Hooks and `core.fsmonitor` can be overridden, but a filter driver\n * (`filter.<name>.clean`/`.smudge` in `.git/config`, selected by\n * `.git/info/attributes`) cannot: git has no switch that ignores repository\n * config or `$GIT_DIR/info/attributes`, and overriding each driver by name\n * races an agent that keeps rewriting the file.\n *\n * So the git that records and checks out trees runs against a **shadow**\n * `GIT_DIR`: a bare repository this module creates under the host's temporary\n * directory for one operation and deletes afterwards. Its config, hooks and\n * `info/attributes` are the ones `git init --template=` writes, which is none.\n * `GIT_CONFIG_NOSYSTEM` and `GIT_CONFIG_GLOBAL=/dev/null` drop the host's own\n * config files too, so the only settings are the ones on the command line.\n * `GIT_OBJECT_DIRECTORY` points at the workspace's object store, because objects\n * are data: git hashes and inflates them and never runs anything they say.\n *\n * What still touches the workspace repository is plain data:\n *\n * - `rev-parse` in the workspace, which resolves refs and paths and runs no\n * hook, filter, fsmonitor or other configured program;\n * - `git config --file <workspace config>`, which reads or writes that one file\n * and follows no `include`;\n * - a copy of the workspace index into the shadow, so the recorded tree holds\n * what the agent staged without the harness writing the agent's index; and\n * - a handful of `core.*` settings that change how bytes are hashed\n * ({@link dataSettings}), each accepted only as a bare word.\n *\n * A materialized checkout gets its own standalone `.git`, written by this\n * module as files, so a container can still run git in it: `HEAD` names the\n * commit, `objects/info/alternates` points back at the workspace's objects by a\n * relative path, and `index` is the one the checkout was written from. Host git\n * never uses that directory; it is the container's.\n *\n * @since 1.0.0\n */\n\nimport type { ChildProcessSpawner } from \"@smthrs/kernel/ChildProcessSpawner\"\nimport { Effect } from \"effect\"\nimport * as StdError from \"../StdError.ts\"\nimport * as Exec from \"./Exec.ts\"\n\nconst failed = (message: string, code: StdError.Code = \"command_failed\") => new StdError.StdError({ code, message })\n\n/**\n * Settings that stop the workspace repository from naming a program for the\n * `rev-parse` this module runs in it. `rev-parse` runs none of them; these keep\n * that true if a later call is added beside it.\n */\nconst hostGitSettings = [\"-c\", \"core.hooksPath=/dev/null\", \"-c\", \"core.fsmonitor=false\"] as const\n\n/** Host config files git would otherwise read, removed from every shadow command. */\nconst isolated = { GIT_CONFIG_NOSYSTEM: \"1\", GIT_CONFIG_GLOBAL: \"/dev/null\" } as const\n\n/**\n * Workspace settings that change how a tree is hashed or compared, carried\n * onto the shadow so a checkpoint records what the agent's own git would.\n * None of them names a program.\n */\nconst dataSettings = /^core\\.(autocrlf|eol|safecrlf|filemode|symlinks|ignorecase|precomposeunicode)$/\n\n/** A setting value this module will repeat to git: a bare word, never a command. */\nconst bareWord = /^[A-Za-z0-9_-]+$/\n\nconst run = (command: string, args: ReadonlyArray<string>, env?: Readonly<Record<string, string>>) =>\n Exec.exec(command, { args, ...(env === undefined ? {} : { env }) }).pipe(\n Effect.mapError((error) => failed(`${command} could not run: ${error.message}`))\n )\n\n/**\n * Runs host git in the workspace at `root`, for `rev-parse` only.\n *\n * @category utilities\n * @since 1.0.0\n */\nconst git = (root: string, args: ReadonlyArray<string>) => run(\"git\", [...hostGitSettings, \"-C\", root, ...args])\n\nconst resolveCommit = (root: string, refs: ReadonlyArray<string>) =>\n Effect.gen(function*() {\n for (const ref of refs) {\n const answer = yield* git(root, [\"rev-parse\", \"--verify\", \"--quiet\", `${ref}^{commit}`])\n const commit = answer.stdout.trim()\n if (answer.exitCode === 0 && commit !== \"\") return { ref, commit }\n }\n return yield* Effect.fail(failed(`No commit resolves from ${refs.join(\" or \")} in ${root}.`, \"not_found\"))\n })\n\n/**\n * Where one workspace repository keeps what the shadow needs, as its own git\n * reports it.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Repository {\n /** The root the caller named, without a trailing slash. */\n readonly root: string\n /** The same directory, as git canonicalizes it. */\n readonly toplevel: string\n /** The common git directory, which holds config and objects. */\n readonly common: string\n /** The workspace index. */\n readonly index: string\n readonly objectFormat: string\n /** {@link dataSettings} as `-c` arguments. */\n readonly settings: ReadonlyArray<string>\n}\n\n/**\n * Reads or writes the workspace's config file as a file, never as a repository.\n *\n * `--git-dir=/dev/null` stops git discovering any repository around the host's\n * working directory, and `--file` reads the one file without `include`s.\n *\n * @category utilities\n * @since 1.0.0\n */\nconst config = (repository: Pick<Repository, \"common\">, args: ReadonlyArray<string>) =>\n run(\"git\", [\"--git-dir=/dev/null\", \"config\", \"--file\", `${repository.common}/config`, ...args], isolated)\n\nconst open = (root: string): Effect.Effect<Repository, StdError.StdError, ChildProcessSpawner> =>\n Effect.gen(function*() {\n const stripped = root.replace(/\\/+$/, \"\")\n const answer = yield* git(stripped, [\n \"rev-parse\",\n \"--path-format=absolute\",\n \"--show-toplevel\",\n \"--git-common-dir\",\n \"--git-path\",\n \"index\",\n \"--show-object-format\"\n ])\n const [toplevel, common, index, objectFormat] = answer.stdout.split(\"\\n\").map((line) => line.trim())\n if (\n answer.exitCode !== 0 || toplevel === undefined || toplevel === \"\" || common === undefined || common === \"\" ||\n index === undefined || index === \"\" || objectFormat === undefined || !bareWord.test(objectFormat)\n ) {\n return yield* Effect.fail(failed(`${stripped} is not a git work tree: ${answer.stderr.trim()}`))\n }\n const found = yield* config({ common }, [\"--get-regexp\", dataSettings.source])\n const settings = found.exitCode === 0\n ? found.stdout.split(\"\\n\").flatMap((line) => {\n const [key, value] = line.trim().split(/\\s+/)\n return key !== undefined && value !== undefined && dataSettings.test(key) && bareWord.test(value)\n ? [\"-c\", `${key}=${value}`]\n : []\n })\n : []\n return { root: stripped, toplevel, common, index, objectFormat, settings }\n })\n\nconst temporaryRoot = (): string => {\n const configured = globalThis.process?.env?.TMPDIR?.replace(/\\/+$/, \"\")\n return configured === undefined || configured === \"\" ? \"/tmp\" : configured\n}\n\nconst remove = (path: string) =>\n run(\"rm\", [\"-rf\", \"--\", path]).pipe(\n Effect.flatMap((removed) => removed.exitCode === 0 ? Effect.void : Effect.fail(failed(removed.stderr.trim())))\n )\n\n/**\n * A harness-owned `GIT_DIR` over one workspace's objects.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Shadow {\n readonly path: string\n readonly repository: Repository\n /** Runs host git with the shadow as `GIT_DIR`, and `workTree` as its work tree when given. */\n readonly git: (\n args: ReadonlyArray<string>,\n workTree?: string\n ) => Effect.Effect<Exec.ExecResult, StdError.StdError, ChildProcessSpawner>\n /** Copies the workspace index into the shadow, so the shadow never writes the agent's own. */\n readonly adoptIndex: Effect.Effect<void, StdError.StdError, ChildProcessSpawner>\n}\n\nconst shadowOf = (repository: Repository, path: string): Shadow => ({\n path,\n repository,\n git: (args, workTree) =>\n run(\n \"git\",\n [\n `--git-dir=${path}`,\n ...(workTree === undefined ? [] : [`--work-tree=${workTree}`]),\n ...hostGitSettings,\n ...repository.settings,\n ...args\n ],\n { ...isolated, GIT_OBJECT_DIRECTORY: `${repository.common}/objects` }\n ),\n adoptIndex: run(\"sh\", [\n \"-c\",\n \"set -C; if [ -e \\\"$1\\\" ]; then cat -- \\\"$1\\\" > \\\"$2\\\"; fi\",\n \"sh\",\n repository.index,\n `${path}/index`\n ]).pipe(\n Effect.flatMap((copied) =>\n copied.exitCode === 0\n ? Effect.void\n : Effect.fail(failed(`Could not read the workspace index: ${copied.stderr.trim()}`))\n )\n )\n})\n\n/**\n * Runs `use` with a fresh {@link Shadow} over the repository at `root`, and\n * deletes the shadow however `use` ends.\n *\n * @category utilities\n * @since 1.0.0\n */\nconst withShadow = <A, E, R>(\n root: string | Repository,\n use: (shadow: Shadow) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E | StdError.StdError, R | ChildProcessSpawner> =>\n Effect.gen(function*() {\n const repository = typeof root === \"string\" ? yield* open(root) : root\n const path = `${temporaryRoot()}/smithers-git-${globalThis.crypto.randomUUID()}`\n return yield* Effect.acquireUseRelease(\n Effect.succeed(path),\n () =>\n Effect.gen(function*() {\n const created = yield* run(\n \"git\",\n [\"init\", \"--quiet\", \"--bare\", \"--template=\", `--object-format=${repository.objectFormat}`, path],\n isolated\n )\n if (created.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not create a shadow repository: ${created.stderr.trim()}`))\n }\n return yield* use(shadowOf(repository, path))\n }),\n () =>\n remove(path).pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"could not remove a shadow repository\").pipe(\n Effect.annotateLogs({ path, reason: error.message })\n )\n )\n )\n )\n })\n\n/** `to` relative to `from`, both absolute POSIX paths. */\nconst relative = (from: string, to: string): string => {\n const source = from.split(\"/\").filter((part) => part !== \"\")\n const target = to.split(\"/\").filter((part) => part !== \"\")\n let shared = 0\n while (shared < source.length && shared < target.length && source[shared] === target[shared]) shared++\n return [...source.slice(shared).map(() => \"..\"), ...target.slice(shared)].join(\"/\") || \".\"\n}\n\n/**\n * The config of a checkout's own `.git`, for the container's git.\n *\n * Only {@link dataSettings}, already restricted to bare words, reach it.\n */\nconst checkoutConfig = (repository: Repository): string => {\n const sha1 = repository.objectFormat === \"sha1\"\n const lines = [\n \"[core]\",\n `\\trepositoryformatversion = ${sha1 ? 0 : 1}`,\n \"\\tbare = false\",\n ...repository.settings.filter((_, index) => index % 2 === 1).map((setting) => {\n const [key, value] = setting.split(\"=\")\n return `\\t${key?.slice(\"core.\".length)} = ${value}`\n }),\n ...(sha1 ? [] : [\"[extensions]\", `\\tobjectformat = ${repository.objectFormat}`])\n ]\n return `${lines.join(\"\\n\")}\\n`\n}\n\n/** Fails with `message` and the command's stderr unless it exited 0. */\nconst succeeded = (result: Exec.ExecResult, message: string) =>\n result.exitCode === 0 ? Effect.void : Effect.fail(failed(`${message}: ${result.stderr.trim()}`))\n\n/**\n * Measures which staging directory shares the filesystem of the checkout's\n * parent `$1`: the shadow `$2`, the workspace root's parent `$3`, or the host\n * cache directory `$4`. Prints one line each for the parent, the shadow, the\n * root's parent (`unwritable` when the host user cannot create a stage there)\n * and the cache (empty unless both others missed and it could be created).\n * `stat -c` is GNU and BusyBox, `stat -f` is BSD; an empty line means neither\n * answered.\n */\nconst measure = [\n \"set -e\",\n \"mkdir -p -- \\\"$1\\\"\",\n \"dev() { stat -c %d -- \\\"$1\\\" 2>/dev/null || stat -f %d -- \\\"$1\\\" 2>/dev/null || echo; }\",\n \"t=$(dev \\\"$1\\\")\",\n \"s=$(dev \\\"$2\\\")\",\n \"if [ -w \\\"$3\\\" ]; then b=$(dev \\\"$3\\\"); else b=unwritable; fi\",\n \"c=\",\n \"if [ -n \\\"$t\\\" ] && [ \\\"$t\\\" != \\\"$s\\\" ] && [ \\\"$t\\\" != \\\"$b\\\" ] && [ -n \\\"$4\\\" ] && mkdir -p -m 700 -- \\\"$4\\\" 2>/dev/null; then c=$(dev \\\"$4\\\"); fi\",\n \"printf '%s\\\\n' \\\"$t\\\" \\\"$s\\\" \\\"$b\\\" \\\"$c\\\"\"\n].join(\"; \")\n\n/**\n * The host user's cache directory for checkout stages: `$XDG_CACHE_HOME`, or\n * `~/.cache`, under `smithers`. Empty when neither is an absolute path.\n */\nconst cacheRoot = (): string => {\n const env = globalThis.process?.env\n const xdg = env?.XDG_CACHE_HOME?.replace(/\\/+$/, \"\")\n if (xdg !== undefined && xdg.startsWith(\"/\")) return `${xdg}/smithers`\n const home = env?.HOME?.replace(/\\/+$/, \"\")\n return home !== undefined && home.startsWith(\"/\") ? `${home}/.cache/smithers` : \"\"\n}\n\n/**\n * Moves the staged checkout `$1` into the directory `$2` under the name `$3`\n * in one `rename`, then proves the directory there is the one that was staged.\n * The staging directory is on the same filesystem, so `mv` renames and never\n * copies.\n *\n * The shell first enters `$2` by its physical path and refuses unless that\n * lies under the real path of the workspace root `$4`. The rename then names\n * the target relative to that directory, so a parent the agent swaps for a\n * symlink, before or after the check, cannot carry the checkout out of the\n * workspace.\n */\nconst publish = [\n \"set -e\",\n \"root=$(cd -P -- \\\"$4\\\" && pwd -P)\",\n \"cd -P -- \\\"$2\\\"\",\n \"here=$(pwd -P)\",\n \"case \\\"$here\\\" in \\\"$root\\\"|\\\"$root\\\"/*) ;; *) echo \\\"$2 resolves to $here, outside the workspace $root\\\" >&2; exit 1 ;; esac\",\n \"if [ -e \\\"./$3\\\" ] || [ -L \\\"./$3\\\" ]; then echo \\\"$2/$3 already exists\\\" >&2; exit 1; fi\",\n \"staged=$(ls -di -- \\\"$1\\\" | awk '{print $1}')\",\n \"mv -- \\\"$1\\\" \\\"./$3\\\"\",\n \"if [ -L \\\"./$3\\\" ] || [ ! -d \\\"./$3\\\" ]; then echo \\\"$2/$3 was replaced while it was written\\\" >&2; exit 1; fi\",\n \"moved=$(ls -di -- \\\"./$3\\\" | awk '{print $1}')\",\n \"if [ \\\"$staged\\\" != \\\"$moved\\\" ]; then echo \\\"$2/$3 was replaced while it was written\\\" >&2; exit 1; fi\"\n].join(\"; \")\n\n/**\n * Checks `commit`'s tree out at the new directory `host`, with a standalone\n * `.git` the container's git can use.\n *\n * Host git never writes into an agent-writable directory. The tree and its\n * `.git` are written into a staging directory the agent cannot reach: inside\n * the shadow, or, when the host's temporary directory is another filesystem,\n * beside the workspace root or under the host user's cache directory. One\n * `rename` then gives the finished directory its name under the workspace. A\n * path the agent swaps for a symlink cannot redirect a write: a symlink at\n * `host` fails the call before the rename, and a parent that resolves outside\n * the workspace root fails it before the rename too.\n */\nconst checkout = (shadow: Shadow, host: string, commit: string) =>\n Effect.gen(function*() {\n const repository = shadow.repository\n const parent = host.slice(0, host.lastIndexOf(\"/\"))\n const name = host.slice(host.lastIndexOf(\"/\") + 1)\n const beside = repository.root.slice(0, repository.root.lastIndexOf(\"/\")) || \"/\"\n const cache = cacheRoot()\n const stage = `checkout-${globalThis.crypto.randomUUID()}`\n const besideStage = `${beside.replace(/\\/+$/, \"\")}/.smithers-${stage}`\n const cacheStage = `${cache}/${stage}`\n const measured = yield* run(\"sh\", [\"-c\", measure, \"sh\", parent, shadow.path, beside, cache])\n yield* succeeded(measured, `Could not check out ${commit}`)\n const [target, inShadow, besideRoot, inCache] = measured.stdout.split(\"\\n\").map((line) => line.trim())\n const scratch = target === undefined || target === \"\" || target === inShadow\n ? undefined\n : target === besideRoot\n ? besideStage\n : target === inCache\n ? cacheStage\n : undefined\n const base = target === undefined || target === \"\"\n ? undefined\n : target === inShadow\n ? shadow.path\n : scratch\n if (base === undefined) {\n const unwritable = besideRoot === \"unwritable\" ? \" (not writable by this user)\" : \"\"\n return yield* Effect.fail(\n failed(\n `Could not check out ${commit}: neither ${shadow.path} nor ${beside}${unwritable} nor ${\n cache === \"\" ? \"a cache directory\" : cache\n } is on the filesystem of ${parent}`\n )\n )\n }\n const staged = `${base}/${name}`\n const objects = relative(\n `${repository.toplevel}${host.slice(repository.root.length)}/.git/objects`,\n `${repository.common}/objects`\n )\n const write = Effect.gen(function*() {\n const prepared = yield* run(\"sh\", [\n \"-c\",\n [\n \"set -eC\",\n ...(scratch !== undefined ? [\"mkdir -m 700 -- \\\"$1\\\"\"] : []),\n \"mkdir -- \\\"$2\\\" \\\"$2/.git\\\" \\\"$2/.git/objects\\\" \\\"$2/.git/objects/info\\\" \\\"$2/.git/refs\\\"\",\n \"printf '%s\\\\n' \\\"$3\\\" > \\\"$2/.git/HEAD\\\"\",\n \"printf '%s\\\\n' \\\"$4\\\" > \\\"$2/.git/objects/info/alternates\\\"\",\n \"printf '%s' \\\"$5\\\" > \\\"$2/.git/config\\\"\"\n ].join(\"; \"),\n \"sh\",\n base,\n staged,\n commit,\n objects,\n checkoutConfig(repository)\n ])\n yield* succeeded(prepared, `Could not check out ${commit}`)\n const written = yield* shadow.git([\"read-tree\", \"--reset\", \"-u\", commit], staged)\n yield* succeeded(written, `Could not check out ${commit}`)\n const indexed = yield* run(\"sh\", [\n \"-c\",\n \"set -C; cat -- \\\"$1\\\" > \\\"$2\\\"\",\n \"sh\",\n `${shadow.path}/index`,\n `${staged}/.git/index`\n ])\n yield* succeeded(indexed, `Could not check out ${commit}`)\n const moved = yield* run(\"sh\", [\"-c\", publish, \"sh\", staged, parent, name, repository.root])\n yield* succeeded(moved, `Could not check out ${commit}`)\n })\n return yield* scratch !== undefined\n ? write.pipe(Effect.ensuring(remove(scratch).pipe(Effect.ignore)))\n : write\n })\n\nconst withDetachedWorktree = <A, E, R>(\n root: string,\n prefix: string,\n commit: string,\n use: (host: string) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E | StdError.StdError, R | ChildProcessSpawner> =>\n Effect.gen(function*() {\n // Allocate on execution, including when the same Effect is run twice.\n // Never remove an existing checkout: another call may still be using it.\n const host = `${root.replace(/\\/+$/, \"\")}/${prefix}-${globalThis.crypto.randomUUID()}`\n return yield* Effect.acquireUseRelease(\n Effect.succeed(host),\n () =>\n Effect.gen(function*() {\n yield* withShadow(root, (shadow) => checkout(shadow, host, commit))\n return yield* use(host)\n }),\n // A checkout left behind is a stale copy of the repository inside the\n // workspace. Walks prune it, but the operator must still hear about it.\n () =>\n remove(host).pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"could not remove a scratch checkout\").pipe(\n Effect.annotateLogs({ path: host, reason: error.message })\n )\n )\n )\n )\n })\n\n/**\n * Internal Git operations used by both checkpoint and baseline leases.\n *\n * @category utilities\n * @since 1.0.0\n */\nexport const GitWorktree = { config, git, open, resolveCommit, withDetachedWorktree, withShadow }\n"]}
1
+ {"version":3,"file":"GitWorktree.js","sourceRoot":"","sources":["../../../src/internal/GitWorktree.ts"],"names":[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CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAC,IAAI,CAC3D,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAC3D,CACF,CACF,CACJ,CAAA;AACH,CAAC,CAAC,CAAA;AAEJ;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAA","sourcesContent":["/**\n * Detached checkouts shared by checkpoint reads and baseline test runs.\n *\n * ## Host git never reads a file the agent can write that names a program\n *\n * The repository is the workspace's, and an agent can write its `.git`: a\n * containerised agent writes it through the bind mount. Git reads programs out\n * of that directory in more places than any list of `-c` overrides can close.\n * Hooks and `core.fsmonitor` can be overridden, but a filter driver\n * (`filter.<name>.clean`/`.smudge` in `.git/config`, selected by\n * `.git/info/attributes`) cannot: git has no switch that ignores repository\n * config or `$GIT_DIR/info/attributes`, and overriding each driver by name\n * races an agent that keeps rewriting the file.\n *\n * So the git that records and checks out trees runs against a **shadow**\n * `GIT_DIR`: a bare repository this module creates under the host's temporary\n * directory for one operation and deletes afterwards. Its config, hooks and\n * `info/attributes` are the ones `git init --template=` writes, which is none.\n * `GIT_CONFIG_NOSYSTEM` and `GIT_CONFIG_GLOBAL=/dev/null` drop the host's own\n * config files too, so the only settings are the ones on the command line.\n * `GIT_OBJECT_DIRECTORY` points at the workspace's object store, because objects\n * are data: git hashes and inflates them and never runs anything they say.\n *\n * What still touches the workspace repository is plain data:\n *\n * - `rev-parse` in the workspace, which resolves refs and paths and runs no\n * hook, filter, fsmonitor or other configured program;\n * - `git config --file <workspace config>`, which reads or writes that one file\n * and follows no `include`;\n * - a copy of the workspace index into the shadow, so the recorded tree holds\n * what the agent staged without the harness writing the agent's index; and\n * - a handful of `core.*` settings that change how bytes are hashed\n * ({@link dataSettings}), each accepted only as a bare word.\n *\n * A materialized checkout gets its own standalone `.git`, written by this\n * module as files, so a container can still run git in it: `HEAD` names the\n * commit, `objects/info/alternates` points back at the workspace's objects by a\n * relative path, and `index` is the one the checkout was written from. Host git\n * never uses that directory; it is the container's.\n *\n * @since 1.0.0\n */\n\nimport type { ChildProcessSpawner } from \"@smthrs/kernel/ChildProcessSpawner\"\nimport { Effect } from \"effect\"\nimport * as StdError from \"../StdError.ts\"\nimport * as Exec from \"./Exec.ts\"\n\nconst failed = (message: string, code: StdError.Code = \"command_failed\") => new StdError.StdError({ code, message })\n\n/**\n * Settings that stop the workspace repository from naming a program for the\n * `rev-parse` this module runs in it. `rev-parse` runs none of them; these keep\n * that true if a later call is added beside it.\n */\nconst hostGitSettings = [\"-c\", \"core.hooksPath=/dev/null\", \"-c\", \"core.fsmonitor=false\"] as const\n\n/** Host config files git would otherwise read, removed from every shadow command. */\nconst isolated = { GIT_CONFIG_NOSYSTEM: \"1\", GIT_CONFIG_GLOBAL: \"/dev/null\" } as const\n\n/**\n * Workspace settings that change how a tree is hashed or compared, carried\n * onto the shadow so a checkpoint records what the agent's own git would.\n * None of them names a program.\n */\nconst dataSettings = /^core\\.(autocrlf|eol|safecrlf|filemode|symlinks|ignorecase|precomposeunicode)$/\n\n/** A setting value this module will repeat to git: a bare word, never a command. */\nconst bareWord = /^[A-Za-z0-9_-]+$/\n\nconst run = (command: string, args: ReadonlyArray<string>, env?: Readonly<Record<string, string>>) =>\n Exec.exec(command, { args, ...(env === undefined ? {} : { env }) }).pipe(\n Effect.mapError((error) => failed(`${command} could not run: ${error.message}`))\n )\n\n/**\n * Runs host git in the workspace at `root`, for `rev-parse` only.\n *\n * @category utilities\n * @since 1.0.0\n */\nconst git = (root: string, args: ReadonlyArray<string>) => run(\"git\", [...hostGitSettings, \"-C\", root, ...args])\n\nconst resolveCommit = (root: string, refs: ReadonlyArray<string>) =>\n Effect.gen(function*() {\n for (const ref of refs) {\n const answer = yield* git(root, [\"rev-parse\", \"--verify\", \"--quiet\", `${ref}^{commit}`])\n const commit = answer.stdout.trim()\n if (answer.exitCode === 0 && commit !== \"\") return { ref, commit }\n }\n return yield* Effect.fail(failed(`No commit resolves from ${refs.join(\" or \")} in ${root}.`, \"not_found\"))\n })\n\n/**\n * Where one workspace repository keeps what the shadow needs, as its own git\n * reports it.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Repository {\n /** The root the caller named, without a trailing slash. */\n readonly root: string\n /** The same directory, as git canonicalizes it. */\n readonly toplevel: string\n /** The common git directory, which holds config and objects. */\n readonly common: string\n /** The workspace index. */\n readonly index: string\n readonly objectFormat: string\n /** {@link dataSettings} as `-c` arguments. */\n readonly settings: ReadonlyArray<string>\n}\n\n/**\n * Reads or writes the workspace's config file as a file, never as a repository.\n *\n * `--git-dir=/dev/null` stops git discovering any repository around the host's\n * working directory, and `--file` reads the one file without `include`s.\n *\n * @category utilities\n * @since 1.0.0\n */\nconst config = (repository: Pick<Repository, \"common\">, args: ReadonlyArray<string>) =>\n run(\"git\", [\"--git-dir=/dev/null\", \"config\", \"--file\", `${repository.common}/config`, ...args], isolated)\n\nconst open = (root: string): Effect.Effect<Repository, StdError.StdError, ChildProcessSpawner> =>\n Effect.gen(function*() {\n const stripped = root.replace(/\\/+$/, \"\")\n const answer = yield* git(stripped, [\n \"rev-parse\",\n \"--path-format=absolute\",\n \"--show-toplevel\",\n \"--git-common-dir\",\n \"--git-path\",\n \"index\",\n \"--show-object-format\"\n ])\n const [toplevel, common, index, objectFormat] = answer.stdout.split(\"\\n\").map((line) => line.trim())\n if (\n answer.exitCode !== 0 || toplevel === undefined || toplevel === \"\" || common === undefined || common === \"\" ||\n index === undefined || index === \"\" || objectFormat === undefined || !bareWord.test(objectFormat)\n ) {\n return yield* Effect.fail(failed(`${stripped} is not a git work tree: ${answer.stderr.trim()}`))\n }\n const found = yield* config({ common }, [\"--get-regexp\", dataSettings.source])\n const settings = found.exitCode === 0\n ? found.stdout.split(\"\\n\").flatMap((line) => {\n const [key, value] = line.trim().split(/\\s+/)\n return key !== undefined && value !== undefined && dataSettings.test(key) && bareWord.test(value)\n ? [\"-c\", `${key}=${value}`]\n : []\n })\n : []\n return { root: stripped, toplevel, common, index, objectFormat, settings }\n })\n\nconst temporaryRoot = (): string => {\n const configured = globalThis.process?.env?.TMPDIR?.replace(/\\/+$/, \"\")\n return configured === undefined || configured === \"\" ? \"/tmp\" : configured\n}\n\nconst remove = (path: string) =>\n run(\"rm\", [\"-rf\", \"--\", path]).pipe(\n Effect.flatMap((removed) => removed.exitCode === 0 ? Effect.void : Effect.fail(failed(removed.stderr.trim())))\n )\n\n/**\n * A harness-owned `GIT_DIR` over one workspace's objects.\n *\n * @category models\n * @since 1.0.0\n */\nexport interface Shadow {\n readonly path: string\n readonly repository: Repository\n /** Runs host git with the shadow as `GIT_DIR`, and `workTree` as its work tree when given. */\n readonly git: (\n args: ReadonlyArray<string>,\n workTree?: string\n ) => Effect.Effect<Exec.ExecResult, StdError.StdError, ChildProcessSpawner>\n /**\n * Copies the workspace index into the shadow, with its modification time, so\n * the shadow never writes the agent's own.\n *\n * The time is part of what git reads. It trusts an entry's recorded stat\n * unless the entry is at least as new as the index file, in whole seconds;\n * a copy stamped at the moment of copying made every entry look older, and a\n * same-size edit from the second the index was written was recorded as the\n * committed bytes (#3431). The time is taken before the bytes are read, so\n * an index rewritten meanwhile leaves the copy looking older, never newer.\n */\n readonly adoptIndex: Effect.Effect<void, StdError.StdError, ChildProcessSpawner>\n}\n\n/** The `adoptIndex` script: `$1` is the workspace index, `$2` the shadow's. */\nconst adoptIndexScript = [\n \"set -C\",\n \"if [ -e \\\"$1\\\" ]\",\n \"then : > \\\"$2.at\\\" && touch -r \\\"$1\\\" -- \\\"$2.at\\\" && cat -- \\\"$1\\\" > \\\"$2\\\" && touch -r \\\"$2.at\\\" -- \\\"$2\\\" && rm -f -- \\\"$2.at\\\"\",\n \"fi\"\n].join(\"; \")\n\nconst shadowOf = (repository: Repository, path: string): Shadow => ({\n path,\n repository,\n git: (args, workTree) =>\n run(\n \"git\",\n [\n `--git-dir=${path}`,\n ...(workTree === undefined ? [] : [`--work-tree=${workTree}`]),\n ...hostGitSettings,\n ...repository.settings,\n ...args\n ],\n { ...isolated, GIT_OBJECT_DIRECTORY: `${repository.common}/objects` }\n ),\n adoptIndex: run(\"sh\", [\n \"-c\",\n adoptIndexScript,\n \"sh\",\n repository.index,\n `${path}/index`\n ]).pipe(\n Effect.flatMap((copied) =>\n copied.exitCode === 0\n ? Effect.void\n : Effect.fail(failed(`Could not read the workspace index: ${copied.stderr.trim()}`))\n )\n )\n})\n\n/**\n * Runs `use` with a fresh {@link Shadow} over the repository at `root`, and\n * deletes the shadow however `use` ends.\n *\n * @category utilities\n * @since 1.0.0\n */\nconst withShadow = <A, E, R>(\n root: string | Repository,\n use: (shadow: Shadow) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E | StdError.StdError, R | ChildProcessSpawner> =>\n Effect.gen(function*() {\n const repository = typeof root === \"string\" ? yield* open(root) : root\n const path = `${temporaryRoot()}/smithers-git-${globalThis.crypto.randomUUID()}`\n return yield* Effect.acquireUseRelease(\n Effect.succeed(path),\n () =>\n Effect.gen(function*() {\n const created = yield* run(\n \"git\",\n [\"init\", \"--quiet\", \"--bare\", \"--template=\", `--object-format=${repository.objectFormat}`, path],\n isolated\n )\n if (created.exitCode !== 0) {\n return yield* Effect.fail(failed(`Could not create a shadow repository: ${created.stderr.trim()}`))\n }\n return yield* use(shadowOf(repository, path))\n }),\n () =>\n remove(path).pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"could not remove a shadow repository\").pipe(\n Effect.annotateLogs({ path, reason: error.message })\n )\n )\n )\n )\n })\n\n/** `to` relative to `from`, both absolute POSIX paths. */\nconst relative = (from: string, to: string): string => {\n const source = from.split(\"/\").filter((part) => part !== \"\")\n const target = to.split(\"/\").filter((part) => part !== \"\")\n let shared = 0\n while (shared < source.length && shared < target.length && source[shared] === target[shared]) shared++\n return [...source.slice(shared).map(() => \"..\"), ...target.slice(shared)].join(\"/\") || \".\"\n}\n\n/**\n * The config of a checkout's own `.git`, for the container's git.\n *\n * Only {@link dataSettings}, already restricted to bare words, reach it.\n */\nconst checkoutConfig = (repository: Repository): string => {\n const sha1 = repository.objectFormat === \"sha1\"\n const lines = [\n \"[core]\",\n `\\trepositoryformatversion = ${sha1 ? 0 : 1}`,\n \"\\tbare = false\",\n ...repository.settings.filter((_, index) => index % 2 === 1).map((setting) => {\n const [key, value] = setting.split(\"=\")\n return `\\t${key?.slice(\"core.\".length)} = ${value}`\n }),\n ...(sha1 ? [] : [\"[extensions]\", `\\tobjectformat = ${repository.objectFormat}`])\n ]\n return `${lines.join(\"\\n\")}\\n`\n}\n\n/** Fails with `message` and the command's stderr unless it exited 0. */\nconst succeeded = (result: Exec.ExecResult, message: string) =>\n result.exitCode === 0 ? Effect.void : Effect.fail(failed(`${message}: ${result.stderr.trim()}`))\n\n/**\n * Measures which staging directory shares the filesystem of the checkout's\n * parent `$1`: the shadow `$2`, the workspace root's parent `$3`, or the host\n * cache directory `$4`. Prints one line each for the parent, the shadow, the\n * root's parent (`unwritable` when the host user cannot create a stage there)\n * and the cache (empty unless both others missed and it could be created).\n * `stat -c` is GNU and BusyBox, `stat -f` is BSD; an empty line means neither\n * answered.\n */\nconst measure = [\n \"set -e\",\n \"mkdir -p -- \\\"$1\\\"\",\n \"dev() { stat -c %d -- \\\"$1\\\" 2>/dev/null || stat -f %d -- \\\"$1\\\" 2>/dev/null || echo; }\",\n \"t=$(dev \\\"$1\\\")\",\n \"s=$(dev \\\"$2\\\")\",\n \"if [ -w \\\"$3\\\" ]; then b=$(dev \\\"$3\\\"); else b=unwritable; fi\",\n \"c=\",\n \"if [ -n \\\"$t\\\" ] && [ \\\"$t\\\" != \\\"$s\\\" ] && [ \\\"$t\\\" != \\\"$b\\\" ] && [ -n \\\"$4\\\" ] && mkdir -p -m 700 -- \\\"$4\\\" 2>/dev/null; then c=$(dev \\\"$4\\\"); fi\",\n \"printf '%s\\\\n' \\\"$t\\\" \\\"$s\\\" \\\"$b\\\" \\\"$c\\\"\"\n].join(\"; \")\n\n/**\n * The host user's cache directory for checkout stages: `$XDG_CACHE_HOME`, or\n * `~/.cache`, under `smithers`. Empty when neither is an absolute path.\n */\nconst cacheRoot = (): string => {\n const env = globalThis.process?.env\n const xdg = env?.XDG_CACHE_HOME?.replace(/\\/+$/, \"\")\n if (xdg !== undefined && xdg.startsWith(\"/\")) return `${xdg}/smithers`\n const home = env?.HOME?.replace(/\\/+$/, \"\")\n return home !== undefined && home.startsWith(\"/\") ? `${home}/.cache/smithers` : \"\"\n}\n\n/**\n * Moves the staged checkout `$1` into the directory `$2` under the name `$3`\n * in one `rename`, then proves the directory there is the one that was staged.\n * The staging directory is on the same filesystem, so `mv` renames and never\n * copies.\n *\n * The shell first enters `$2` by its physical path and refuses unless that\n * lies under the real path of the workspace root `$4`. The rename then names\n * the target relative to that directory, so a parent the agent swaps for a\n * symlink, before or after the check, cannot carry the checkout out of the\n * workspace.\n */\nconst publish = [\n \"set -e\",\n \"root=$(cd -P -- \\\"$4\\\" && pwd -P)\",\n \"cd -P -- \\\"$2\\\"\",\n \"here=$(pwd -P)\",\n \"case \\\"$here\\\" in \\\"$root\\\"|\\\"$root\\\"/*) ;; *) echo \\\"$2 resolves to $here, outside the workspace $root\\\" >&2; exit 1 ;; esac\",\n \"if [ -e \\\"./$3\\\" ] || [ -L \\\"./$3\\\" ]; then echo \\\"$2/$3 already exists\\\" >&2; exit 1; fi\",\n \"staged=$(ls -di -- \\\"$1\\\" | awk '{print $1}')\",\n \"mv -- \\\"$1\\\" \\\"./$3\\\"\",\n \"if [ -L \\\"./$3\\\" ] || [ ! -d \\\"./$3\\\" ]; then echo \\\"$2/$3 was replaced while it was written\\\" >&2; exit 1; fi\",\n \"moved=$(ls -di -- \\\"./$3\\\" | awk '{print $1}')\",\n \"if [ \\\"$staged\\\" != \\\"$moved\\\" ]; then echo \\\"$2/$3 was replaced while it was written\\\" >&2; exit 1; fi\"\n].join(\"; \")\n\n/**\n * Checks `commit`'s tree out at the new directory `host`, with a standalone\n * `.git` the container's git can use.\n *\n * Host git never writes into an agent-writable directory. The tree and its\n * `.git` are written into a staging directory the agent cannot reach: inside\n * the shadow, or, when the host's temporary directory is another filesystem,\n * beside the workspace root or under the host user's cache directory. One\n * `rename` then gives the finished directory its name under the workspace. A\n * path the agent swaps for a symlink cannot redirect a write: a symlink at\n * `host` fails the call before the rename, and a parent that resolves outside\n * the workspace root fails it before the rename too.\n */\nconst checkout = (shadow: Shadow, host: string, commit: string) =>\n Effect.gen(function*() {\n const repository = shadow.repository\n const parent = host.slice(0, host.lastIndexOf(\"/\"))\n const name = host.slice(host.lastIndexOf(\"/\") + 1)\n const beside = repository.root.slice(0, repository.root.lastIndexOf(\"/\")) || \"/\"\n const cache = cacheRoot()\n const stage = `checkout-${globalThis.crypto.randomUUID()}`\n const besideStage = `${beside.replace(/\\/+$/, \"\")}/.smithers-${stage}`\n const cacheStage = `${cache}/${stage}`\n const measured = yield* run(\"sh\", [\"-c\", measure, \"sh\", parent, shadow.path, beside, cache])\n yield* succeeded(measured, `Could not check out ${commit}`)\n const [target, inShadow, besideRoot, inCache] = measured.stdout.split(\"\\n\").map((line) => line.trim())\n const scratch = target === undefined || target === \"\" || target === inShadow\n ? undefined\n : target === besideRoot\n ? besideStage\n : target === inCache\n ? cacheStage\n : undefined\n const base = target === undefined || target === \"\"\n ? undefined\n : target === inShadow\n ? shadow.path\n : scratch\n if (base === undefined) {\n const unwritable = besideRoot === \"unwritable\" ? \" (not writable by this user)\" : \"\"\n return yield* Effect.fail(\n failed(\n `Could not check out ${commit}: neither ${shadow.path} nor ${beside}${unwritable} nor ${\n cache === \"\" ? \"a cache directory\" : cache\n } is on the filesystem of ${parent}`\n )\n )\n }\n const staged = `${base}/${name}`\n const objects = relative(\n `${repository.toplevel}${host.slice(repository.root.length)}/.git/objects`,\n `${repository.common}/objects`\n )\n const write = Effect.gen(function*() {\n const prepared = yield* run(\"sh\", [\n \"-c\",\n [\n \"set -eC\",\n ...(scratch !== undefined ? [\"mkdir -m 700 -- \\\"$1\\\"\"] : []),\n \"mkdir -- \\\"$2\\\" \\\"$2/.git\\\" \\\"$2/.git/objects\\\" \\\"$2/.git/objects/info\\\" \\\"$2/.git/refs\\\"\",\n \"printf '%s\\\\n' \\\"$3\\\" > \\\"$2/.git/HEAD\\\"\",\n \"printf '%s\\\\n' \\\"$4\\\" > \\\"$2/.git/objects/info/alternates\\\"\",\n \"printf '%s' \\\"$5\\\" > \\\"$2/.git/config\\\"\"\n ].join(\"; \"),\n \"sh\",\n base,\n staged,\n commit,\n objects,\n checkoutConfig(repository)\n ])\n yield* succeeded(prepared, `Could not check out ${commit}`)\n const written = yield* shadow.git([\"read-tree\", \"--reset\", \"-u\", commit], staged)\n yield* succeeded(written, `Could not check out ${commit}`)\n const indexed = yield* run(\"sh\", [\n \"-c\",\n \"set -C; cat -- \\\"$1\\\" > \\\"$2\\\"\",\n \"sh\",\n `${shadow.path}/index`,\n `${staged}/.git/index`\n ])\n yield* succeeded(indexed, `Could not check out ${commit}`)\n const moved = yield* run(\"sh\", [\"-c\", publish, \"sh\", staged, parent, name, repository.root])\n yield* succeeded(moved, `Could not check out ${commit}`)\n })\n return yield* scratch !== undefined\n ? write.pipe(Effect.ensuring(remove(scratch).pipe(Effect.ignore)))\n : write\n })\n\nconst withDetachedWorktree = <A, E, R>(\n root: string,\n prefix: string,\n commit: string,\n use: (host: string) => Effect.Effect<A, E, R>\n): Effect.Effect<A, E | StdError.StdError, R | ChildProcessSpawner> =>\n Effect.gen(function*() {\n // Allocate on execution, including when the same Effect is run twice.\n // Never remove an existing checkout: another call may still be using it.\n const host = `${root.replace(/\\/+$/, \"\")}/${prefix}-${globalThis.crypto.randomUUID()}`\n return yield* Effect.acquireUseRelease(\n Effect.succeed(host),\n () =>\n Effect.gen(function*() {\n yield* withShadow(root, (shadow) => checkout(shadow, host, commit))\n return yield* use(host)\n }),\n // A checkout left behind is a stale copy of the repository inside the\n // workspace. Walks prune it, but the operator must still hear about it.\n () =>\n remove(host).pipe(\n Effect.catch((error) =>\n Effect.logWarning(\"could not remove a scratch checkout\").pipe(\n Effect.annotateLogs({ path: host, reason: error.message })\n )\n )\n )\n )\n })\n\n/**\n * Internal Git operations used by both checkpoint and baseline leases.\n *\n * @category utilities\n * @since 1.0.0\n */\nexport const GitWorktree = { config, git, open, resolveCommit, withDetachedWorktree, withShadow }\n"]}
@@ -46,14 +46,14 @@ import * as Read from "@smthrs/std/Read"
46
46
  import * as Schema from "effect/Schema"
47
47
 
48
48
  /** A step that reads a file. It declares what `read` declares. */
49
- export const ReadTarget = ({
49
+ export const ReadTarget = {
50
50
  name: "read-target",
51
51
  input: Schema.Struct({ path: Schema.String }),
52
52
  output: Read.Output,
53
53
  capabilities: Read.capabilities,
54
54
  effects: Read.effects,
55
55
  flows: [Read.flow]
56
- })
56
+ }
57
57
  ```
58
58
 
59
59
  A planner reading `ReadTarget` can see that the step reads and does not write,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@smthrs/std",
3
3
  "type": "module",
4
- "version": "1.0.0-rc.3",
4
+ "version": "1.0.0-rc.4",
5
5
  "license": "MIT",
6
6
  "smthrs": {
7
7
  "group": "agent"
@@ -401,11 +401,11 @@
401
401
  "tag": "next"
402
402
  },
403
403
  "dependencies": {
404
- "@smthrs/capability": "1.0.0-rc.3",
405
- "@smthrs/control": "1.0.0-rc.3",
406
- "@smthrs/core": "1.0.0-rc.3",
407
- "@smthrs/kernel": "1.0.0-rc.3",
408
- "@smthrs/model": "1.0.0-rc.3"
404
+ "@smthrs/capability": "1.0.0-rc.4",
405
+ "@smthrs/control": "1.0.0-rc.4",
406
+ "@smthrs/core": "1.0.0-rc.4",
407
+ "@smthrs/kernel": "1.0.0-rc.4",
408
+ "@smthrs/model": "1.0.0-rc.4"
409
409
  },
410
410
  "devDependencies": {
411
411
  "@effect/language-service": "0.87.2",
package/src/Bash.ts CHANGED
@@ -369,6 +369,18 @@ const plan = (input: Input): Plan | StdError.StdError => {
369
369
  }
370
370
  }
371
371
 
372
+ /**
373
+ * The plan, refused when its input names no one invocation or when a hermetic
374
+ * call's paths fall outside its declared envelope. Spawned and terminal
375
+ * execution share this one check.
376
+ */
377
+ const precheck = (input: Input, path: Path.Path): Plan | StdError.StdError => {
378
+ const intent = plan(input)
379
+ if (intent instanceof StdError.StdError || input.mode !== "hermetic") return intent
380
+ // A planned call carries exactly one of command or script.
381
+ return outsideEnvelope(input, input.command ?? input.script!, path) ?? intent
382
+ }
383
+
372
384
  /** The plan as the host will spawn it, once the container transport has had it. */
373
385
  const routed = (
374
386
  plan: Plan,
@@ -378,7 +390,7 @@ const routed = (
378
390
  if (input.container === undefined) return Effect.succeed(plan)
379
391
  if (Option.isNone(transport)) return Effect.fail(Container.unavailable(input.container))
380
392
  return Effect.map(
381
- transport.value.exec(request(plan, input)),
393
+ transport.value.exec(request(plan, input, input.container)),
382
394
  (routing): Plan => ({
383
395
  file: routing.file,
384
396
  args: routing.args,
@@ -411,8 +423,8 @@ const routed = (
411
423
  * still arrives on the inherited standard input and no argument is ever
412
424
  * re-parsed as shell text.
413
425
  */
414
- const request = (plan: Plan, input: Input): Container.Request => ({
415
- container: input.container ?? "",
426
+ const request = (plan: Plan, input: Input, container: string): Container.Request => ({
427
+ container,
416
428
  file: "bash",
417
429
  args: plan.args === undefined
418
430
  ? ["-lc", plan.file]
@@ -472,13 +484,8 @@ const fingerprint = (
472
484
  export const run = Effect.fn("Bash.run")(function*(
473
485
  input: Input
474
486
  ): Effect.fn.Return<Output, StdError.StdError, ChildProcessSpawner.ChildProcessSpawner | Path.Path> {
475
- const path = yield* Path.Path
476
- const intent = plan(input)
487
+ const intent = precheck(input, yield* Path.Path)
477
488
  if (intent instanceof StdError.StdError) return yield* Effect.fail(intent)
478
- if (input.mode === "hermetic") {
479
- const violation = outsideEnvelope(input, input.command ?? input.script ?? "", path)
480
- if (violation !== undefined) return yield* Effect.fail(violation)
481
- }
482
489
  // The working directory belongs to the container. The transport supplies
483
490
  // any environment overrides its host process needs to forward into it.
484
491
  const contained = input.container !== undefined
@@ -516,6 +523,57 @@ export const run = Effect.fn("Bash.run")(function*(
516
523
  }
517
524
  })
518
525
 
526
+ /**
527
+ * What one call runs, after planning and before any transport: the program,
528
+ * its arguments (absent for a shell command line), standard input, the
529
+ * caller's environment, and the logical invocation as a person reads it.
530
+ *
531
+ * @category models
532
+ * @since 1.0.0
533
+ */
534
+ export interface Invocation {
535
+ readonly file: string
536
+ readonly args: ReadonlyArray<string> | undefined
537
+ readonly stdin: string | undefined
538
+ readonly env: Record<string, string> | undefined
539
+ readonly quoted: string
540
+ }
541
+
542
+ /**
543
+ * The invocation `input` names, or the typed refusal explaining why it names
544
+ * none. The same plan {@link run} spawns; a terminal provider runs it instead.
545
+ *
546
+ * @category constructors
547
+ * @since 1.0.0
548
+ */
549
+ export const invocation = (input: Input): Invocation | StdError.StdError => plan(input)
550
+
551
+ /**
552
+ * {@link run}'s contract through a registered terminal (T-TRM-05): the same
553
+ * plan, hermetic pre-check, bounded output and diagnostics refresh, with
554
+ * execution supplied by `execute` instead of a spawn on this host. A terminal
555
+ * has no container transport, so a containerised call is refused before it
556
+ * reaches `execute`.
557
+ *
558
+ * @category handlers
559
+ * @since 1.0.0
560
+ */
561
+ export const inTerminal = <R>(
562
+ execute: (input: Input) => Effect.Effect<Output, StdError.StdError, R>
563
+ ) =>
564
+ Effect.fn("Bash.inTerminal")(function*(
565
+ input: Input
566
+ ): Effect.fn.Return<Output, StdError.StdError, R | Path.Path> {
567
+ const intent = precheck(input, yield* Path.Path)
568
+ if (intent instanceof StdError.StdError) return yield* Effect.fail(intent)
569
+ if (input.container !== undefined) return yield* Effect.fail(Container.unavailable(input.container))
570
+ const output = yield* execute(input)
571
+ // The terminal ran on this workspace: files a language server holds may
572
+ // have changed, exactly as after a spawn here.
573
+ yield* Diagnostics.refresh
574
+ return output
575
+ })
576
+
519
577
  /**
520
578
  * The refusal a sealed host answers a call outside its container with.
521
579
  *
@@ -179,10 +179,28 @@ export interface Shadow {
179
179
  args: ReadonlyArray<string>,
180
180
  workTree?: string
181
181
  ) => Effect.Effect<Exec.ExecResult, StdError.StdError, ChildProcessSpawner>
182
- /** Copies the workspace index into the shadow, so the shadow never writes the agent's own. */
182
+ /**
183
+ * Copies the workspace index into the shadow, with its modification time, so
184
+ * the shadow never writes the agent's own.
185
+ *
186
+ * The time is part of what git reads. It trusts an entry's recorded stat
187
+ * unless the entry is at least as new as the index file, in whole seconds;
188
+ * a copy stamped at the moment of copying made every entry look older, and a
189
+ * same-size edit from the second the index was written was recorded as the
190
+ * committed bytes (#3431). The time is taken before the bytes are read, so
191
+ * an index rewritten meanwhile leaves the copy looking older, never newer.
192
+ */
183
193
  readonly adoptIndex: Effect.Effect<void, StdError.StdError, ChildProcessSpawner>
184
194
  }
185
195
 
196
+ /** The `adoptIndex` script: `$1` is the workspace index, `$2` the shadow's. */
197
+ const adoptIndexScript = [
198
+ "set -C",
199
+ "if [ -e \"$1\" ]",
200
+ "then : > \"$2.at\" && touch -r \"$1\" -- \"$2.at\" && cat -- \"$1\" > \"$2\" && touch -r \"$2.at\" -- \"$2\" && rm -f -- \"$2.at\"",
201
+ "fi"
202
+ ].join("; ")
203
+
186
204
  const shadowOf = (repository: Repository, path: string): Shadow => ({
187
205
  path,
188
206
  repository,
@@ -200,7 +218,7 @@ const shadowOf = (repository: Repository, path: string): Shadow => ({
200
218
  ),
201
219
  adoptIndex: run("sh", [
202
220
  "-c",
203
- "set -C; if [ -e \"$1\" ]; then cat -- \"$1\" > \"$2\"; fi",
221
+ adoptIndexScript,
204
222
  "sh",
205
223
  repository.index,
206
224
  `${path}/index`