wishforge-ide/apps/ide/policy/frontend.cjs
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

60 lines
2.7 KiB
JavaScript

const { ContainerModule, injectable } = require('@theia/core/shared/inversify');
const {
CollaborationFrontendContribution,
} = require('@theia/collaboration/lib/browser/collaboration-frontend-contribution');
const { CollaborationWorkspaceService } = require('@theia/collaboration/lib/browser/collaboration-workspace-service');
const { FrontendApplicationConfigProvider } = require('@theia/core/lib/browser/frontend-application-config-provider');
const { ConnectionProvider, SocketIoTransport } = require('open-collaboration-protocol');
const { io } = require('socket.io-client');
const { collaborationBase, createPrefixConnectionProvider } = require('../collaboration/client-factory.cjs');
Object.defineProperty(exports, '__esModule', { value: true });
// Register room commands only for this workspace's authenticated gateway route.
// An absent/mismatched URL keeps collaboration disabled with no public fallback.
class ScopedCollaborationContribution extends CollaborationFrontendContribution {
async scopedUrl() {
const url = await this.getCollaborationServerUrl();
return collaborationBase(url, window.location.href).href;
}
init() {
this.scopedUrl()
.then(() => this.setStatusBarEntryDefault())
.catch(() => {});
}
registerCommands(commands) {
this.scopedUrl()
.then(() => super.registerCommands(commands))
.catch(() => {});
}
async createConnectionProvider() {
const url = await this.scopedUrl();
return createPrefixConnectionProvider(
{ ConnectionProvider, SocketIoTransport, io },
{
url,
browserLocation: window.location.href,
client: FrontendApplicationConfigProvider.get().applicationName,
fetch: window.fetch.bind(window),
authenticationHandler: (token, metadata) => this.handleAuth(url, token, metadata),
// OCT tokens are instance-local; never reuse a different workspace token
// from the upstream global localStorage key.
userToken: undefined,
},
);
}
}
injectable()(ScopedCollaborationContribution);
// Every backend already belongs to one provisioned project. A guest's virtual
// collaboration URI must not overwrite the backend-wide default for other tabs.
class DedicatedWorkspaceService extends CollaborationWorkspaceService {
isRemoteSession() {
return true;
}
}
injectable()(DedicatedWorkspaceService);
module.exports.default = new ContainerModule((_bind, _unbind, _isBound, rebind) => {
require('./plugin-install-frontend.cjs').bindManagedExtensionNotice(_bind);
rebind(CollaborationWorkspaceService).to(DedicatedWorkspaceService).inSingletonScope();
rebind(CollaborationFrontendContribution).to(ScopedCollaborationContribution).inSingletonScope();
});