18 Commits

Author SHA1 Message Date
eust-w
a2a02f2978 🔒 Cap IDE launch codes and sessions per person
The gateway refused new launches once 1000 codes or sessions existed in
total, so one member could crowd everyone else out for as long as the
sessions lived. Each person now holds at most 20 of each; beyond that
their own oldest ends, and its open connections close at their next
check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 22:22:11 +08:00
eust-w
f82bc387b9 🔒 Block the workspace credential endpoint regardless of path case
Theia's Express routes match paths case-insensitively, so
/Wishforge-Internal/git-credential passed the gateway's check and reached
the endpoint with the workspace's connection token attached. The gateway
now compares the path in lower case and also refuses the bare prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 04:04:27 +08:00
eust-w
e89f11b396 feat: run the cloud IDE on the local k3s cluster
The local cluster deploys the IDE gateway, and the provisioner creates a
Theia workspace with an OCT sidecar per project in the tenant namespace.
`build` adds the ide, ide-gateway and oct-workspace images; `web`
forwards the workbench (3100) and the gateway (3101).

- On a local development cluster (WF_ALLOW_INSECURE_HTTP), the
  provisioner accepts the in-cluster HTTP platform Git and the localhost
  gateway for workspaces.
- Builds use a proxy from the host environment, at the address the VM
  sees the host at.
- `web` refuses ports already taken on the host, where kubectl would
  otherwise listen on ::1 only. Its defaults stay clear of the local
  development stack (3000, 4400).
- Pods reading the settings or secrets carry a digest of them, so a
  redeploy with changed settings rolls them.
- The IDE build context leaves out every local node_modules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 23:24:04 +08:00
eust-w
ed20bf640e fix: keep IDE collaboration sign-in alive, and label branch-run diffs
- OCT holds each login poll open for 30 seconds before answering. The
  gateway gave every upstream 30 seconds of silence, so creating a
  collaboration session failed with "Workspace upstream unavailable" once
  sign-in took that long, and raced at best.
- Collaboration requests now get at least 65 seconds; other upstreams
  keep 30 (upstreamTimeoutMs).
- A run that starts from a branch shows its checkpoint relative to that
  branch, so the branch's own commits, which merge too, are not in the
  diff. The run page now says so instead of "relative to the target
  branch".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 23:24:04 +08:00
eust-w
0bcfbc13dd feat(ide): push IDE work to ide/ branches and merge it through a verified wish
People's changes now reach the target branch the same way the agent's do. The
IDE credential carries a ref prefix and the Git service runs a pre-receive hook
on every push that refuses updates outside it, so the IDE can push only
`ide/` branches; the platform's own integration is unaffected.

- A wish may name a source branch. The run starts from that branch's head, the
  agent builds on it, and verification, repair rounds, merging onto a moved
  target and conflict repair work as before. A missing branch makes the run
  wait (git_storage) until it is pushed.
- Release risk is now computed from the target branch before integration, not
  from where the run started: a migration committed on the source branch would
  otherwise have been missed and could have skipped approval.
