Skip to content

refactor(registry/harleylrn/modules/kiro-cli)!: remove agentapi, tasks and start logic - #1161

Draft
35C4n0r wants to merge 7 commits into
mainfrom
35C4n0r/migrate-kiro-cli
Draft

35C4n0r wants to merge 7 commits into
mainfrom
35C4n0r/migrate-kiro-cli

Conversation

@35C4n0r

@35C4n0r 35C4n0r commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes REG-87

Refactor harleylrn/kiro-cli to install and configure Kiro CLI only, matching the claude-code, codex, copilot, and cursor-cli (#1152) migrations. Changes beyond the AgentAPI removal are limited to what the current Kiro docs require.

  • Replace the agentapi module with coder-utils; drop Tasks/web-app inputs (order, group, report_tasks, cli_app, web_app_display_name, cli_app_display_name, install_agentapi, agentapi_version, agentapi_chat_based_path, ai_prompt, system_prompt, coder_mcp_instructions, trust_all_tools), the task_app_id output, the start script, the default agent template, and the task-reporting coder MCP server.
  • Install with the documented installer (https://cli.kiro.dev/install) for latest. A pinned kiro_cli_version or custom kiro_install_url installs <url>/<version>/kirocli-<arch>-linux.zip (default host desktop-release.q.us-east-1.amazonaws.com, as before). Runs on every start when install_kiro_cli = true (existing binaries are removed first because the official installer prompts on /dev/tty otherwise); with false, kiro-cli must be on PATH.
  • workdir is optional and created if missing.
  • agent_config is written to ~/.kiro/agents/<name>.json (honors KIRO_HOME) and set with kiro-cli settings chat.defaultAgent. MCP servers go in its mcpServers field, so there is no separate mcp input. Without it, Kiro's built-in default agent is used.
  • Add api_key (KIRO_API_KEY, documented auth method). auth_tarball is read from KIRO_CLI_AUTH_TARBALL at install time instead of being rendered into the script.
  • Add scripts output; README reduced to examples and doc links; rewrite tests. Bump to 2.0.0.

Important

MCP servers connecting was not verified: Kiro disables MCP unless signed in to a real account, and none was available. kiro-cli mcp add --agent writes the same inline mcpServers structure the module writes.

Decision log
Topic Kiro CLI reality Decision
Install Docs recommend curl -fsSL https://cli.kiro.dev/install | bash (latest only, glibc/musl detection); zip install documented at desktop-release.../latest/; versioned paths exist Installer for latest, release zip for pinned versions/mirrors
MCP Agent config mcpServers has the highest precedence; kiro-cli mcp add needs login No mcp variable; use agent_config.mcpServers
Default agent kiro-cli settings chat.defaultAgent works without login and preserves other keys Use the CLI (as the original module did), no jq
Validations Not present before None added; version and agent name are base64-encoded into the script
Auth Browser login first, then KIRO_API_KEY Add api_key; keep auth_tarball
Config dir KIRO_HOME overrides ~/.kiro Honored for the agent file

Testing

  • terraform test (6 passed), bun test main.test.ts (14 passed, container-based), terraform fmt, prettier, shellcheck
  • Dogfood workspace from a test template: official install (2.30.0), PATH and CODER_SCRIPT_BIN_DIR symlink, script order with a downstream coder exp sync script, agent file written and listed as default by kiro-cli agent list, user settings preserved, KIRO_API_KEY set and absent from scripts/logs, restart, pinned 2.29.0 downgrade via release zip, API key rotation

Generated with Coder Agents.

…s and start logic

- Replace the agentapi module with coder-utils; drop Tasks/web-app inputs, the start script, and the task-reporting coder MCP server.
- Install via the official installer for latest; pinned versions and mirrors use the release archive.
- Make workdir optional; add mcp (merged into ~/.kiro/settings/mcp.json) and api_key (KIRO_API_KEY).
- Keep agent_config and auth_tarball; the tarball is read from its env var instead of being rendered into the script.
- Add scripts output, rewrite README and tests, bump to 2.0.0.
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Module Scorecard Check

harleylrn/kiro-cli: first scorecard, 66 / 100

No specific score is required to contribute, but modules with higher scores are more likely to be approved by the Coder team and widely used.

Full scorecard for this PR
Presentation & Onboarding Agent Integration Credential Hygiene Restricted-Environment Readiness Engineering Quality Overall
12 / 17 10 / 25 20 / 20 12 / 20 7 / 10 66 / 100
Drilldown

Presentation & Onboarding — 12 / 17

Criterion Max Score Notes
Configuration-mode examples 12 12 README shows distinct documented modes: standalone launcher (coder_app), custom agent config with MCP servers, pinned version/internal mirror, and downstream script serialization via scripts output — each with sensible defaults and context.
Visual preview 5 0 No image, GIF, or video anywhere in the README.

Credential Hygiene — 20 / 20

Criterion Max Score Notes
Secrets marked sensitive 16 16 auth_tarball and api_key are sensitive = true; all README examples reference var.kiro_cli_auth_tarball/env vars rather than inline literal secrets, and tests assert secrets never land in rendered scripts.
Non-hardcoded auth path 4 4 README documents kiro-cli login flow and generating a pre-authenticated tarball as alternatives to hardcoding API keys.

Restricted-Environment Readiness — 12 / 20

Criterion Max Score Notes
Mirrorable artifact source 5 5 kiro_install_url variable overrides the base download URL used in install_from_archive (${base_url}/${ARG_VERSION}/kirocli-${arch}-linux.zip); README's "Pinned version or internal mirror" example demonstrates pointing it at https://artifacts.internal.corp/kiro-cli-releases.
Bring-your-own binary 10 5 install_kiro_cli = false variable and ensure_kiro_in_path fallback fully support a baked-in binary (confirmed in main.tf and tests), but README never shows an example setting this variable — only described in the variable's inline description, not in a README example/section.
Egress transparency 3 0 No dedicated README section enumerating install/runtime endpoints (cli.kiro.dev, desktop-release.q.us-east-1.amazonaws.com, custom mirror); URLs only appear scattered inside unrelated config examples.
Runs without sudo 2 2 Install script (install.sh.tftpl) never invokes sudo anywhere; all operations target $HOME.

Engineering Quality — 7 / 10

Criterion Max Score Notes
Input quality 6 3 All variables have clear descriptions and sensible defaults (e.g., install_kiro_cli = true, kiro_cli_version = "latest"), but no validation blocks exist anywhere in main.tf despite opportunities (e.g., validating agent_config JSON or kiro_cli_version format).
Test coverage 4 4 main.tftest.hcl covers business logic (defaults, workdir trimming, env var creation, scripts ordering) and main.test.ts covers end-to-end install/auth/agent-config behavior in containers.

Agent Integration — 10 / 25

Criterion Max Score Notes
AI governance 10 0 No mention of Coder AI Gateway or Agent Firewall anywhere in the README.
Dashboard entry point 5 5 README's "Standalone mode with a launcher app" example defines a full coder_app resource (slug, display_name, icon, open_in, command) launching kiro-cli chat.
Session continuity 5 0 No documentation of resuming sessions, session IDs, or a persistent session manager (tmux/screen/boo).
Managed configuration 5 5 agent_config variable documents writing an agent JSON (tools, MCP servers like playwright) and setting chat.defaultAgent, matching Kiro's agent-configuration format.

Overall — 66 / 100

Raw 61 / 92 → round(61 / 92 × 100) = 66

Tip

You can run this locally by telling your agent: "review this module against .github/scorecard/SCORECARD.md".


Scored against SCORECARD.md with solstice-1. Language-model scores are advisory.

…api removal and current docs

Drop the mcp variable (agent_config already accepts mcpServers), variable validations, and jq-based settings edits; set the default agent with kiro-cli settings. Use the documented release host for pinned installs and trim the README.
@linear-code

linear-code Bot commented Oct 13, 2026

Copy link
Copy Markdown

REG-87


```tf
module "kiro-cli" {
module "kiro_cli" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always use - in names and not _

@coder

coder Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Automated review requested by @matifali. Please sanity-check before acting on it.

Summary

The agentapi module is replaced with coder-utils@0.0.1. The start script, coder_ai_task/task_app_id, CODER_MCP_APP_STATUS_SLUG, the coder MCP server that called coder_report_task, the default agent template, and every Tasks/web-app input are removed. Kiro is installed with the official installer for latest, or from the release zip for a pinned version or mirror. api_key is new and workdir is now optional. Version goes 1.0.2 → 2.0.0 in all 5 README examples, which is correct for a breaking change.

Correctness

  • main.tf (122 lines) is self-consistent: every local and variable it references exists, and templatefile passes exactly the 6 args the template uses. The scripts output has a description. Secrets are sensitive and delivered only through coder_env.
  • The install flow makes sense: validate, or install and skip when a matching version is present, then workdir, auth tarball, agent config.

Leftovers

  • None in module code. A grep for report_task|agentapi|coder_ai_task|APP_STATUS|AGENTAPI_URL|3284|app_slug|ai_prompt|task_app|exp mcp|coder_task only hits the README migration note and the test helper import (see nit N4).

Findings

should-fix S1: upgraded workspaces keep the v1 Tasks agent as Kiro's default. scripts/install.sh.tftpl:234-238
v1 wrote ~/.kiro/agents/agent.json, a default agent with @coder tools and a coder MCP server: coder exp mcp server --allowed-tools coder_report_task with CODER_MCP_APP_STATUS_SLUG, CODER_MCP_AI_AGENTAPI_URL=http://localhost:3284, and a baked-in CODER_AGENT_TOKEN. It also ran kiro-cli settings chat.defaultAgent agent. In v2, with no agent_config, configure_agent returns early, so on a persistent home Kiro keeps loading that stale agent. Its MCP server points at a removed tool, AgentAPI, and an expired token. That contradicts the README (line 22), which says Kiro's built-in default agent is used.
Fix: when agent_config is unset and $KIRO_DIR/agents/agent.json is the legacy module file (e.g. its mcpServers.coder.args contain coder_report_task), remove it (or just its coder server) and clear chat.defaultAgent. Alternatively, document the manual cleanup in the migration note. Even with agent_config set, kiro-cli mcp remove --name coder --agent agent is worth running to clear the stale token-bearing entry.

should-fix S2: the migration note is incomplete compared with auggie and the AGENTS.md checklist ("Breaking changes documented: removed inputs, changed defaults"). README.md:22
It only names ai_prompt, system_prompt, and trust_all_tools. Missing:

  • Removed inputs: order, group, report_tasks, cli_app, web_app_display_name, cli_app_display_name, install_agentapi, agentapi_version, agentapi_chat_based_path, coder_mcp_instructions
  • The removed task_app_id output
  • workdir is now optional and only created; it's no longer the launch directory
  • Changed default and egress: kiro_install_url now defaults to null, and latest now downloads https://cli.kiro.dev/install instead of the desktop-release.q.us-east-1.amazonaws.com zip. Air-gapped or allowlisted deployments that relied on the old host need to know.

The auggie README warning (#1177, line 22) is a good template.

nit N1: pinned/mirror install dropped --no-confirm and doesn't detach stdin. scripts/install.sh.tftpl:151
v1 ran ./kirocli/install.sh --no-confirm. v2 runs KIRO_CLI_SKIP_SETUP=1 sh .../install.sh with inherited stdin. The PR says a downgrade was tested, but keeping --no-confirm and adding < /dev/null (as the official-installer path does at line 104) protects against the overwrite prompt the comment at lines 101-103 warns about.

nit N2: a broken existing binary aborts silently. scripts/install.sh.tftpl:170
Under set -euo pipefail, if kiro-cli --version fails, current=$(installed_kiro_version) exits the script with no message. Use current=$(installed_kiro_version || true) so it falls through to a reinstall.

nit N3: agent name isn't validated or tested. main.tf:101
try(jsondecode(var.agent_config).name, "agent") is used as a filename: a name like ../x writes outside agents/, and invalid JSON silently becomes agent.json. Old agent_name_extraction tftest coverage was dropped. Add a validation (can(jsondecode(var.agent_config)), plus a name regex such as ^[A-Za-z0-9_-]+$) and a tftest asserting base64encode("agent") when name is absent.

nit N4: tests still import from the agentapi module. main.test.ts:18-21 imports extractCoderEnvVars/writeExecutable from ../../../coder/modules/agentapi/test-util. claude-code does the same, so this is series-wide. If agentapi is later deleted, these tests break. Consider moving the helpers into ~test.

nit N5: provider constraint. main.tf:7 says coder >= 2.12, but coder-utils requires >= 2.13. Bump it for accuracy. (coder-utils README now shows 0.0.2; the whole series pins 0.0.1, so the bump is fine to leave to the series.)

nit N6: there's no README example for install_kiro_cli = false (bring your own binary), and no egress list. The scorecard flagged both.

Tests

  • kiro-cli.tftest.hcl (Tasks-centric) is replaced by main.tftest.hcl with 6 runs: defaults, workdir trim, api_key and auth_tarball env vars not rendered into the script, and scripts ordering.
  • main.test.ts was rewritten with 14 container tests covering bring-your-own binary, official installer, pinned archive, mirror, version match skip, download failure, workdir, agent config, no-agent-config, tarball extraction, zstd requirement, secret isolation, and pre/post scripts. Good, meaningful coverage.
  • Gaps: agent-name default (N3); upgrade-from-v1 cleanup (S1); kiro-cli settings failure handling.

CI and reviews

  • Passing: Validate Terraform output (runs TS tests, terraform tests, validate, shellcheck), lint, Check for typos and unformatted code, Validate README files.
  • Compare module scores against main was still in progress. The scorecard bot gave 69/100; its note about a tmux NOTE suggests it scored an earlier commit.
  • No human reviews or review comments, so nothing is unresolved. Only bot comments: Linear linkback and scorecard.

Series consistency

Consistent with claude-code and the rest of the series: coder-utils@0.0.1, module dir $HOME/.coder-modules/<ns>/<name>, optional workdir, scripts output, .tftpl with base64 args, README launcher coder_app example, required_version >= 1.9.

…_kiro_cli is true

Drop the installed-version skip, matching the other agent modules. The
official installer prompts on /dev/tty when kiro-cli already exists, so
remove the existing binaries before running it.
@35C4n0r

35C4n0r commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

Addressed review feedback in 3cc4dd1 and 27a7e5b:

  • Hyphenated module names (@matifali): README examples now use module "kiro-cli" and module.kiro-cli.scripts.
  • Installed-version check removed (automated review N2): with install_kiro_cli = true the module always installs, matching the other agent modules, so a broken existing binary no longer makes the script exit silently. The official installer prompts on /dev/tty when kiro-cli already exists (no --force bypass on Linux), so the existing binaries are removed first. A new test installs twice to cover restarts.
  • Migration note (automated review S2): lists the removed inputs and the task_app_id output, notes workdir is optional, and calls out that latest now installs from https://cli.kiro.dev/install while pinned versions still use desktop-release.q.us-east-1.amazonaws.com.

Re-tested in a dogfood workspace on the latest head: Kiro CLI 2.32.0 installed, scripts ran in order before a downstream coder exp sync script, agent written and set as default with user settings preserved, KIRO_API_KEY set. Restart reinstalled cleanly over the existing binary, and switching to a pinned 2.29.0 and back to latest worked.

@DevelopmentCats could you review?

Generated with Coder Agents.

@coder coder Bot mentioned this pull request Oct 20, 2026
4 of 9 tasks
greg-the-coder added a commit that referenced this pull request Oct 23, 2026
## Description

Adds a `coder-labs/kiro-crew` module. The module installs Kiro CLI and
Kiro Crew, starts the `kirocrew gateway` and a loopback token-minting
redirector, and exposes two subdomain apps: a visible tile that points
at the redirector, and a hidden dashboard app. Opening the tile mints a
short-lived gateway token and redirects to the dashboard, so it opens
already authenticated. At startup the module derives the dashboard
origin from the agent's `VSCODE_PROXY_URI` and from any
`workspace_proxy_hostnames`. The gateway trusts those origins (plus
optional extra origins) through `KIROCREW_CORS_ORIGINS`, and
`dashboard.url` is set to the primary origin. The redirector keeps the
browser on the primary deployment or workspace proxy it came through.

This is a port of a Kiro Crew prototype tested by @greg-the-coder,
adapted to registry conventions: `coder-utils` install/start scripts as
`.tftpl` files, `$HOME/.coder-modules/coder-labs/kiro-crew` data layout,
base64 for free-form inputs, the Builder ID token passed through
`coder_env` instead of being rendered into scripts, and Terraform plus
Bun tests with mocked installers.

<details>
<summary>Decision log / deviations from the prototype</summary>

- Raw `coder_script` replaced by `coder-utils` 0.0.2 (install + start).
Logs moved from `/tmp` to
`$HOME/.coder-modules/coder-labs/kiro-crew/logs/` (`install.log`,
`start.log`, `gateway.log`, `redirector.log`).
- Ports (8899 gateway, 8898 redirector), the redirector flow (`/healthz`
returns 200 without minting a token; `/` returns 302 to
`<dashboard>/?token=…`, or 503 while the gateway starts), healthchecks,
detached `setsid nohup` launch, port-based stale-process cleanup, the
userns sandbox fallback, `PYTHONPATH` unset, the pipx guard, and the
`extra_mcp_json` deep merge are preserved.
- `aws_builder_id_token` is exported as `KIRO_AWS_BUILDER_ID_TOKEN`
through `coder_env` (as in #1161) instead of being rendered into the
script and staged in a file.
- Installers download to a temp file, are syntax-checked, then run,
instead of `curl | sh`.
- Removed the unused `subdomain`, `install_prefix` and `log_path`
inputs. Added `dashboard_origin` (an override for the primary dashboard
origin), `workspace_proxy_hostnames`, `pre_install_script`,
`post_install_script`, `icon`, and the `scripts` output.
- The start script also frees the redirector port before relaunching.
- Generated helpers (`start-gateway.sh`, `redirect-gateway.py`,
`coder-origins.py`) are written to
`$HOME/.coder-modules/coder-labs/kiro-crew/scripts/` next to the
coder-utils scripts, not to Kiro Crew's `~/.kiro/crew` data directory.

</details>

<details>
<summary>Decision log: dashboard origins and workspace proxies</summary>

**Problem (reproduced on dogfood).** The module derived
`https://<slug>-dashboard--<ws>--<owner>.<access-host>` in Terraform.
Dogfood's wildcard is `*--apps.dogfood.cdr.dev`, and each workspace
proxy has its own (`*--apps.us-east-2.dogfood.cdr.dev`, ...). The
redirector sent every browser, on primary or on a proxy, to a host that
is not a valid app URL. The real dashboard hosts returned `Host header
not allowed.`, because the gateway allowlist is exact-match and fixed at
launch.

**Evidence.**
- Terraform cannot see the wildcard app hostname. The agent's
`VSCODE_PROXY_URI` is `<scheme>://` + the primary wildcard with `*`
replaced by `{{port}}--<agent>--<ws>--<owner>`
(`coderd/agentapi/manifest.go`), with no auth needed.
- Slug apps use `<slug>--<ws>--<owner>` without the agent
(`db2sdk.AppSubdomain`). Coder also routes the form that names the
agent.
- Coder's app proxy keeps the browser's `Host`
(`httputil.NewSingleHostReverseProxy` does not rewrite `req.Host`), so
the redirector can tell which hostname the browser used.
- Proxy wildcards come only from `/api/v2/regions`, which needs a user
token. The agent token gets 401.

**Decisions.**
1. Compute origins at startup in a stdlib-only Python helper. Primary
comes from `VSCODE_PROXY_URI`, plus each entry in the new
`workspace_proxy_hostnames`. Both slug forms are trusted. The old
Terraform-derived origin is only a last resort, and it logs a warning.
2. One snapshot (`~/.kiro/crew/coder-origins.json`) feeds both the
gateway allowlist and the redirector's exact `app host -> dashboard
origin` routes. The redirector only looks up the request `Host` and
never builds `Location` from it, so a token never goes to an origin
outside the allowlist. Unknown hosts, including unlisted proxies, go to
the primary origin.
3. No automatic proxy discovery. It would need
`data.coder_workspace_owner.me.session_token` inside the workspace.
coder-utils writes the start script to the persistent home volume, and
`coder_env` would expose the token to every process. Explicit
configuration was the safer tradeoff.
4. `dashboard_origin` still overrides the primary origin. When it is
set, `VSCODE_PROXY_URI` is ignored.
5. Redirects send `Cache-Control: no-store` and `Referrer-Policy:
no-referrer`.
6. The gateway allowlist is static, so adding a proxy requires a
workspace restart (documented).

</details>

## Type of Change

- [x] New module
- [ ] New template
- [ ] Bug fix
- [ ] Feature/enhancement
- [ ] Documentation
- [ ] Other

## Module Information

**Path:** `registry/coder-labs/modules/kiro-crew`  
**New version:** `v0.0.1`  
**Breaking change:** [ ] Yes [x] No

## Testing & Validation

- [x] Tests pass (`bun test`)
- [x] Code formatted (`bun fmt`)
- [x] Changes tested locally

- `terraform test`: 16 passed (plan for input-derived values; apply for
healthchecks, `coder_env`, and the `scripts` output).
- `bun test main.test.ts`: 13 passed. Covers cached and fresh installs,
`use_cached = false`, download failure, MCP write and merge, gateway and
redirector launch (302 with token, CORS origins, `dashboard.url`, token
env), 503 before the gateway is ready, replacing a stale listener, and a
missing binary, proxy-preserving redirects (including the agent-named
form, an explicit scheme and port, and unlisted or unrelated hosts
falling back to primary, with every redirect origin checked against the
gateway allowlist), the `dashboard_origin` override, and the fallback
without `VSCODE_PROXY_URI`. Installers and the gateway are mocked.
- `terraform_validate.sh`, `readmevalidation`, `shellcheck` (including
the rendered `.tftpl` scripts), and `validate_set_u_order.sh` pass.
- Live on dogfood (workspace on `j-kiro-crew-pr-1196`, running the
rendered start script): opening the tile via primary, us-east-2,
eu-central-1, and ap-southeast-2 redirected to the dashboard on the same
hostname and served the Kiro Crew page (HTTP 200). With no
`workspace_proxy_hostnames`, us-east-2 fell back to the primary
dashboard, which loaded.
- Not tested: Kiro login.

## Related Issues

The companion Kubernetes template is on branch
`superblink/coder-labs-kiro-crew-template` and will be opened as a
separate PR after this module is published, because it references
`registry.coder.com/coder-labs/kiro-crew/coder` 0.0.1.

---

Generated with Coder Agents using Claude

Created on behalf of @greg-the-coder

---------

Co-authored-by: coder[bot] <137810501+coder[bot]@users.noreply.github.com>
Co-authored-by: greg-the-coder <greg@coder.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.

2 participants