Skip to content

feat(templates): generalize boot flow and add template picker UI#7

Open
Dhi13man wants to merge 5 commits intoopen-gitagent:mainfrom
Dhi13man:feat/template-picker
Open

feat(templates): generalize boot flow and add template picker UI#7
Dhi13man wants to merge 5 commits intoopen-gitagent:mainfrom
Dhi13man:feat/template-picker

Conversation

@Dhi13man
Copy link

@Dhi13man Dhi13man commented Mar 21, 2026

Why

ClawLess hardcodes GitClaw as the only agent — buildContainerPackageJson pins gitclaw: '1.1.4', buildWorkspaceFiles always mounts GitClaw config files, and sdk.ts branches on isGitclaw. This blocks #4 (OpenClaw support) because there's no way to register and boot a different agent.

This PR makes the boot flow template-driven so any agent can be registered and selected at startup.

Before / After

Before (main) After (with 2 templates registered)
before after

Before: Direct boot to loading screen — no choice of agent.
After: Picker overlay appears when multiple templates are registered. User clicks a card to select their agent.

Design Context

flowchart TD
    A[main.ts] -->|registry.size > 1?| B{Template Picker}
    A -->|registry.size <= 1| C[Boot default template]
    B -->|user clicks card| C
    C --> D[resolveTemplate]
    D --> E[mergeTemplateWithOptions]
    E --> F[boot: mount workspace + package.json from template]
    F --> G{template.configRequired?}
    G -->|yes| H[Show config panel, wait for API key]
    G -->|no| I[Launch agent directly]
    H --> I
    I --> J[startAgent with AgentConfig]
Loading

Trade-offs

  • buildWorkspaceFiles now starts with empty tree instead of hardcoded defaults. Templates that don't declare workspace files get an empty workspace. Accepted because defaults now live in GITCLAW_TEMPLATE.workspace and flow through mergeTemplateWithOptions — GitClaw behavior is identical, new templates opt-in to exactly the files they need.
  • startGitclaw() kept but deprecated rather than deleted. It has GitClaw-specific restart messaging that startAgent() doesn't replicate. Removing is safe but deferred to reduce risk.
  • Picker uses textContent instead of innerHTML for template name/description. Prevents XSS if a malicious template is registered.

How to review

Order File What changed
1 src/workspace.ts buildContainerPackageJson takes AgentConfig instead of hardcoding deps. buildWorkspaceFiles starts empty.
2 src/templates.ts ContainerTemplate gains configRequired. GITCLAW_TEMPLATE declares its workspace files.
3 src/container.ts boot() accepts agentConfig, passes it to package.json builder.
4 src/sdk.ts isGitclaw branch replaced with template.configRequired. All agents use startAgent().
5 src/main.ts Picker overlay — shows when >1 template, skips when 1.
6 index.html + src/style.css Picker markup and styles.
7 src/*.test.ts 43 tests for all pure functions.

Test plan

  • npx vitest run — 43 tests covering:
    • buildContainerPackageJson: agent config derivation, version defaulting, false/undefined, extraDeps merge
    • buildWorkspaceFiles: empty input, flat files, nested paths, multi-file merge
    • mergeTemplateWithOptions: per-key merge, agent override, tab dedup, startupScript fallback
    • parseTemplateYaml: scalars, agent blocks, env blocks, block scalars, validation
  • Manual: npm run dev boots GitClaw identically (picker skipped with 1 template)
  • Manual: register second template → picker renders both cards, selection triggers boot

Closes #4 (partial — template infrastructure)

Generated with Dhiman's Agentic Suite

Dhi13man and others added 5 commits March 21, 2026 13:57
Remove hardcoded GitClaw assumptions from workspace builder, container
boot, and SDK launch flow. Templates now declare their own workspace
files, dependencies, and config requirements. A picker overlay appears
at startup when multiple templates are registered.

Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
…ll assertion

- Replace innerHTML with textContent in template picker (XSS fix)
- Empty hardcoded base tree in buildWorkspaceFiles — defaults now come
  from GITCLAW_TEMPLATE.workspace via template resolution
- Use local template variable instead of this._template! assertion
- Add tests for undefined agent and package name

Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
…, YAML parser

Cover buildWorkspaceFiles (nested paths, merging), mergeTemplateWithOptions
(per-key merge, tab dedup, agent override), and parseTemplateYaml (agent
blocks, env blocks, block scalars, comments, validation).

Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
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.

Support OpenClaw as an agent template

1 participant