tenjin-cli 0.1.0-alpha.18 → 0.1.0-alpha.19
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 +151 -40
- package/dist/{_esm-CE7KNONL.js → _esm-OVVGTKHH.js} +4 -4
- package/dist/{chunk-WUHY2AXD.js → chunk-2SQEFBAM.js} +4 -3
- package/dist/{chunk-FGR734LZ.js → chunk-3VYGDRRL.js} +5 -5
- package/dist/{chunk-PDA2BVFY.js → chunk-5DOHKQ24.js} +4 -15
- package/dist/chunk-5DOHKQ24.js.map +1 -0
- package/dist/{chunk-N35E6CM2.js → chunk-6DCELMQA.js} +6 -6
- package/dist/{chunk-WXC57XGG.js → chunk-A36LQPHV.js} +1 -1
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/{chunk-BTX2QE2Y.js → chunk-A6CY6BUW.js} +3 -3
- package/dist/{chunk-TP4D47BY.js → chunk-AISBL7EY.js} +3 -3
- package/dist/{chunk-ON6C6WOX.js → chunk-AMG4SONW.js} +138 -58
- package/dist/chunk-AMG4SONW.js.map +1 -0
- package/dist/{chunk-AUKDYPPX.js → chunk-BG2EXNAA.js} +7 -6
- package/dist/chunk-BG2EXNAA.js.map +1 -0
- package/dist/{chunk-F3FUGWPZ.js → chunk-FHBGTOFA.js} +121 -40
- package/dist/chunk-FHBGTOFA.js.map +1 -0
- package/dist/{chunk-HPWO4O6S.js → chunk-FPUPBQHX.js} +2 -2
- package/dist/{chunk-3AUDA53C.js → chunk-KTAW4KGH.js} +6 -5
- package/dist/{chunk-J5INH7WB.js → chunk-LSWVVSFX.js} +106 -5
- package/dist/chunk-LSWVVSFX.js.map +1 -0
- package/dist/chunk-O2JYBOUO.js +47 -0
- package/dist/chunk-O2JYBOUO.js.map +1 -0
- package/dist/{chunk-NRQMOVKM.js → chunk-PZQRSZJV.js} +2 -2
- package/dist/{chunk-NRQMOVKM.js.map → chunk-PZQRSZJV.js.map} +1 -1
- package/dist/{chunk-N44H5TFB.js → chunk-SCAOYGKX.js} +315 -71
- package/dist/chunk-SCAOYGKX.js.map +1 -0
- package/dist/{chunk-35M3VITA.js → chunk-TDGN476R.js} +60 -7
- package/dist/chunk-TDGN476R.js.map +1 -0
- package/dist/{chunk-AR7U7BRG.js → chunk-UNV4K45L.js} +12 -18
- package/dist/{chunk-AR7U7BRG.js.map → chunk-UNV4K45L.js.map} +1 -1
- package/dist/{chunk-ZG7SFI34.js → chunk-VFVFVQM6.js} +4 -4
- package/dist/{chunk-EPCOMXLF.js → chunk-WUU3BH6G.js} +2 -2
- package/dist/{chunk-KUBEYXSO.js → chunk-XDADPAWW.js} +22 -22
- package/dist/{chunk-YPQSMIDH.js → chunk-XNP6VUAJ.js} +3 -3
- package/dist/{chunk-AWQPGIR6.js → chunk-Y66XUXVI.js} +5 -5
- package/dist/{chunk-TJMCBIZU.js → chunk-ZDKEU2GF.js} +2 -2
- package/dist/{chunk-WLMJE3GJ.js → chunk-ZTFIQC4C.js} +2 -2
- package/dist/{cli-MP3RAYHL.js → cli-456F77ZY.js} +33 -28
- package/dist/{cli-MP3RAYHL.js.map → cli-456F77ZY.js.map} +1 -1
- package/dist/{config-BJK6U5VY.js → config-BLUWOH6S.js} +9 -12
- package/dist/{doctor-KJROWE5V.js → doctor-PS45CR3T.js} +37 -29
- package/dist/{doctor-KJROWE5V.js.map → doctor-PS45CR3T.js.map} +1 -1
- package/dist/{fund-I5COXPEJ.js → fund-4SW2ZBWC.js} +17 -17
- package/dist/{hook-command-EJO2564A.js → hook-command-YTV7X333.js} +247 -24
- package/dist/hook-command-YTV7X333.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/{install-NUQLLHS2.js → install-U4BIDCHH.js} +14 -13
- package/dist/{install-wallet-JPFTEC6H.js → install-wallet-EYHELQMG.js} +14 -14
- package/dist/{mcp-I5XMVE64.js → mcp-AC4PIXH5.js} +30 -26
- package/dist/{mcp-I5XMVE64.js.map → mcp-AC4PIXH5.js.map} +1 -1
- package/dist/{pay-WA3JSCNB.js → pay-VJOP6TFT.js} +19 -19
- package/dist/{send-KVUH5WDO.js → send-YH75Z6LB.js} +14 -14
- package/dist/{status-FFC6FO72.js → status-5CHCDLUE.js} +24 -17
- package/dist/status-5CHCDLUE.js.map +1 -0
- package/dist/{status-line-SAXSU6CR.js → status-line-CZAZUOAY.js} +6 -6
- package/dist/{status-line-wiring-DQZCWIUO.js → status-line-wiring-2ABDVXSJ.js} +4 -4
- package/dist/tenjin-daemon.mjs +3 -14
- package/dist/{uninstall-SWICHBTF.js → uninstall-BYVGAQMO.js} +13 -15
- package/dist/{uninstall-SWICHBTF.js.map → uninstall-BYVGAQMO.js.map} +1 -1
- package/dist/{update-W572AMXG.js → update-7QJDSHST.js} +5 -5
- package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-N2GIVMZ7.js} +2 -2
- package/dist/{wallet-L2YLAJFN.js → wallet-YZOXIXBC.js} +14 -14
- package/docs/agent-permissions.md +29 -13
- package/docs/safety-model.md +7 -1
- package/package.json +1 -1
- package/dist/chunk-35M3VITA.js.map +0 -1
- package/dist/chunk-AUKDYPPX.js.map +0 -1
- package/dist/chunk-F3FUGWPZ.js.map +0 -1
- package/dist/chunk-J5INH7WB.js.map +0 -1
- package/dist/chunk-N44H5TFB.js.map +0 -1
- package/dist/chunk-ON6C6WOX.js.map +0 -1
- package/dist/chunk-PDA2BVFY.js.map +0 -1
- package/dist/chunk-U2DZISAH.js +0 -111
- package/dist/chunk-U2DZISAH.js.map +0 -1
- package/dist/chunk-WS4JA6TC.js +0 -137
- package/dist/chunk-WS4JA6TC.js.map +0 -1
- package/dist/chunk-WXC57XGG.js.map +0 -1
- package/dist/hook-command-EJO2564A.js.map +0 -1
- package/dist/skill-placement-JMDPSKE6.js +0 -299
- package/dist/skill-placement-JMDPSKE6.js.map +0 -1
- package/dist/status-FFC6FO72.js.map +0 -1
- /package/dist/{_esm-CE7KNONL.js.map → _esm-OVVGTKHH.js.map} +0 -0
- /package/dist/{chunk-WUHY2AXD.js.map → chunk-2SQEFBAM.js.map} +0 -0
- /package/dist/{chunk-FGR734LZ.js.map → chunk-3VYGDRRL.js.map} +0 -0
- /package/dist/{chunk-N35E6CM2.js.map → chunk-6DCELMQA.js.map} +0 -0
- /package/dist/{chunk-BTX2QE2Y.js.map → chunk-A6CY6BUW.js.map} +0 -0
- /package/dist/{chunk-TP4D47BY.js.map → chunk-AISBL7EY.js.map} +0 -0
- /package/dist/{chunk-HPWO4O6S.js.map → chunk-FPUPBQHX.js.map} +0 -0
- /package/dist/{chunk-3AUDA53C.js.map → chunk-KTAW4KGH.js.map} +0 -0
- /package/dist/{chunk-ZG7SFI34.js.map → chunk-VFVFVQM6.js.map} +0 -0
- /package/dist/{chunk-EPCOMXLF.js.map → chunk-WUU3BH6G.js.map} +0 -0
- /package/dist/{chunk-KUBEYXSO.js.map → chunk-XDADPAWW.js.map} +0 -0
- /package/dist/{chunk-YPQSMIDH.js.map → chunk-XNP6VUAJ.js.map} +0 -0
- /package/dist/{chunk-AWQPGIR6.js.map → chunk-Y66XUXVI.js.map} +0 -0
- /package/dist/{chunk-TJMCBIZU.js.map → chunk-ZDKEU2GF.js.map} +0 -0
- /package/dist/{chunk-WLMJE3GJ.js.map → chunk-ZTFIQC4C.js.map} +0 -0
- /package/dist/{config-BJK6U5VY.js.map → config-BLUWOH6S.js.map} +0 -0
- /package/dist/{fund-I5COXPEJ.js.map → fund-4SW2ZBWC.js.map} +0 -0
- /package/dist/{install-NUQLLHS2.js.map → install-U4BIDCHH.js.map} +0 -0
- /package/dist/{install-wallet-JPFTEC6H.js.map → install-wallet-EYHELQMG.js.map} +0 -0
- /package/dist/{pay-WA3JSCNB.js.map → pay-VJOP6TFT.js.map} +0 -0
- /package/dist/{send-KVUH5WDO.js.map → send-YH75Z6LB.js.map} +0 -0
- /package/dist/{status-line-SAXSU6CR.js.map → status-line-CZAZUOAY.js.map} +0 -0
- /package/dist/{status-line-wiring-DQZCWIUO.js.map → status-line-wiring-2ABDVXSJ.js.map} +0 -0
- /package/dist/{update-W572AMXG.js.map → update-7QJDSHST.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → viemAdapter-By13KInL-N2GIVMZ7.js.map} +0 -0
- /package/dist/{wallet-L2YLAJFN.js.map → wallet-YZOXIXBC.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/skill-placement.ts","../src/lib/skill-materialize.ts","../src/lib/skill-writer.ts"],"sourcesContent":["import { lstatSync } from 'node:fs';\nimport { readdir, rm, rmdir } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { isAbsolute, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { emitWriteNotice } from './output';\nimport type { Io } from './output';\nimport { loadRawConfig } from './config';\nimport { isTeamModeConfig } from './settings';\nimport { skillMaterialize } from './skill-materialize';\nimport { readSkillFile, skillFrontmatterName, skillsDirsFor } from './skill-wiring';\nimport { installSkill } from './skill-writer';\nimport { OPTIONAL_PAY_SKILL, SKILL_NAMES, resolveSkillsSource } from './skills-source';\n\n/**\n * Optional skills, where PRESENCE is the whole mechanism: the tenjin-pay skill\n * is on disk exactly while the `bazaarPay` toggle is on, so an agent is never\n * taught a lane the operator turned off, and turning the lane on is what makes\n * the teaching appear. No conditional content, no markers: the unit of\n * consent stays the one the whole pipeline already has, a skill directory.\n *\n * Its CONTENT still goes through the same shaping every other skill's does\n * (lib/skill-materialize): presence and content are different questions, and the\n * placer is one of the writers that has to materialize for the comparers to keep\n * agreeing. tenjin-pay ships no marker today, so it is a no-op there — but a\n * placer that skipped shaping would be the one writer whose `up-to-date` meant\n * something different from everyone else's.\n *\n * Removal follows `uninstall`'s rules exactly (lib/uninstall removeSkills):\n * only a SKILL.md whose frontmatter still claims our name is ours to delete,\n * and the directory goes only when our file was the only thing in it, so an\n * operator's own files beside it survive a toggle-off.\n */\n\n/** Ensure `name` is present or absent under one skills directory. */\nexport async function placeOptionalSkill(\n name: string,\n skillsDir: string,\n skillsSource: string,\n present: boolean,\n teamMode: boolean,\n): Promise<{ changed: boolean }> {\n const skillDir = join(skillsDir, name);\n if (present) {\n const { status } = await installSkill(join(skillsSource, name), skillDir, false, name, {\n materialize: skillMaterialize({ teamMode }),\n });\n return { changed: status !== 'up-to-date' };\n }\n if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) {\n return { changed: false };\n }\n const path = join(skillDir, 'SKILL.md');\n const read = await readSkillFile(path);\n if (read.kind === 'absent') return { changed: false };\n if (read.kind !== 'ok' || skillFrontmatterName(read.bytes.toString('utf8')) !== name) {\n return { changed: false }; // not ours to delete for sitting at our path\n }\n await rm(path, { force: true });\n const rest = await readdir(skillDir).catch(() => null);\n if (rest !== null && rest.length === 0) await rmdir(skillDir).catch(() => undefined);\n return { changed: true };\n}\n\n/**\n * The `config set bazaarPay` twin of the heal: converge the tenjin-pay skill's\n * presence with the toggle across every skills directory a tenjin skill is\n * already wired into (presence of any shipped skill is the operator's consent\n * to a directory; an unwired directory is never created). Operator act, so\n * failures degrade per directory and doctor reports what remains.\n */\nexport async function syncBazaarSkill(\n enabled: boolean,\n deps: {\n io: Io;\n homeDir?: string;\n skillsSourceDir?: string;\n /** Where `config.json` lives, for the team-mode fact the content is shaped by.\n * Absent means public, for a caller with no data dir to read. */\n dataDir?: string;\n },\n): Promise<void> {\n const home = deps.homeDir ?? homedir();\n if (!isAbsolute(home)) return;\n // Same fail-safe as the heal's: an unreadable config throws out of here rather\n // than being guessed as public, which on a team machine would write the other\n // mode's text. The caller is already best-effort after a successful persist.\n const teamMode =\n deps.dataDir === undefined ? false : isTeamModeConfig(await loadRawConfig(deps.dataDir));\n let source: string;\n try {\n source =\n deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL('.', import.meta.url)));\n } catch {\n return; // no readable source: nothing safe to write, nothing to remove FROM\n }\n const touched: string[] = [];\n for (const dir of skillsDirsFor(home)) {\n try {\n if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;\n const consented = SKILL_NAMES.some(\n (name) =>\n lstatSync(join(dir, name, 'SKILL.md'), { throwIfNoEntry: false })?.isFile() === true,\n );\n if (!consented) continue;\n const { changed } = await placeOptionalSkill(\n OPTIONAL_PAY_SKILL,\n dir,\n source,\n enabled,\n teamMode,\n );\n if (changed) touched.push(join(dir, OPTIONAL_PAY_SKILL));\n } catch {\n // This directory keeps what it has; `tenjin doctor` reports the drift.\n }\n }\n if (touched.length > 0) {\n emitWriteNotice(\n deps.io,\n `${enabled ? 'Installed' : 'Removed'} ${touched.join(' and ')} to match bazaarPay.`,\n );\n }\n}\n","import { CliError } from './errors';\n\n/**\n * Config-conditional blocks in packaged skill markdown. A skill source may wrap a\n * region in full-line HTML-comment markers:\n *\n * <!-- tenjin:when teamMode -->\n * ...lines an agent should only see when the flag is on...\n * <!-- tenjin:else -->\n * ...lines an agent should only see when it is off...\n * <!-- /tenjin:when -->\n *\n * Materializing resolves those regions against a flag set and the marker lines\n * themselves never survive, so an installed SKILL.md carries no machinery for an\n * agent to read. The `else` arm is what makes this a REPLACEMENT seam rather than\n * an additive one, and it is the whole reason it exists: the two arms are\n * structurally exclusive, so exactly one of them can ever reach a reader. Guidance\n * that DIFFERS by machine fact is written as one when/else pair replacing one\n * region, never as a base paragraph plus a \"however, on a team shelf...\" rider —\n * a reader in either mode would then see both, and two rules for the same decision\n * in one file is worse than either rule alone. A bare `when` with no `else` stays\n * legal for content that is genuinely additive.\n *\n * Unknown flags are OFF because every flag this CLI defines defaults off; a marker\n * for a flag this build does not know is a newer source's block, and advertising a\n * lane this build cannot gate is the unsafe direction. That default is safe for a\n * bare `when` and merely wrong-way-round for a when/else, so a typo in a flag NAME\n * cannot be caught here: `skill-writer.test.ts` pins every marker in every shipped\n * skill against {@link SKILL_CONTENT_FLAG_NAMES} instead, which is where a\n * misspelling has to fail.\n *\n * Every writer and every comparer resolves flags through {@link skillContentFlags}\n * so there is one mapping from machine facts to marker flags. `install`, the\n * post-command self-heal, the optional-skill placer and `doctor`'s staleness\n * compare all materialize; `scripts/pack-smoke.sh` cannot run this code against\n * the packed tarball, so it asserts the rendered PROPERTIES (marker-free, and no\n * sentence from the other mode) rather than raw bytes. Those five agree only while\n * that stays true: teaching four of five is how a shaped skill and a raw\n * comparison end up disagreeing forever.\n *\n * The grammar is deliberately line-based and flat (no nesting): the parse below\n * fails closed on anything else, because a half-stripped skill silently teaching\n * the wrong verb set is worse than a refused install.\n */\nconst OPEN_MARKER = /^\\s*<!--\\s*tenjin:when\\s+([a-zA-Z][a-zA-Z0-9.]*)\\s*-->\\s*$/;\nconst CLOSE_MARKER = /^\\s*<!--\\s*\\/tenjin:when\\s*-->\\s*$/;\n/** The arm switch. Carries no flag name: there is exactly one flag in play, the\n * open marker's, and repeating it is a second place for it to be misspelled. */\nconst ELSE_MARKER = /^\\s*<!--\\s*tenjin:else\\s*-->\\s*$/;\n/**\n * A line reaching for the grammar and missing it: trailing content after an open\n * marker, a flag name on a close or an else, a mistyped delimiter. Without this\n * such a line survives as ordinary content and the parse fails much later at\n * whichever marker is left unbalanced, naming a line the author did not write\n * wrong.\n */\nconst NEAR_MARKER = /^\\s*<!--\\s*\\/?\\s*tenjin:(?:when|else)\\b/;\n\n/** Flag values keyed by flag name; absent keys read as false. */\nexport type SkillContentFlags = Readonly<Record<string, boolean>>;\n\n/**\n * Every flag name a shipped skill's markers may use. A closed set, and the reason\n * it can be one is that the runtime deliberately cannot police it: an unknown flag\n * resolves OFF, which for a when/else pair means silently rendering the OTHER\n * mode's guidance. So the check for a misspelled flag is a build-time one over the\n * packaged skills (`skill-writer.test.ts`), and this is the list it checks against.\n */\nexport const SKILL_CONTENT_FLAG_NAMES = ['teamMode'] as const;\n\n/**\n * THE mapping from machine facts to marker flags. Every writer and comparer goes\n * through this rather than building a record inline, so there is one answer to\n * \"what does this machine's skill text say\" and no call site can drift by omitting\n * a flag (an omitted flag is a silent OFF, which is a rendered mode, not an error).\n *\n * `teamMode` is the machine's CONFIGURED mode — a team shelf of the team's own\n * plus its door key, per `settings.isTeamModeConfig` — not this invocation's. A\n * `--base-url` cannot reach it, and it should not: the file being written outlives\n * the command that wrote it and is read by every later session on this machine.\n */\nexport function skillContentFlags(facts: { teamMode: boolean }): SkillContentFlags {\n return { teamMode: facts.teamMode };\n}\n\n/** The transform `installSkill` takes, for a machine in the given mode. */\nexport function skillMaterialize(facts: {\n teamMode: boolean;\n}): (rel: string, content: Buffer) => Buffer {\n return materializeTransform(skillContentFlags(facts));\n}\n\n/** One packaged skill file's text as this machine would read it. */\nexport function renderSkillMarkdown(text: string, facts: { teamMode: boolean }): string {\n return materializeSkillMarkdown(text, skillContentFlags(facts));\n}\n\nexport function materializeSkillMarkdown(text: string, flags: SkillContentFlags): string {\n const lines = text.split('\\n');\n const out: string[] = [];\n let inBlock: string | null = null;\n /** Does the arm currently being read survive? */\n let keep = false;\n /** Has this block's `else` been seen? A second one is malformed, not a no-op. */\n let elsed = false;\n for (const [i, line] of lines.entries()) {\n const open = OPEN_MARKER.exec(line);\n if (open !== null) {\n if (inBlock !== null) {\n throw markerError(`nested tenjin:when at line ${i + 1} (already inside \"${inBlock}\")`);\n }\n inBlock = open[1]!;\n keep = flags[inBlock] === true;\n elsed = false;\n continue;\n }\n if (ELSE_MARKER.test(line)) {\n if (inBlock === null) throw markerError(`unopened tenjin:else at line ${i + 1}`);\n // Two elses would make the third arm's fate depend on parity, and the author\n // who typed it meant one of them to be a close.\n if (elsed) throw markerError(`second tenjin:else at line ${i + 1} in \"${inBlock}\"`);\n elsed = true;\n keep = !keep;\n continue;\n }\n if (CLOSE_MARKER.test(line)) {\n if (inBlock === null) throw markerError(`unopened /tenjin:when at line ${i + 1}`);\n inBlock = null;\n continue;\n }\n if (NEAR_MARKER.test(line)) {\n throw markerError(`malformed tenjin:when marker at line ${i + 1}: ${line.trim()}`);\n }\n if (inBlock === null || keep) out.push(line);\n }\n if (inBlock !== null) throw markerError(`unclosed tenjin:when \"${inBlock}\"`);\n return out.join('\\n');\n}\n\n/**\n * Every flag name the markers in `text` reference, in source order. Used by the\n * build-time pin over the packaged skills; see {@link SKILL_CONTENT_FLAG_NAMES}\n * for why that check cannot live in the parse.\n */\nexport function markerFlagsIn(text: string): string[] {\n return text\n .split('\\n')\n .map((line) => OPEN_MARKER.exec(line)?.[1])\n .filter((flag): flag is string => flag !== undefined);\n}\n\n/**\n * The transform `installSkill` takes for packaged source files. Only markdown is\n * text this grammar owns; any other file type a skill may ever ship passes through\n * byte-for-byte, so this can never corrupt a non-text asset.\n */\nexport function materializeTransform(\n flags: SkillContentFlags,\n): (rel: string, content: Buffer) => Buffer {\n return (rel, content) => {\n if (!rel.toLowerCase().endsWith('.md')) return content;\n return Buffer.from(materializeSkillMarkdown(content.toString('utf8'), flags), 'utf8');\n };\n}\n\nfunction markerError(detail: string): CliError {\n return new CliError('INTERNAL', `Malformed skill markers: ${detail}.`, {\n fix: 'Reinstall tenjin-cli; the packaged skills must carry balanced tenjin:when markers.',\n });\n}\n","import { existsSync } from 'node:fs';\nimport { lstat, readFile, readdir, realpath, stat } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { writeFileAtomic } from './atomic-json';\nimport { hasCode } from './errno';\nimport { CliError } from './errors';\nimport { PRODUCTION_HOST } from './production-origin';\nimport { HOSTED_SKILL_NAME, readSkillFile } from './skill-wiring';\n\n/**\n * Writing one packaged skill into one harness directory, and the path guards that\n * write needs. Its own module, free of the command layer's dependencies, because\n * `install` and the post-command self-heal both write skills and the heal runs on\n * every command: reaching into commands/install would parse the wallet's viem\n * chunk on a `tenjin config`.\n */\n\nexport type SkillInstallStatus =\n 'installed' | 'updated' | 'up-to-date' | 'would-install' | 'would-update';\n\nexport interface SkillInstallResult {\n status: SkillInstallStatus;\n warning?: string;\n /** Was a real copy (a SKILL.md, not just the directory) already on disk before this run? */\n preexisting: boolean;\n}\n\nexport interface SkillWriteOptions {\n /**\n * Write THROUGH a symlinked destination (default), or replace it. `install`\n * follows the link, because the operator pointed it somewhere on purpose. The\n * unattended self-heal does not, and passes false: it has already refused every\n * link it could see, and this closes the gap between that look and this write,\n * where a link appearing in between would otherwise be followed. `rename` never\n * follows its final component, so the worst a race can now do is leave our\n * regular file where the new link was.\n */\n followSymlinks?: boolean;\n /**\n * Shape a packaged file before it is compared and written (config-conditional\n * skill content; see lib/skill-materialize). Applied to the SOURCE side only,\n * before the on-disk compare, so \"up-to-date\" means \"matches what this config\n * state would write\" and a config change makes the same source differ again. A\n * transform that throws aborts the whole install of this skill: a half-shaped\n * skill must never be written.\n */\n materialize?: (rel: string, content: Buffer) => Buffer;\n}\n\nexport async function installSkill(\n srcDir: string,\n destDir: string,\n dryRun: boolean,\n name: string,\n opts: SkillWriteOptions = {},\n): Promise<SkillInstallResult> {\n const src = await readTree(srcDir);\n if (src === null) {\n // assertSkillsSource already guards SKILL.md; this is defensive for an empty dir.\n throw new CliError('INTERNAL', `Packaged skill source ${srcDir} is empty`);\n }\n if (opts.materialize !== undefined) {\n for (const [rel, content] of src) src.set(rel, opts.materialize(rel, content));\n }\n\n // Only the files this package SHIPS are read and written. Everything else in the\n // directory belongs to the operator: never inspected, listed, or removed. That is\n // what package managers do (npm, dpkg, Homebrew all own their files, not the\n // directory), and wholesale replacement was the single cause behind a run of\n // data-loss, symlink and enumeration bugs.\n //\n // Resolved on BOTH paths, dry run included, so a dry run cannot promise a write\n // the real run refuses.\n const writeTo = new Map<string, string>();\n await assertReachable(destDir, name);\n await assertNoCaseCollision(destDir, name);\n for (const rel of src.keys()) {\n const declared = join(destDir, rel);\n writeTo.set(\n rel,\n opts.followSymlinks === false ? declared : await resolveThroughLink(declared, name),\n );\n }\n\n let differs = false;\n let preexisting = false;\n for (const [rel, content] of src) {\n const current = await readShippedFile(writeTo.get(rel)!, name, destDir);\n if (rel === 'SKILL.md') preexisting = current !== null;\n if (current === null || !current.equals(content)) differs = true;\n }\n const change = !preexisting ? 'create' : differs ? 'update' : 'none';\n\n if (!dryRun && change !== 'none') {\n for (const [rel, content] of src) {\n const target = writeTo.get(rel)!;\n try {\n // An existing file keeps the mode it has. A skill an operator (or their\n // dotfiles) made group-readable or read-only is theirs to have set that\n // way, and an update is no reason to hand it back at the default 0644.\n const current = await stat(target).catch(() => null);\n await writeFileAtomic(\n target,\n content,\n current === null ? {} : { mode: current.mode & 0o777 },\n );\n } catch (err) {\n // Culprit is derived from the file that FAILED, not assumed to be the\n // skills root: an existing skill directory that refuses the temp file is\n // itself the thing to chmod, and a symlinked SKILL.md fails in the link's\n // TARGET directory, which no path under destDir names.\n throw wrapWriteError(\n err,\n destDir,\n `the ${name} skill`,\n await deepestExisting(dirname(target)),\n { expected: ': a skill is a directory holding SKILL.md' },\n );\n }\n }\n }\n\n if (change === 'create') return { status: dryRun ? 'would-install' : 'installed', preexisting };\n if (change === 'none') return { status: 'up-to-date', preexisting };\n return {\n status: dryRun ? 'would-update' : 'updated',\n preexisting,\n // The hosted skill is a MIRROR of tenjin.blog/skills.md (roadmap G4), so a\n // differing local copy is a replacement, not the drift warning the CLI skills\n // get. Neither side carries a version or date, so the wording claims no\n // direction: the local file may well be a newer fetch than this package's copy.\n warning:\n name === HOSTED_SKILL_NAME\n ? `${destDir}: the hosted Tenjin skill differed and ${dryRun ? 'would be' : 'was'} replaced by this package's mirror of ${PRODUCTION_HOST}/skills.md, which may be older; it stays as the zero-install fallback. Re-fetch it from ${PRODUCTION_HOST}/skills.md if you need the current one.`\n : `${destDir}: local edits to ${name}'s SKILL.md ${dryRun ? 'would be' : 'were'} overwritten (the packaged copy is canonical).`,\n };\n}\n\n/**\n * Read a shipped file, or null when it is not there.\n *\n * The node-type guard lives in `readSkillFile`, shared with the wiring check and\n * the staleness check, because all three read the same operator-controlled paths\n * and a pipe at one of them used to hang whichever command got there first.\n */\nasync function readShippedFile(\n path: string,\n name: string,\n destDir: string,\n): Promise<Buffer | null> {\n const read = await readSkillFile(path);\n if (read.kind === 'absent') return null;\n if (read.kind === 'ok') return read.bytes;\n if (read.kind === 'not-regular') {\n throw new CliError('INTERNAL', `${path} is not a regular file, so ${name} was not written.`, {\n fix: `A skill file must be a regular file. Check what is there (\\`ls -l ${path}\\`) and remove or replace it, then re-run \\`tenjin install\\`.`,\n });\n }\n // Names the FILE, not its directory: this is a read failure, and pointing at a\n // perfectly writable parent is what sent operators to chmod the wrong thing.\n throw wrapWriteError(read.err, destDir, `the ${name} skill`, path, { verb: 'read' });\n}\n\n/**\n * A destination the operator manages through a symlink is written THROUGH it, so\n * their link survives and their target is what actually changes. Same call the\n * settings.json writer makes, and the same reason: committing with `rename` over a\n * link would replace it with a regular file and strand the target.\n */\nexport async function resolveThroughLink(path: string, name: string): Promise<string> {\n const entry = await lstat(path).catch(() => null);\n if (entry === null || !entry.isSymbolicLink()) return path;\n const target = await realpath(path).catch(() => null);\n if (target !== null) return target;\n throw new CliError('INTERNAL', `${path} is a broken symlink, so ${name} was not written.`, {\n fix: `Point it at a path that exists, or remove it (\\`ls -ld ${path}\\`), then re-run \\`tenjin install\\`.`,\n });\n}\n\n/**\n * On a case-insensitive filesystem (the macOS default), a user directory named a\n * case variant of a shipped skill ALIASES the skill's path, so the write would\n * replace the user's own SKILL.md under a warning naming a path that is not on\n * disk. Detected by the alias itself: the destination resolves but the parent\n * lists only a differently-cased entry, which also means a case-SENSITIVE\n * filesystem (where both names can coexist) never trips this. Dry runs too.\n */\nasync function assertNoCaseCollision(destDir: string, name: string): Promise<void> {\n if (!existsSync(destDir)) return;\n const entries = await readdir(dirname(destDir)).catch(() => null);\n if (entries === null || entries.includes(name)) return;\n const variant = entries.find((e) => e.toLowerCase() === name.toLowerCase());\n if (variant === undefined) return;\n const actual = join(dirname(destDir), variant);\n throw new CliError(\n 'INTERNAL',\n `${actual} is a case variant of the ${name} skill and this filesystem treats them as the same directory, so ${name} was not written.`,\n {\n fix: `Rename or remove ${actual}, then re-run \\`tenjin install\\`.`,\n },\n );\n}\n\n/**\n * Fail a destination directory that is a BROKEN SYMLINK, on dry runs too, so a dry\n * run cannot report `would-install` where the real run cannot write. It checks only\n * that: an unwritable but real directory passes here and fails at the write, with\n * the permission-denied error.\n */\nasync function assertReachable(destDir: string, name: string): Promise<void> {\n const entry = await lstat(destDir).catch(() => null);\n if (entry?.isSymbolicLink() !== true) return;\n if ((await realpath(destDir).catch(() => null)) !== null) return;\n throw new CliError('INTERNAL', `${destDir} is a broken symlink, so ${name} was not written.`, {\n fix: `Point it at a directory that exists, or remove it (\\`ls -ld ${destDir}\\`), then re-run \\`tenjin install\\`.`,\n });\n}\n\n/**\n * The directory a denied WRITE should point the operator at: the deepest existing\n * ancestor of the failed target's directory, RESOLVED. An existing skill directory\n * that refuses the temp file names itself; a directory that could not be created\n * names the ancestor that refused to create it, because `ls -ld` on a path that is\n * not there says nothing. Resolved because a destination managed through a symlink\n * denies the write in the link's TARGET, and telling the operator to chmod the\n * link's path leaves them staring at a healthy link.\n */\nexport async function deepestExisting(dir: string): Promise<string> {\n for (let cur = dir; ; cur = dirname(cur)) {\n if (existsSync(cur)) return realpath(cur).catch(() => cur);\n if (dirname(cur) === cur) return cur;\n }\n}\n\n/** A raw errno under INTERNAL reads as a CLI bug and carries no fix. */\nexport function wrapWriteError(\n err: unknown,\n /** The destination as the operator knows it (the declared path, pre-resolution). */\n dest: string,\n /** What could not be written, e.g. `the tenjin-search skill` or `the Tenjin pointer`. */\n subject: string,\n /**\n * The path to point the operator at. A READ failure names the file itself, which\n * is the thing whose mode is wrong. A WRITE failure names the deepest existing\n * directory on the failed target's resolved path.\n */\n culprit: string,\n opts: {\n /** Which side failed; a read error reported as \"could not write\" misleads. */\n verb?: 'read' | 'write';\n /** Sentence tail for the wrong-kind fix, telling the operator the expected shape. */\n expected?: string;\n } = {},\n): unknown {\n const verb = opts.verb ?? 'write';\n const denied = hasCode(err, 'EACCES') || hasCode(err, 'EPERM');\n const missing = hasCode(err, 'ENOENT');\n // A skills directory that resolves to a regular file, or a SKILL.md that resolves\n // to a directory. Pathological, but a raw ENOTDIR/EISDIR says nothing about which\n // path is the wrong kind of thing.\n const wrongKind = hasCode(err, 'ENOTDIR') || hasCode(err, 'EISDIR');\n if (!denied && !missing && !wrongKind) return err;\n const fix = denied\n ? `Permission denied on ${culprit}. Check it (\\`ls -ld ${culprit}\\`), then re-run \\`tenjin install\\`.`\n : wrongKind\n ? `${dest} (or a path inside it) is not the kind of thing it needs to be${opts.expected ?? ''}. Check it (\\`ls -ld ${dest}\\`), then re-run \\`tenjin install\\`.`\n : `${dest} could not be created; if it is a symlink, check that its target exists (\\`ls -ld ${dest}\\`), then re-run \\`tenjin install\\`.`;\n return new CliError(\n 'INTERNAL',\n `Could not ${verb} ${subject} ${verb === 'read' ? 'at' : 'to'} ${dest}.`,\n { fix, cause: err },\n );\n}\n\n/**\n * Read a directory tree into a rel-path -> content map, or null when it does not\n * exist. Reads as raw `Buffer`, not `utf8`: today's skills are markdown-only, but\n * this is a general recursive dir-copy, and decoding to a string here would\n * silently corrupt a future non-text asset (an image, a font) on write, or worse,\n * make two different corrupted binaries both decode to U+FFFD and compare equal.\n */\nasync function readTree(dir: string): Promise<Map<string, Buffer> | null> {\n if (!existsSync(dir)) return null;\n const entries = await readdir(dir, { recursive: true, withFileTypes: true });\n const files = new Map<string, Buffer>();\n for (const entry of entries) {\n if (!entry.isFile()) continue;\n const full = join(entry.parentPath, entry.name);\n files.set(relative(dir, full), await readFile(full));\n }\n return files;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,WAAAA,UAAS,IAAI,aAAa;AACnC,SAAS,eAAe;AACxB,SAAS,YAAY,QAAAC,aAAY;AACjC,SAAS,qBAAqB;;;ACwC9B,IAAM,cAAc;AACpB,IAAM,eAAe;AAGrB,IAAM,cAAc;AAQpB,IAAM,cAAc;AAyBb,SAAS,kBAAkB,OAAiD;AACjF,SAAO,EAAE,UAAU,MAAM,SAAS;AACpC;AAGO,SAAS,iBAAiB,OAEY;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AAC;AAC3B,aAAW,OAAO,cAAc,IAAI,GAAG;AACrC,QAAI;AACF,UAAI,UAAU,KAAK,EAAE,gBAAgB,MAAM,CAAC,GAAG,YAAY,MAAM,KAAM;AACvE,YAAM,YAAY,YAAY;AAAA,QAC5B,CAAC,SACC,UAAUD,MAAK,KAAK,MAAM,UAAU,GAAG,EAAE,gBAAgB,MAAM,CAAC,GAAG,OAAO,MAAM;AAAA,MACpF;AACA,UAAI,CAAC,UAAW;AAChB,YAAM,EAAE,QAAQ,IAAI,MAAM;AAAA,QACxB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,UAAI,QAAS,SAAQ,KAAKA,MAAK,KAAK,kBAAkB,CAAC;AAAA,IACzD,QAAQ;AAAA,IAER;AAAA,EACF;AACA,MAAI,QAAQ,SAAS,GAAG;AACtB;AAAA,MACE,KAAK;AAAA,MACL,GAAG,UAAU,cAAc,SAAS,IAAI,QAAQ,KAAK,OAAO,CAAC;AAAA,IAC/D;AAAA,EACF;AACF;","names":["readdir","join","join","readdir"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/router/status.ts"],"sourcesContent":["import { toMoney } from '../lib/money';\nimport type { ConfirmPolicy } from '../lib/policy';\nimport { resolveContextSettings } from '../lib/settings';\nimport { readSpendSummary } from '../lib/wallet/spend';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin status`: what this machine has spent and what it is still holding.\n *\n * IT READS `spend.json`, NOT THE BACKEND. The rolling window, the committed\n * total and the reservations still open are the local truth about money, and\n * the reservations are also the record of a request whose outcome is unknown:\n * an authorization that was transmitted is committed, so anything still open\n * here is either in flight or a crash that has not yet aged out.\n */\n\nexport interface StatusDeps {\n now?: () => number;\n}\n\nexport async function runRouterStatus(\n ctx: CommandContext,\n deps: StatusDeps = {},\n): Promise<CommandResult> {\n const now = deps.now ?? Date.now;\n const settings = await resolveContextSettings(ctx);\n // The same projection an authorization would make, so what this prints is\n // what the next lookup would actually be measured against.\n const ledger = await readSpendSummary(ctx.dataDir, { now });\n const committedAtomic = BigInt(ledger?.committedAtomic ?? '0');\n const reservedAtomic = (ledger?.reservations ?? []).reduce(\n (sum, r) => sum + BigInt(r.amountAtomic),\n 0n,\n );\n const budgetAtomic = BigInt(settings.policy.sessionBudgetAtomic);\n const data = {\n baseUrl: settings.baseUrl,\n window: {\n startedAtMs: ledger?.windowStartMs ?? null,\n committed: toMoney(committedAtomic.toString()),\n reserved: toMoney(reservedAtomic.toString()),\n budget: budgetAtomic === 0n ? null : toMoney(budgetAtomic.toString()),\n },\n caps: {\n maxAutoSpend: toMoney(settings.policy.maxAutoSpendAtomic.toString()),\n confirm: confirmLabel(settings.policy.confirm),\n },\n inFlight: (ledger?.reservations ?? []).map((r) => ({\n amount: toMoney(r.amountAtomic),\n ageSeconds: Math.max(0, Math.round((now() - r.atMs) / 1000)),\n ...(r.requestKey !== undefined ? { request: r.requestKey } : {}),\n })),\n };\n const budgetLine =\n budgetAtomic === 0n\n ? 'no session budget set'\n : `of ${toMoney(budgetAtomic.toString()).usd} USD in the rolling 24h window`;\n return {\n data,\n humanLines: [\n `spent ${toMoney(committedAtomic.toString()).usd} USD ${budgetLine}`,\n `reserved ${toMoney(reservedAtomic.toString()).usd} USD in ${data.inFlight.length} open request(s)`,\n `per call at most ${toMoney(settings.policy.maxAutoSpendAtomic.toString()).usd} USD, confirm ${confirmLabel(settings.policy.confirm)}`,\n ],\n };\n}\n\nfunction confirmLabel(confirm: ConfirmPolicy): string {\n return confirm.mode === 'always'\n ? 'always'\n : `above ${toMoney(confirm.thresholdAtomic.toString()).usd} USD`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,eAAsB,gBACpB,KACA,OAAmB,CAAC,GACI;AACxB,QAAM,MAAM,KAAK,OAAO,KAAK;AAC7B,QAAM,WAAW,MAAM,uBAAuB,GAAG;AAGjD,QAAM,SAAS,MAAM,iBAAiB,IAAI,SAAS,EAAE,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AAS,CAAC,EAAE,GAAG,iBAAiB,aAAa,SAAS,OAAO,OAAO,CAAC;AAAA,IACtI;AAAA,EACF;AACF;AAEA,SAAS,aAAa,SAAgC;AACpD,SAAO,QAAQ,SAAS,WACpB,WACA,SAAS,QAAQ,QAAQ,gBAAgB,SAAS,CAAC,EAAE,GAAG;AAC9D;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|