From d4cce2077659070c584d8852dafc929d5a2fb0eb Mon Sep 17 00:00:00 2001 From: Volodymyr Vreshch Date: Sun, 22 Nov 2026 10:10:43 +0100 Subject: [PATCH 1/2] fix(template): any id length, build skips a dropped app, ci-required Claude-Session: https://claude.ai/code/session_01XQkodgygL4W8UcLQDwC212 --- .github/workflows/ci.yml | 44 +++++++++++++++++++- scripts/template-create.mjs | 69 +++++++++++++++++++++++++++++++ template/.github/workflows/ci.yml | 16 +++++++ template/README.md | 18 ++++---- template/docs/run-locally.md | 10 ++--- template/package.json | 2 +- template/src/app/index.tsx | 6 ++- 7 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 scripts/template-create.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 463ec60..bff3ca7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -451,7 +451,7 @@ jobs: files=$(git diff --name-only "$BASE" HEAD) fi own=false; kit=false - if [ -z "$files" ] || grep -qE '^(template/|\.github/workflows/ci\.yml$)' <<<"$files"; then own=true; fi + if [ -z "$files" ] || grep -qE '^(template/|scripts/template-create\.mjs$|\.github/workflows/ci\.yml$)' <<<"$files"; then own=true; fi if [ -z "$files" ] || grep -qE '^packages/(extension|widget|logs|app)/' <<<"$files"; then kit=true; fi run=$([ "$own" = true ] || [ "$kit" = true ] && echo true || echo false) echo "template: $own, kit: $kit" | tee -a "$GITHUB_STEP_SUMMARY" @@ -599,10 +599,50 @@ jobs: working-directory: template run: docker compose -f .agentage/compose.json logs --no-color --tail 80 || true + # What create makes: a short id, a long id and one part, each must pass verify (the rewrite is scripts/template-create.mjs). + template-create: + name: Template create (${{ matrix.case }}) + needs: template-changes + if: needs.template-changes.outputs.run == 'true' + runs-on: ubuntu-latest + timeout-minutes: 10 + strategy: + fail-fast: false + matrix: + include: + - { case: short id, id: ab, parts: '' } + - { case: long id, id: a-very-long-extension-id, parts: '' } + - { case: api part only, id: demo, parts: api } + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Setup Node.js + uses: actions/setup-node@v7 + with: + node-version: 22 + cache: 'npm' + cache-dependency-path: template/package-lock.json + + - name: Create the copy (the cli's drop and whole-word rewrite) + env: + ID: ${{ matrix.id }} + PARTS: ${{ matrix.parts }} + run: node scripts/template-create.mjs template "$RUNNER_TEMP/copy" "$ID" $PARTS + + - name: Install, commit (build needs a clean git tree) and verify + working-directory: ${{ runner.temp }}/copy + run: | + set -euo pipefail + npm ci --no-audit --no-fund + git init -q -b master && git add -A + git -c user.name=ci -c user.email=ci@example.com commit -qm init + npm run verify + # The one context for the template: green when its jobs passed or this change did not touch it. template: name: Template - needs: [template-changes, template-verify, template-local] + needs: [template-changes, template-verify, template-local, template-create] if: always() runs-on: ubuntu-latest timeout-minutes: 5 diff --git a/scripts/template-create.mjs b/scripts/template-create.mjs new file mode 100644 index 0000000..643e1a9 --- /dev/null +++ b/scripts/template-create.mjs @@ -0,0 +1,69 @@ +import { + cpSync, + existsSync, + readdirSync, + readFileSync, + renameSync, + rmSync, + writeFileSync, +} from 'node:fs'; +import { join } from 'node:path'; + +// Mirrors `agentage extension create` (cli src/commands/extension/create.ts): the cli reads a GitHub repo only. +const PARTS = ['pages', 'ui', 'api', 'mcp', 'worker', 'store', 'cli', 'app']; +const WORD = /(? JSON.parse(readFileSync(file, 'utf8')); +const save = (file, value) => writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`); + +const drop = (dir, kept) => { + const pkg = readJson(join(dir, 'package.json')); + for (const part of PARTS.filter((p) => !kept.includes(p))) { + delete pkg.agentage?.parts?.[part]; + for (const sub of [join('src', part), ...(PRUNE[part]?.paths ?? [])]) + rmSync(join(dir, sub), { recursive: true, force: true }); + for (const path of PRUNE[part]?.keys ?? []) { + const parent = path.slice(0, -1).reduce((at, key) => at?.[key], pkg); + if (parent) delete parent[path.at(-1)]; + } + } + save(join(dir, 'package.json'), pkg); +}; + +const rewrite = (dir, id) => { + for (const entry of readdirSync(dir, { withFileTypes: true })) { + const path = join(dir, entry.name); + if (entry.isDirectory()) rewrite(path, id); + if (entry.isFile() && entry.name !== 'package-lock.json') { + const text = readFileSync(path, 'utf8'); + if (text.replace(WORD, id) !== text) writeFileSync(path, text.replace(WORD, id)); + } + const name = entry.name.replace(WORD, id); + if (name !== entry.name) renameSync(path, join(dir, name)); + } +}; + +const renameLock = (dir, id) => { + const file = join(dir, 'package-lock.json'); + const lock = readJson(file); + for (const at of [lock, lock.packages?.['']]) if (at) at.name = `@agentage/extension-${id}`; + save(file, lock); +}; + +export const createFromTemplate = (from, to, id, parts = PARTS) => { + if (existsSync(to)) throw new Error(`${to} exists`); + cpSync(from, to, { recursive: true, filter: (src) => !/node_modules|\.kit/.test(src) }); + drop(to, parts); + rewrite(to, id); + renameLock(to, id); +}; + +const [from, to, id, ...parts] = process.argv.slice(2); +if (import.meta.url === `file://${process.argv[1]}`) + createFromTemplate(from, to, id, parts.length ? parts : PARTS); diff --git a/template/.github/workflows/ci.yml b/template/.github/workflows/ci.yml index 4379ae4..88f6f79 100644 --- a/template/.github/workflows/ci.yml +++ b/template/.github/workflows/ci.yml @@ -100,3 +100,19 @@ jobs: - name: Logs on failure if: failure() || cancelled() run: docker compose -f .agentage/compose.json logs --no-color --tail 80 || true + + # The one required context: green when every job passed or was skipped. + ci-required: + name: ci-required + needs: [verify, local] + if: always() + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Every job passed or was skipped + env: + NEEDS: ${{ toJSON(needs) }} + run: | + set -euo pipefail + jq -r 'to_entries[] | "\(.key): \(.value.result)"' <<<"$NEEDS" + jq -e 'all(.[]; .result == "success" or .result == "skipped")' <<<"$NEEDS" >/dev/null diff --git a/template/README.md b/template/README.md index 3eefe1c..ce71acc 100644 --- a/template/README.md +++ b/template/README.md @@ -63,16 +63,14 @@ Each part serves `/health` on port 3000 in its container. `up` does not publish ## What it serves -| Part | Folder | What it does | -| ------ | ----------------------- | -------------------------------------------------------------------------------- | -| pages | `src/pages` | `/` shows the id, version and commit | -| ui | `src/ui` | the widget `<{id}-echo>`, served at `/ui/{version}/{id}.js` | -| api | `src/api` | `GET /api/template/echo` (scope `{id}:read`), `GET /api/template/ping` (public) | -| mcp | `src/mcp` | the tool `{id}__echo` (scope `{id}:read`) | -| worker | `src/worker` | the job `tick`, every minute | -| store | `migrations/`, `seeds/` | postgres; `ping` counts the rows of `pings` | -| cli | `src/cli` | `agentage ping [msg]` prints `pong` | -| app | `src/app` | the shell page `/{id}`: an Echo button that calls the api through `useAppHost()` | +- pages, `src/pages`: `/` shows the id, version and commit. +- ui, `src/ui`: the widget `<{id}-echo>`, served at `/ui/{version}/{id}.js`. +- api, `src/api`: `GET /api/template/echo` (scope `{id}:read`) and `GET /api/template/ping` (public). +- mcp, `src/mcp`: the tool `{id}__echo` (scope `{id}:read`). +- worker, `src/worker`: the job `tick`, every minute. +- store, `migrations/` and `seeds/`: postgres; `ping` counts the rows of `pings`. +- cli, `src/cli`: `agentage ping [msg]` prints `pong`. +- app, `src/app`: the shell page `/{id}`: an Echo button that calls the api through `useAppHost()`. A seed in `seeds/` runs once, on an empty store. diff --git a/template/docs/run-locally.md b/template/docs/run-locally.md index 5087ef4..8a1afc9 100644 --- a/template/docs/run-locally.md +++ b/template/docs/run-locally.md @@ -21,12 +21,10 @@ in that folder, or find the holder with `docker ps`. ## Answers -| Call | Answer | -| ------------------------------------------- | -------------------------------------------------------------------------------------------- | -| `GET /api/template/echo?msg=hi` with token | 200 `{"success":true,"data":{"msg":"hi","caller":...}}` | -| `GET /api/template/ping` (public, no token) | 200 `{"success":true,"data":{"msg":"pong","pings":1}}`; `pings` counts the rows in the store | -| a protected route without a token | 401 `{"success":false,"error":{"code":"UNAUTHORIZED","message":...,"agcid":...}}` | -| `echo` without `msg` | 400 `{"success":false,"error":{"code":"VALIDATION_ERROR",...}}`, with the field named | +- `GET /api/template/echo?msg=hi` with a token: 200 `{"success":true,"data":{"msg":"hi","caller":...}}`. +- `GET /api/template/ping` (public, no token): 200 `{"success":true,"data":{"msg":"pong","pings":1}}`; `pings` counts the rows in the store. +- A protected route without a token: 401 `{"success":false,"error":{"code":"UNAUTHORIZED","message":...,"agcid":...}}`. +- `echo` without `msg`: 400 `{"success":false,"error":{"code":"VALIDATION_ERROR",...}}`, with the field named. Every answer has an `Agcid` response header with the request id. An error body also carries it as `error.agcid`. A success body does not. diff --git a/template/package.json b/template/package.json index 57a475e..821fbe2 100644 --- a/template/package.json +++ b/template/package.json @@ -63,7 +63,7 @@ "!dist/**/*.test.*" ], "scripts": { - "build": "tsc -p tsconfig.build.json && (test ! -d src/ui || agentage-widget bundle) && node node_modules/@agentage/extension/dist/tool/cli.js app", + "build": "tsc -p tsconfig.build.json && (test ! -d src/ui || agentage-widget bundle) && (test ! -d src/app || node node_modules/@agentage/extension/dist/tool/cli.js app)", "type-check": "tsc --noEmit -p tsconfig.eslint.json", "lint": "eslint .", "format": "prettier --write .", diff --git a/template/src/app/index.tsx b/template/src/app/index.tsx index 0ceb6af..1d111ea 100644 --- a/template/src/app/index.tsx +++ b/template/src/app/index.tsx @@ -4,6 +4,8 @@ import { Input } from '@agentage/design-system/input'; import { Label } from '@agentage/design-system/label'; import { useState } from 'react'; +const FIELD = 'template-msg'; + // The shell page of the extension: it reaches its own api through useAppHost().api, never fetch. export default function App() { const { api } = useAppHost(); @@ -20,8 +22,8 @@ export default function App() {

