The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
cli: embed the Harness Compute skill in cli.js — the copy beside it never reached a machine
Kelvinda3a73d68c76
diff --git a/cli/build-bundle.mjs b/cli/build-bundle.mjsindex 50d1cbdfb..e9825ad0c 100644--- a/cli/build-bundle.mjs+++ b/cli/build-bundle.mjs@@ -10,7 +10,7 @@* `require` via the banner so ws's try/catch fallback works without them.*/import * as esbuild from 'esbuild'-import { readFileSync, copyFileSync, rmSync, mkdirSync } from 'fs'+import { readFileSync, copyFileSync, rmSync } from 'fs'import { readDshRegistry } from './scripts/lib/dshRegistry.mjs'const version =@@ -20,6 +20,15 @@ const version =// The bundled registry (the store/ folders and store/registry at the repo root) — see src/dsh/registry.ts.const dshRegistry = JSON.stringify(readDshRegistry(new URL('../store', import.meta.url)))+// The Harness Compute skill and its opencode agent definition, embedded the same way — see+// src/lib/harnessComputeSkill.ts. INSIDE cli.js, not beside it: this build ships one file (plus+// notify.mjs), and a `dist/skills/` laid down next to it reached no machine — upload-cli.sh,+// install.sh and the self-updater all move cli.js and notify.mjs and nothing else.+const harnessSkills = JSON.stringify(Object.fromEntries(+ ['harness-compute.md', 'harness-compute.agent.md']+ .map((name) => [name, readFileSync(new URL(`../docs/skills/${name}`, import.meta.url), 'utf8')]),+))+// Start clean so no stale per-file `dist/*.js` / sourcemaps leak into the release artifact.rmSync('dist', { recursive: true, force: true })@@ -31,7 +40,11 @@ await esbuild.build({format: 'esm',target: 'node20',external: ['bufferutil', 'utf-8-validate'],- define: { __ADAPTER_VERSION__: JSON.stringify(version), __DSH_REGISTRY__: JSON.stringify(dshRegistry) },+ define: {+ __ADAPTER_VERSION__: JSON.stringify(version),+ __DSH_REGISTRY__: JSON.stringify(dshRegistry),+ __HARNESS_SKILLS__: JSON.stringify(harnessSkills),+ },// The copyright line is MIT's one condition — it has to travel with the copy the user actually// receives, and the published bundle IS that copy (upload-cli.sh ships `cli.js` and `notify.mjs`,// nothing else). `legalComments: 'eof'` below appends the dependencies' own notices; this is ours.@@ -48,12 +61,4 @@ await esbuild.build({copyFileSync('hook/notify.mjs', 'dist/notify.mjs')-// harnessComputeSkill.ts reads this doc at runtime, as a SIBLING `skills/` dir next to cli.js —-// same layout notify.mjs uses, and the same "the doc is the source, install just ships it" split-// the source file documents.-mkdirSync('dist/skills', { recursive: true })-copyFileSync('../docs/skills/harness-compute.md', 'dist/skills/harness-compute.md')-// The `harness-compute` agent definition the same module installs beside the skill (opencode `--agent`).-copyFileSync('../docs/skills/harness-compute.agent.md', 'dist/skills/harness-compute.agent.md')--console.log(`✓ Bundled dist/cli.js (v${version}) + dist/notify.mjs + dist/skills/`)+console.log(`✓ Bundled dist/cli.js (v${version}, Harness Compute skill embedded) + dist/notify.mjs`)diff --git a/cli/build.mjs b/cli/build.mjsindex f524d21d5..9d01bc4a1 100644--- a/cli/build.mjs+++ b/cli/build.mjs@@ -8,6 +8,11 @@ import { readDshRegistry } from './scripts/lib/dshRegistry.mjs'const version = JSON.parse(readFileSync('package.json', 'utf8')).version// The bundled registry (the store/ folders and store/registry at the repo root) — see src/dsh/registry.ts.const dshRegistry = JSON.stringify(readDshRegistry(join('..', 'store')))+// The Harness Compute skill docs, embedded as build-bundle.mjs embeds them — see src/lib/harnessComputeSkill.ts.+const harnessSkills = JSON.stringify(Object.fromEntries(+ ['harness-compute.md', 'harness-compute.agent.md']+ .map((name) => [name, readFileSync(join('..', 'docs', 'skills', name), 'utf8')]),+))function getAllTsFiles(dir, fileList = []) {const files = readdirSync(dir)@@ -36,7 +41,11 @@ try {target: 'node20',sourcemap: true,outExtension: { '.js': '.js' },- define: { __ADAPTER_VERSION__: JSON.stringify(version), __DSH_REGISTRY__: JSON.stringify(dshRegistry) },+ define: {+ __ADAPTER_VERSION__: JSON.stringify(version),+ __DSH_REGISTRY__: JSON.stringify(dshRegistry),+ __HARNESS_SKILLS__: JSON.stringify(harnessSkills),+ },logLevel: 'info',})diff --git a/cli/src/lib/harnessComputeSkill.spec.ts b/cli/src/lib/harnessComputeSkill.spec.tsindex 5fe39c9fb..946b2f484 100644--- a/cli/src/lib/harnessComputeSkill.spec.ts+++ b/cli/src/lib/harnessComputeSkill.spec.ts@@ -80,6 +80,48 @@ describe('installOpencodeHarnessComputeSkill', () => {expect(readFileSync(agentPath, 'utf-8')).toBe(readFileSync(join(docs, 'harness-compute.agent.md'), 'utf-8'))})+ /**+ * The release bundle is ONE file — upload-cli.sh, install.sh and the self-updater all move `cli.js`+ * and `notify.mjs` and nothing else — so the docs cannot travel as files beside it. The bundle+ * build embeds them (esbuild `define`, the way the dsh registry travels), and a bundled daemon+ * installs from that, never from a `docs/skills/` it does not have.+ */+ it('installs from the sources the build embedded, reading nothing from docs/skills', async () => {+ vi.stubGlobal('__HARNESS_SKILLS__', JSON.stringify({+ 'harness-compute.md': '# EMBEDDED SKILL\n\nfrom the bundle\n',+ 'harness-compute.agent.md': "---\nname: 'harness-compute'\nmode: primary\n---\nEMBEDDED AGENT\n",+ }))+ try {+ const { installOpencodeHarnessComputeSkill } = await load()+ installOpencodeHarnessComputeSkill()++ const skill = readFileSync(join(configHome, 'opencode', 'skills', 'harness-compute', 'SKILL.md'), 'utf-8')+ expect(skill.startsWith('---\nname: harness-compute\n')).toBe(true)+ expect(skill.endsWith('# EMBEDDED SKILL\n\nfrom the bundle\n')).toBe(true)+ expect(skill).not.toContain('HOW TO OPERATE HARNESS COMPUTE')+ const agent = readFileSync(join(configHome, 'opencode', 'agents', 'harness-compute.md'), 'utf-8')+ expect(agent).toBe("---\nname: 'harness-compute'\nmode: primary\n---\nEMBEDDED AGENT\n")+ expect(console.error).not.toHaveBeenCalled()+ } finally {+ vi.unstubAllGlobals()+ }+ })++ it('is what both builds embed: the two docs, by name, in build.mjs and build-bundle.mjs', () => {+ const cliRoot = join(__dirname, '..', '..')+ for (const script of ['build.mjs', 'build-bundle.mjs']) {+ const source = readFileSync(join(cliRoot, script), 'utf-8')+ expect(source, script).toContain('__HARNESS_SKILLS__')+ expect(source, script).toContain("'harness-compute.md'")+ expect(source, script).toContain("'harness-compute.agent.md'")+ }+ // The copy beside cli.js is gone with the lookup that read it: a directory nobody ships is a+ // promise nobody keeps. (The comment explaining why may still name it; the calls may not.)+ const bundle = readFileSync(join(cliRoot, 'build-bundle.mjs'), 'utf-8')+ expect(bundle).not.toMatch(/mkdirSync\(['"]dist\/skills/)+ expect(bundle).not.toMatch(/copyFileSync\([^)]*dist\/skills/)+ })+it('honours OPENCODE_AGENT_DIR and OPENCODE_SKILL_DIR over the XDG default', async () => {vi.resetModules()process.env.XDG_CONFIG_HOME = configHomediff --git a/cli/src/lib/harnessComputeSkill.ts b/cli/src/lib/harnessComputeSkill.tsindex 98f20af63..153acd8ec 100644--- a/cli/src/lib/harnessComputeSkill.ts+++ b/cli/src/lib/harnessComputeSkill.ts@@ -22,16 +22,31 @@ import { env } from '../config/env.js'const cliDir = dirname(fileURLToPath(import.meta.url))-// Same dual-path pattern hooks.ts uses for notify.mjs (import.meta.url is the REAL executing-// file at runtime):-// - packaged/bundled: cli.js at ~/.harness/cli/cli.js → the docs ship as a SIBLING `skills/` dir-// (build-bundle.mjs copies them there, same as it copies notify.mjs).-// - dev/per-file: hooks live at <appRoot>/cli/src/lib/ → the docs are three levels up, at-// <appRoot>/docs/skills/.-function skillSourcePath(name: string): string {- const packaged = join(cliDir, 'skills', name)- const dev = join(cliDir, '..', '..', '..', 'docs', 'skills', name)- return [packaged, dev].find(existsSync) ?? dev+/**+ * The docs as the build embedded them — a JSON object of file name → text, injected by esbuild+ * `define` in build-bundle.mjs and build.mjs the way `__DSH_REGISTRY__` is (dsh/registry.ts).+ *+ * INSIDE cli.js rather than shipped as files beside it, because nothing ships files beside cli.js:+ * upload-cli.sh publishes `cli.js` and `notify.mjs` and nothing else, install.sh fetches those two,+ * the self-updater swaps those two. The `dist/skills/` the bundle used to lay down reached no+ * machine — a daemon installed from the CDN logged "failed to read Harness Compute skill sources"+ * and installed nothing, silently, while a working tree that happened to have a `skills/` beside its+ * cli.js looked fine. Embedded, the docs travel wherever cli.js does and can never be a version+ * behind the code that installs them.+ */+declare const __HARNESS_SKILLS__: string | undefined++function embeddedSkill(name: string): string | null {+ if (typeof __HARNESS_SKILLS__ === 'undefined') return null+ const skills = JSON.parse(__HARNESS_SKILLS__) as Record<string, unknown>+ const text = skills[name]+ return typeof text === 'string' ? text : null+}++/** Dev, per-file (tsx, vitest): this file runs from <appRoot>/cli/src/lib/, and the docs are three+ * levels up, at <appRoot>/docs/skills/. Nothing is embedded there, and nothing needs to be. */+function devSkillPath(name: string): string {+ return join(cliDir, '..', '..', '..', 'docs', 'skills', name)}const SKILL_PATH = join(env.OPENCODE_SKILL_DIR, 'harness-compute', 'SKILL.md')@@ -72,10 +87,12 @@ function installFile(label: string, target: string, source: string): void {}}-/** The doc at `name` under docs/skills/, or null (logged) when it cannot be read. */+/** The doc `name`: what the build embedded, else the file under docs/skills/ (dev), else null (logged). */function readSkillSource(label: string, name: string): string | null {+ const embedded = embeddedSkill(name)+ if (embedded !== null) return embeddedtry {- return readFileSync(skillSourcePath(name), 'utf-8')+ return readFileSync(devSkillPath(name), 'utf-8')} catch (err) {// Best-effort, same posture as every other engine install in hooks.ts: a missing or unreadable// source must never fail `harness start`, only skip this one file.