Registry Mirror
Skip to content

Conversation

@lpiedade

Copy link
Copy Markdown
Contributor

What

User templates can now move between machines, as tasks already do.

Daemon and contract

  • GET /api/v1/templates/{templateId}/export (exportTemplate) answers a user template's file as application/yaml, saved as <id>.yaml. Secrets are masked as a task's export masks them.
    • A template holds no state or logs, and its tasks hold no reference to it, so nothing those tasks did travels with it.
    • A built-in template answers 409 template_read_only.
  • POST /api/v1/templates/import (importTemplate) takes body TemplateImportRequest {yaml, overwrite, dryRun}.
    • The template takes its file's own metadata.id, used only once the template schema has passed, so an untrusted file never names a path.
    • A schema failure or an hf- identifier answers 422, and nothing is written.
    • An identifier a user template already has answers 409 template_exists unless overwrite is set. This holds for a file not yet read by the watcher too.
    • dryRun makes every check, writes nothing, and answers 200 with the template as it would be saved, its document and needs included.
    • A real import answers 201. needs.missing names each agent and skill this machine lacks, and the template is saved all the same.
    • A saved import emits template.created, or template.updated when it replaced one.
  • No new message keys. make generate refreshed generated.ts.

Desktop (Templates view on the Tasks screen)

  • A user template row gets Export. Built-in rows get none.
  • Import sits beside New template and opens TemplateImportDialog.
    • Its first click is the dry run. It shows the template's name, ID, type, and permission profile (the schema default, named as such, when the template sets none), its network and custom permission lists when set, and the agents and skills this machine lacks.
    • For a script template, it also shows the task import's own script preview: the interpreter's argument list and whole inline script (or the whole argument list), working directory, and environment. That preview is now exported from ImportDialog.tsx, with a banner each import words for itself.
    • Only a second click (Save template) on the same text and replace choice saves. Cancel saves nothing.
    • Replacing an existing identifier needs the replace option, as the task import does.

Tests

  • app:
    • TestExportTemplateHoldsNoSecretsLogsOrState: a template whose tasks have run, with secrets in its prompt and comments and in the runs' output. The export holds none of them and no execution ID, and it imports on another machine.
    • TestImportTemplateNamesWhatThisMachineLacks: exported where review-notes exists, imported where it doesn't and a user template has the ID. Covers a refused replace (dry run too), a confirmed replace (template.updated, needs.missing names review-notes), and a new ID (template.created).
    • TestImportTemplateRejectsAnInvalidOrReservedOne: an hf- identifier (a built-in's or not), an unknown type, a non-identifier (../outside), a task file, a file that is no YAML, and empty input. Each is rejected, dry run or not, and nothing is written.
    • TestImportScriptTemplateDryRunGivesItsProgram.
    • The daemon tests were mutation-checked: dropping the redaction, or the replace check, fails them.
  • httpapi: TestTemplateImportExportRoutes.
  • tests/integration: TestAPIGuardOnEveryRoute now lists all six template routes. It failed on main: four routes from [Feature]: Edit, duplicate, and delete user templates #180 were missing from its tables. It passes here.
  • Desktop, TasksScreen.test.tsx:
    • Export a row, import that file, get asked before replacing, see the preview, save on the second click.
    • A script template's preview (interpreter, whole script, working directory, environment, default profile) and Cancel, which sends no non-dry-run request.

What ran (locally; Actions do not start this month)

  • Passed:
    • go test -race on internal/app (template tests) and internal/adapters/httpapi.
    • internal/archtest.
    • TestAPIGuardOnEveryRoute.
    • pnpm -C desktop typecheck, and pnpm -C desktop test (54 files, 1100 tests).
    • make check-generated, check-imports, check-file-names, and check-template-texts.
    • make vet-daemon and gofmt -l.
  • First full make coverage-daemon COVERAGE_UNIT_FLAGS=-race: it ran concurrently with make test-desktop-daemon. Two failures were this branch's and are fixed in 7ee8f5b: archtest (an adapter import in user_templates.go) and the route guard above. The other failures were in tests this change doesn't touch, under that load:
    • claudecode: TestSkillListThatClaudeCodeCannotGive
    • codex: TestDetectReadsTheAccountAndItsManagedRequirements
    • integration: TestRestartEndsWhatTheScriptLeft and TestTasksRunOnTheToolsOwnSignIns
    • app: a 10-minute package timeout after TestEditWhileRunningKeepsTheStartingTimeout
  • A rerun of the full coverage-daemon on its own is in progress. Its result will be added here.
  • make test-desktop-daemon failed one test this change doesn't touch: realDaemon.test.tsx › "a user's agent selected in the task form…", with a refused connection, under that same load. It has not been rerun alone yet.

What did not run

  • No browser or Tauri visual check of the dialog. The happy-dom tests drive the flow.
  • No CI.

Notes

  • Test-first held for the daemon and routes. The desktop dialog was written before its tests.
  • The issue still carried needs-triage when work started. Its one open point (where the dashboard offers import and export) was answered in [Feature]: Edit, duplicate, and delete user templates #180: the Templates view on the Tasks screen.

Closes #181

- A user template lived on one machine: tasks move by export and
  import, templates had no such path (#181).
- Export masks secrets as a task's export does; a template holds no
  state or logs, and its tasks hold no reference to it, so nothing
  they did travels with it.
- Import takes the file's own identifier only after the schema has
  checked it, so an untrusted file never names a path; an hf-
  identifier fails as it does on any write.
- A dry run makes every check and writes nothing, so the dashboard
  can show what a template would run before it is saved.
- An existing identifier is replaced only on request, as for tasks,
  and the answer names the agents and skills this machine lacks.
- A user template row offers Export, saved where the user picks as a
  task's export is; built-in rows offer none, since every HarmFlow
  ships them (#181).
- Import sits beside New template. Its first click is the daemon's
  dry run, which shows the type and permission profile, the agents
  and skills this machine lacks, and for a script template the
  program it runs; only a second click on the same text saves it,
  and closing the dialog saves nothing.
- The script preview is the task import's own, now exported with a
  banner each import words for itself: a template is not saved
  disabled, as an imported script task is.
- An existing identifier is replaced only when the user ticks the
  replace option, as the task import does.
- A file written outside HarmFlow since the last scan is on disk but
  not in memory; its import now asks before replacing it and is
  announced as an update, as for a file already read.
- The import's toast names the template in the interface's language,
  as its preview does, since a template's text can differ by language.
- The route guard test failed on main: four template routes from #180
  were in the contract but not in its tables. It now sends each of
  the six template routes without a valid token, with a request that
  would write a template if the guard let it through.
- The export's redaction moves to tasks.go, which already imports the
  event log, so user_templates.go adds no adapter import to the app
  layer's allowlist.
@lpiedade lpiedade self-assigned this Nov 19, 2026
@lpiedade
lpiedade merged commit 3709ca8 into main Nov 19, 2026
7 checks passed
@lpiedade
lpiedade deleted the feat/181-import-export-templates branch November 19, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Import and export task templates

1 participant