- Clones work on `ide/work`; a plain `git push` publishes it.
- The console lists a project's IDE branches with a button to submit a wish
  that merges one, and the new-wish form has a starting-point field; MCP
  `submit_wish` accepts `sourceBranch`. The Git service lists branches under
  a prefix for this (`POST /refs`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 19:17:14 +08:00
eust-w
6d2dcebe65 feat(ide): clone the project into IDE workspaces and push back through Git (FR-H2)
While someone has a workspace open, the gateway asks the API for a 15-minute
write token for the project's platform repository on behalf of that person
(membership and role checked each time) and delivers it to the workspace
backend. The backend writes it to a Git config file outside the repository
(a memory volume in Kubernetes) that the clone includes, and on the first
delivery clones the target branch into a folder named after the project. The
workspace cannot mint credentials itself, so access ends with the last
session.

- People commit and push to the target branch like with any Git server; the
  platform only accepts fast-forwards, and the next wish starts from that
  commit (covered end to end in the local loop test).
- Commits are authored by whoever opened the latest session, from the name and
  email in their sign-in; their own git config overrides it.
- Only the gateway can reach the delivery endpoint: it needs Theia's
  connection token, and the gateway refuses the path for browsers.
- The provisioner pins the workspace to its repository and lets the pod reach
  the Git service; the Kubernetes baseline admits that traffic. External
  repositories are not cloned.
- The local shared Theia clones each project into its own folder.
- The Theia image installs Git, and its stage is named theia: the default
  build target of that Dockerfile is the gateway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:52:37 +08:00
eust-w
0235248a69 fix(ide): send the person's token when launching an IDE session
The gateway's authorize() takes a credential object since sessions are
rechecked by user id, but /launch and /session still passed the bare token,
so every launch was refused with 401. The socket-based gateway tests that
would have caught it cannot run where opening ports is not permitted; a new
test drives the request handler in process with a fake fetch instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:52:22 +08:00
eust-w
b38db08eeb docs: align documentation with the code and write it in Chinese
Operations, development and architecture docs, the reference pages and the
component READMEs were rewritten against the code: every documented variable
exists, and the settings operators need (runtime image, Git service, listen
addresses, Runner targets, single-tenant gateway and provisioner bindings) are
documented.

Gaps the docs used to present as working are now stated as such: IDE
workspaces do not clone the project yet (FR-H2), and in Kubernetes mode
dependency installs and image builds have no network path until an egress
proxy and builder access exist. The Kubernetes README describes what the
provisioner creates, what the Runner needs in a target namespace, and the
cluster acceptance that is still outstanding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 18:01:39 +08:00
eust-w
7e04a779f0 ci: add a CI workflow and complete the image targets
- .github/workflows/ci.yml: format check, typecheck (including tests) and all
  unit tests with the provisioner tests; PostgreSQL migrations applied twice (the
  second run must find nothing) plus the PostgreSQL integration tests; IDE
  gateway, collaboration and policy tests against the IDE package's dependencies.
- runtime.Dockerfile gains web (Next.js production build) and provisioner
  (kubectl from an operator-supplied image) targets; tool images default to
  scratch so only the targets that need them fail without them.
- apps/ide/Dockerfile takes reviewed Node images as arguments and adds a slim
  gateway target.
- The Kubernetes provisioner also deletes a stopped generation's capability
  secrets, service accounts and network policy; volumes stay for diagnosis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:11:32 +08:00
eust-w
b810423990 feat: show code changes, verification output and lessons in the console
- Runs: a per-file diff of the latest checkpoint, verification evidence with each
  command's exit code, duration and output tail (and failed installs), the last
  failure that the repair round works on, and the integrated commit when a
  project without delivery completes.
- Projects: repository status with a retry for platform repositories, the
  project's lessons (list, add a convention, disable, delete) and runs filtered
  on the server; IDE texts describe the Git hand-off instead of the removed
  save barrier.
- Releases: the approval dialog shows the requirement, project, target
  environment (production flagged), verification commands and approval deadline
  from a new review endpoint; failed releases say why. Environments locked by a
  deployment with an unknown outcome can be unlocked after a confirmation.
- Errors are titled by HTTP status; secondary text and focus rings meet the
  contrast requirements; the mobile drawer leaves the tab order when closed and
  closes on Esc.
- Sessions: the web BFF refreshes access tokens with the refresh token for up to
  12 hours; IDE gateway sessions are renewed while in use (idle timeout 15 min,
  at most 12 h) and rechecked by the granted user, so revocation still applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 17:01:30 +08:00
eust-w
a9411f586b feat: run the whole loop locally with a local provisioner
Local development had no provisioner, so every wish stopped at "sandbox not
ready", and dev:all started neither the coordinator nor the deployer.

- The provisioner moves from apps/ide to apps/provisioner and gains a backend
  switch: `local` starts an executor and a verifier process per run generation
  on this host (WF_SANDBOX_MODE=host, own directories and run-scoped tokens,
  development mode only) and points workspaces at the local Theia; `kubernetes`
  keeps the Kata Jobs, now started with the image entrypoint instead of the npm dev
  script and allowed to reach the platform Git service.
- In development the resource grant needs no runtime image digest.
- setup:local is one idempotent script that creates or completes .env.local,
  including the deployment mode, provisioner and grant settings.
- dev:all starts Git, API, provisioner, coordinator, deployer and web; dev:ide
  starts Theia and the IDE gateway; ide:install and ide:build wrap the separate
  Theia package. npm test also runs the provisioner tests.
- Project settings accept the target branch and dependency install commands.
- Web development conveniences require WF_DEPLOYMENT_MODE=development.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:36:12 +08:00
eust-w
cce214f8fb feat: close the main loop from wish to integrated commit
Verification ran git inside the tree under test, kept no command output and
treated every infrastructure fault as a test failure; repairs went through an
executor lease the coordinator should not hold; and a project without delivery
could never succeed. This reworks the worker execution path and the control-plane
contracts it depends on.

- Verification exports the exact commit to a directory without .git, installs
  dependencies (network allowed) and runs the protected commands under
  bubblewrap in kata mode or directly in host mode; evidence records exit code,
  duration, digest, a redacted output tail and the isolation used. Production
  rejects host evidence. A failed installation waits as infrastructure.
- Waiting reasons are an enum with a redacted detail; dispatcher, GitHub and
  model-proxy states map onto it, and the console explains each one with a way out.
- Repairs are requested by the coordinator through /internal/runs/:id/repair;
  the control plane derives the failure summary from the verifier's evidence and
  enforces the repair budget. Continuing after the budget is spent grants one more
  round; a new requirement revision starts a fresh budget.
- Execution identities may only move a run within their own stages and only to
  running or waiting; success comes from integration evidence (no delivery
  configured) or deployment acceptance. The unused preview stage is gone.
- Integration fast-forwards when the target has not moved, merges and re-verifies
  otherwise, retries when a push finds the target moved, and turns merge conflicts
  into a repair round that merges the current target for the agent to resolve.
- Successful runs that needed a repair leave a project lesson; active lessons are
  injected into later prompts, and admins can list, add, disable and delete them.
- Executor progress (messages, commands, file changes, plan updates) is stored as
  normalized events; previously agent messages were recorded as the literal word
  "output". Provider failures keep the work as a checkpoint and wait as
  provider_error instead of failing the run.
- Workers declare WF_SANDBOX_MODE=host|kata (host refused in production),
  heartbeat with retries until the lease could have expired, and retry safe
  control-plane reads with backoff.
- tests/local-loop.test.ts runs the loop end to end with real Git, the in-process
  control plane behind its internal routes and a scripted agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 15:15:54 +08:00
eust-w
78ed117763 feat: make the deployment mode explicit and fail closed
Security-relevant behaviour (development tokens, loopback HTTP, inline
checkpoints, raw provider keys, optional verification profiles) was
keyed off NODE_ENV === 'production', so any deployment that forgot
NODE_ENV silently ran with development rules.

- @wishforge/contracts exports deploymentMode/isProduction/
  requireDeploymentMode. WF_DEPLOYMENT_MODE wins; misspelled values and
  development combined with NODE_ENV=production are rejected; NODE_ENV
  remains a fallback only for libraries and tests.
- All API, runtime, artifact, Git service and operator-script checks use
  isProduction.
- The API, worker, Git service and Runner refuse to start without an
  explicit WF_DEPLOYMENT_MODE; the IDE gateway treats anything other
  than an explicit development mode as production.
- The development seed loads .env.local before checking the mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 14:07:02 +08:00
eust-w
3931bf94f0 refactor: hand off between IDE and agents through Git only
The IDE carried a second, Theia-internal coordination system: multi-
client save barriers, a hash-chained snapshot store, IndexedDB draft
recovery, transferable debugger-control leases that intercepted
Theia's plugin RPC, Ed25519 actor assertions from the gateway, and an
API gate that blocked every agent integration while any IDE workspace
was open until a human imported a coordinated snapshot. It depended on
Theia internals, made F5 debugging require five environment variables
plus a gateway-signed header, and stalled agent runs. IDE and agents
now hand off through Git commits (docs/architecture.md ADR-7).

- Delete apps/ide/coordination, apps/ide/security, the policy
  extension's coordination/draft/DAP-guard/lifecycle-safety modules and
  the unused product.json; the policy extension keeps only the managed
  extension allow-list and scoped collaboration.
- API: workspace snapshot import/match/check routes are gone. The
  project integration lease (one integrating run per project, fenced)
  moves to domain/integration-lease.ts and is still enforced on
  integrate/build transitions and build evidence.
- Workspace lifecycle: pause/resume no longer requires a save barrier;
  automatic sleep needs 30 idle minutes and zero gateway connections,
  which the gateway now reports itself. The lifecycle/integration
  authorize relays and the gateway's assertion signing are removed;
  gateway edit roles match the contract roles.
- Worker: no snapshot matching, workspace-input gate or local lock
  file during integration; runtime workspace-snapshot is removed.
- Web: the snapshot import panel is removed from run detail.
- Provisioner workspaces no longer mount coordination state or the
  gateway public key; local setup no longer generates gateway keys.

The local Theia build under apps/ide/lib must be rebuilt to pick up the
slimmer policy extension.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:56:22 +08:00
eust-w
0ef99b1e6d style: add Prettier and EditorConfig, format the codebase
Adds prettier 3.9.8 (exact) with a shared config (single quotes,
120 columns, trailing commas), .prettierignore, .editorconfig and the
`format` / `format:check` scripts, then formats all TypeScript,
JavaScript, CSS, JSON and YAML sources.

Purely mechanical: no behaviour change. Typecheck passes, the vitest
suite and the 74 IDE node tests produce the same results as before
(socket-binding tests still cannot run inside this sandbox).
Previously the longest source line was ~3000 characters; reviewing the
following semantic changes now produces readable diffs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:32:43 +08:00
eust-w
86649af4d6 docs: rewrite architecture and restructure documentation
- docs/architecture.md replaces system-design.md: component map,
  run state machine with an explicit waiting-reason catalogue, key
  sequences (dispatch, execute/verify/repair, integrate, release,
  IDE launch, lessons), data model, API surface, identity and trust
  model, isolation modes (host for local development, kata for
  production), deployment topology, ADRs, known limitations and a
  requirement-to-test verification matrix.
- docs/development.md: local setup, one-command start, first wish,
  IDE, MCP and the test matrix (integration toggles are explicit).
- docs/operations.md: production prerequisites, explicit deployment
  mode, component configuration, Kubernetes provisioner, tenants and
  quotas, IDE gateway routing and lifecycle, delivery, monitoring,
  backup/restore, incident handling and known risks. Merges the former
  observability, recovery, billing-entitlements and runbook documents.
- Contract documents move to docs/reference/; evidence narratives that
  pointed at machine-local /private/tmp files are removed and the UI
  reference is rewritten for the target console.
- Delete docs for removed scope: workspace snapshot handoff and private
  application access.
- README rewritten as a concise entry point.

The documents describe the target state that the following
implementation commits realise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:29:46 +08:00
eust-w
f668a2bcbc docs: add product requirements and drop evidence-log documents
- docs/requirements.md is now the single source of product scope:
  positioning, glossary, an explicit definition of RSI (in-task
  self-repair, project lessons, versioned agent configuration with
  human promotion), roles, core journeys, prioritized functional
  requirements with acceptance criteria, non-functional requirements,
  explicit non-goals and milestones.
- Remove implementation-status-2026-10-17.md and
  acceptance-traceability.md. They were dated evidence logs pointing at
  machine-local /private/tmp files and referenced undefined "P0-P5"
  priorities; requirement-to-test traceability moves into the
  architecture document's verification matrix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:21:19 +08:00
eust-w
b47a07e8d2 chore: baseline snapshot of the Codex-delivered code before review
Imports the previously untracked working tree as-is so that the review
changes that follow (requirements -> design -> implementation) can be
reviewed as diffs and reverted if needed. No content changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 13:18:04 +08:00