template

- - setMsg(e.target.value)} /> + + setMsg(e.target.value)} />

From 50986bd00e1047c05aca6f4e935588e250ac3227 Mon Sep 17 00:00:00 2001 From: Volodymyr Vreshch Date: Sun, 22 Nov 2026 10:42:50 +0100 Subject: [PATCH 2/2] ci(template): create runs the real cli, not a script copy Claude-Session: https://claude.ai/code/session_01XQkodgygL4W8UcLQDwC212 --- .github/workflows/ci.yml | 22 ++++++------ scripts/template-create.mjs | 69 ------------------------------------- 2 files changed, 12 insertions(+), 79 deletions(-) delete mode 100644 scripts/template-create.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bff3ca7..67ad7df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -451,7 +451,7 @@ jobs: files=$(git diff --name-only "$BASE" HEAD) fi own=false; kit=false - if [ -z "$files" ] || grep -qE '^(template/|scripts/template-create\.mjs$|\.github/workflows/ci\.yml$)' <<<"$files"; then own=true; fi + if [ -z "$files" ] || grep -qE '^(template/|\.github/workflows/ci\.yml$)' <<<"$files"; then own=true; fi if [ -z "$files" ] || grep -qE '^packages/(extension|widget|logs|app)/' <<<"$files"; then kit=true; fi run=$([ "$own" = true ] || [ "$kit" = true ] && echo true || echo false) echo "template: $own, kit: $kit" | tee -a "$GITHUB_STEP_SUMMARY" @@ -599,7 +599,7 @@ jobs: working-directory: template run: docker compose -f .agentage/compose.json logs --no-color --tail 80 || true - # What create makes: a short id, a long id and one part, each must pass verify (the rewrite is scripts/template-create.mjs). + # The real `agentage extension create` on this change's template/ folder, then verify in the created folder. template-create: name: Template create (${{ matrix.case }}) needs: template-changes @@ -613,25 +613,27 @@ jobs: - { case: short id, id: ab, parts: '' } - { case: long id, id: a-very-long-extension-id, parts: '' } - { case: api part only, id: demo, parts: api } + - { case: app and api, id: demo, parts: app api } steps: - - name: Checkout - uses: actions/checkout@v7 - - name: Setup Node.js uses: actions/setup-node@v7 with: node-version: 22 - cache: 'npm' - cache-dependency-path: template/package-lock.json - - name: Create the copy (the cli's drop and whole-word rewrite) + # --no-install: without it create would build the folder and give it to a local daemon. + - name: agentage extension create from this change's template/ env: ID: ${{ matrix.id }} PARTS: ${{ matrix.parts }} - run: node scripts/template-create.mjs template "$RUNNER_TEMP/copy" "$ID" $PARTS + REPO: ${{ github.event.pull_request.head.repo.full_name || github.repository }} + REF: ${{ github.head_ref || github.ref_name }} + run: | + set -euo pipefail + mkdir "$RUNNER_TEMP/made" && cd "$RUNNER_TEMP/made" + npx -y @agentage/cli@0.72.0 extension create "$ID" $PARTS --from "$REPO#$REF:template" --yes --no-install - name: Install, commit (build needs a clean git tree) and verify - working-directory: ${{ runner.temp }}/copy + working-directory: ${{ runner.temp }}/made/extension-${{ matrix.id }} run: | set -euo pipefail npm ci --no-audit --no-fund diff --git a/scripts/template-create.mjs b/scripts/template-create.mjs deleted file mode 100644 index 643e1a9..0000000 --- a/scripts/template-create.mjs +++ /dev/null @@ -1,69 +0,0 @@ -import { - cpSync, - existsSync, - readdirSync, - readFileSync, - renameSync, - rmSync, - writeFileSync, -} from 'node:fs'; -import { join } from 'node:path'; - -// Mirrors `agentage extension create` (cli src/commands/extension/create.ts): the cli reads a GitHub repo only. -const PARTS = ['pages', 'ui', 'api', 'mcp', 'worker', 'store', 'cli', 'app']; -const WORD = /(? JSON.parse(readFileSync(file, 'utf8')); -const save = (file, value) => writeFileSync(file, `${JSON.stringify(value, null, 2)}\n`); - -const drop = (dir, kept) => { - const pkg = readJson(join(dir, 'package.json')); - for (const part of PARTS.filter((p) => !kept.includes(p))) { - delete pkg.agentage?.parts?.[part]; - for (const sub of [join('src', part), ...(PRUNE[part]?.paths ?? [])]) - rmSync(join(dir, sub), { recursive: true, force: true }); - for (const path of PRUNE[part]?.keys ?? []) { - const parent = path.slice(0, -1).reduce((at, key) => at?.[key], pkg); - if (parent) delete parent[path.at(-1)]; - } - } - save(join(dir, 'package.json'), pkg); -}; - -const rewrite = (dir, id) => { - for (const entry of readdirSync(dir, { withFileTypes: true })) { - const path = join(dir, entry.name); - if (entry.isDirectory()) rewrite(path, id); - if (entry.isFile() && entry.name !== 'package-lock.json') { - const text = readFileSync(path, 'utf8'); - if (text.replace(WORD, id) !== text) writeFileSync(path, text.replace(WORD, id)); - } - const name = entry.name.replace(WORD, id); - if (name !== entry.name) renameSync(path, join(dir, name)); - } -}; - -const renameLock = (dir, id) => { - const file = join(dir, 'package-lock.json'); - const lock = readJson(file); - for (const at of [lock, lock.packages?.['']]) if (at) at.name = `@agentage/extension-${id}`; - save(file, lock); -}; - -export const createFromTemplate = (from, to, id, parts = PARTS) => { - if (existsSync(to)) throw new Error(`${to} exists`); - cpSync(from, to, { recursive: true, filter: (src) => !/node_modules|\.kit/.test(src) }); - drop(to, parts); - rewrite(to, id); - renameLock(to, id); -}; - -const [from, to, id, ...parts] = process.argv.slice(2); -if (import.meta.url === `file://${process.argv[1]}`) - createFromTemplate(from, to, id, parts.length ? parts : PARTS);