gestalt-mobile 0.68.4 → 0.68.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +15 -4
  2. package/dist/client/assets/index-Dl5gXKZh.js +183 -0
  3. package/dist/client/index.html +1 -1
  4. package/dist/server/server/composition.contracts.js +232 -12
  5. package/dist/server/server/composition.js +111 -29
  6. package/dist/server/server/features/plans/application/plan-attachment-supervision.js +3 -1
  7. package/dist/server/server/features/plans/application/prepare-org-plan-supervision.js +18 -10
  8. package/dist/server/server/features/plans/application/start-org-plan-supervision.js +23 -4
  9. package/dist/server/server/features/plans/execute-plan/endpoint.js +1 -1
  10. package/dist/server/server/features/sessions/application/workspace-conflict.js +19 -0
  11. package/dist/server/server/features/sessions/application/writer-acquisition.js +7 -0
  12. package/dist/server/server/features/sessions/forget-session/endpoint.js +7 -0
  13. package/dist/server/server/features/sessions/forget-session/use-case.js +8 -2
  14. package/dist/server/server/features/sessions/register-routes.js +1 -0
  15. package/dist/server/server/features/sessions/restore-session/endpoint.js +10 -1
  16. package/dist/server/server/features/sessions/start-session/endpoint.js +8 -0
  17. package/dist/server/server/features/sessions/start-turn/use-case.js +13 -1
  18. package/dist/server/server/platform/codex/error-code.js +2 -2
  19. package/dist/server/server/platform/codex/protocol-compatibility.js +7 -24
  20. package/dist/server/server/platform/codex/session-runtime.js +18 -0
  21. package/dist/server/server/platform/http/problem-handler.js +9 -0
  22. package/dist/server/server/platform/kimi/kimi-session-runtime.js +5 -0
  23. package/dist/server/server/platform/persistence/migrate.js +17 -0
  24. package/dist/server/server/platform/persistence/sqlite-event-journal.js +6 -2
  25. package/dist/server/server/platform/persistence/sqlite-forget-operation-store.js +38 -6
  26. package/dist/server/server/platform/persistence/sqlite-org-plan-launch-store.js +43 -16
  27. package/dist/server/server/platform/persistence/sqlite-session-repository.js +29 -7
  28. package/dist/server/server/platform/persistence/sqlite-workspace-lifecycle.js +59 -0
  29. package/dist/server/server/platform/plans/filesystem-plan-status-source.js +2 -2
  30. package/dist/server/server/platform/scratch/filesystem-session-scratch.js +3 -1
  31. package/dist/server/server/platform/scratch/filesystem-workspace-forget.js +123 -0
  32. package/dist/server/shared/contracts/org-plan-execution.js +1 -1
  33. package/dist/server/shared/contracts/plan-signal.js +2 -1
  34. package/package.json +1 -1
  35. package/dist/client/assets/index-CKyExrMf.js +0 -183
@@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-CKyExrMf.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-Dl5gXKZh.js"></script>
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-CCTlWqX8.css">
21
21
  </head>
22
22
  <body>
@@ -143,10 +143,10 @@ function liveAppServer(handles) {
143
143
  };
144
144
  };
145
145
  }
146
- async function createComposedSession(app) {
146
+ async function createComposedSession(app, workspaceName = 'workspace') {
147
147
  const workspace = (await app.inject('/api/bootstrap'))
148
148
  .json()
149
- .workspaces[0]?.children.find((item) => item.name === 'workspace');
149
+ .workspaces[0]?.children.find((item) => item.name === workspaceName);
150
150
  expect(workspace).toBeDefined();
151
151
  const created = await app.inject({
152
152
  method: 'POST',
@@ -460,7 +460,7 @@ async function createUnauthorizedProductionApp(root, dataDir) {
460
460
  installedCodexVersion: null,
461
461
  });
462
462
  }
463
- async function orgPlanActivationFixture() {
463
+ async function orgPlanActivationFixture(installedCodexVersion = 'codex-cli 0.144.3') {
464
464
  const root = await mkdtemp(join(tmpdir(), 'gestalt-plan-activation-root-'));
465
465
  const dataDir = await mkdtemp(join(tmpdir(), 'gestalt-plan-activation-state-'));
466
466
  ownTemporaryPaths(root, dataDir);
@@ -487,7 +487,7 @@ async function orgPlanActivationFixture() {
487
487
  root,
488
488
  dataDir,
489
489
  relyingParty,
490
- installedCodexVersion: 'codex-cli 0.144.3',
490
+ installedCodexVersion,
491
491
  startAppServers: true,
492
492
  sessionModelCatalog: { list: async () => ['gpt-6.1-sol', 'gpt-5.6-terra'] },
493
493
  profiles: {
@@ -1865,6 +1865,21 @@ describe('production composition', () => {
1865
1865
  expect(opened.statusCode).toBe(200);
1866
1866
  expect(opened.json()).toMatchObject({ title: 'Autopilot fixture', allDone: false });
1867
1867
  expect((await app.inject(`/api/sessions/${sessionId}/plan`)).statusCode).toBe(200);
1868
+ expect((await app.inject(`/api/sessions/${sessionId}`)).json()).toMatchObject({
1869
+ lastOrgPlan: { supervision: false },
1870
+ autopilot: { enabled: false },
1871
+ });
1872
+ // This coordinator fixture begins execution through the supervisor's explicit
1873
+ // helper publication, independently of the passive visualizer attachment.
1874
+ await writeFile(planStatusFilePath(planStatusDirectoryPath(workspacePath, sessionId), planPath), JSON.stringify({
1875
+ schemaVersion: 1,
1876
+ planPath,
1877
+ reason: 'supervision-start',
1878
+ updatedAt: new Date().toISOString(),
1879
+ }));
1880
+ await vi.waitFor(async () => expect((await app.inject(`/api/sessions/${sessionId}`)).json()).toMatchObject({
1881
+ lastOrgPlan: { supervision: true },
1882
+ }));
1868
1883
  await app.listen({ host: '127.0.0.1', port: 0 });
1869
1884
  const address = app.server.address();
1870
1885
  if (!address || typeof address === 'string')
@@ -1963,6 +1978,8 @@ describe('production composition', () => {
1963
1978
  ownTemporaryPaths(root, dataDir);
1964
1979
  const workspacePath = join(root, 'workspace');
1965
1980
  await mkdir(workspacePath);
1981
+ const otherWorkspace = join(root, 'workspace-other');
1982
+ await mkdir(otherWorkspace);
1966
1983
  const handles = [];
1967
1984
  const app = await composeAuthorizedApp({
1968
1985
  root,
@@ -1982,7 +1999,10 @@ describe('production composition', () => {
1982
1999
  });
1983
2000
  onTestFinished(() => app.close());
1984
2001
  // Managed TMPDIR fixtures share an ancestor publication fence during session creation.
1985
- const sessions = [await createComposedSession(app), await createComposedSession(app)];
2002
+ const sessions = [
2003
+ await createComposedSession(app),
2004
+ await createComposedSession(app, 'workspace-other'),
2005
+ ];
1986
2006
  await vi.waitFor(async () => expect(await Promise.all(sessions.map(async (sessionId) => (await app.inject(`/api/sessions/${sessionId}`)).json().state))).toEqual(['ready', 'ready']));
1987
2007
  const planText = `#+TITLE: Autopilot fixture
1988
2008
  * WIP [#A] Parent
@@ -2004,9 +2024,10 @@ describe('production composition', () => {
2004
2024
  - Done when :: The plan remains incomplete.
2005
2025
  `;
2006
2026
  await Promise.all(sessions.map(async (sessionId, index) => {
2007
- const planPath = join(workspacePath, `autopilot-${index}.org`);
2027
+ const selectedWorkspace = index === 0 ? workspacePath : otherWorkspace;
2028
+ const planPath = join(selectedWorkspace, `autopilot-${index}.org`);
2008
2029
  await writeFile(planPath, planText);
2009
- await writeFile(planStatusFilePath(planStatusDirectoryPath(workspacePath, sessionId), planPath), JSON.stringify({
2030
+ await writeFile(planStatusFilePath(planStatusDirectoryPath(selectedWorkspace, sessionId), planPath), JSON.stringify({
2010
2031
  schemaVersion: 1,
2011
2032
  planPath,
2012
2033
  reason: 'supervision-start',
@@ -4303,8 +4324,10 @@ describe('production composition', () => {
4303
4324
  },
4304
4325
  });
4305
4326
  onTestFinished(() => fixture.app.close());
4306
- const peer = await createComposedSession(fixture.app);
4307
- await installAutopilotPlan(fixture.app, peer, fixture.workspacePath, 'peer-plan');
4327
+ const peerWorkspace = join(fixture.root, 'workspace-peer');
4328
+ await mkdir(peerWorkspace);
4329
+ const peer = await createComposedSession(fixture.app, 'workspace-peer');
4330
+ await installAutopilotPlan(fixture.app, peer, peerWorkspace, 'peer-plan');
4308
4331
  const starts = () => fixture.handles
4309
4332
  .flatMap((handle) => handle.requests)
4310
4333
  .filter((request) => request.method === 'turn/start');
@@ -5689,7 +5712,8 @@ describe('production composition', () => {
5689
5712
  });
5690
5713
  expect(transitions).toBeDefined();
5691
5714
  const sessionA = await createComposedSession(app);
5692
- const sessionB = await createComposedSession(app);
5715
+ await mkdir(join(root, 'workspace-peer'));
5716
+ const sessionB = await createComposedSession(app, 'workspace-peer');
5693
5717
  const handleA = await vi.waitFor(() => {
5694
5718
  const handle = handles.find((candidate) => candidate.calls.includes('thread/start'));
5695
5719
  expect(handle?.request).toBeDefined();
@@ -5918,7 +5942,8 @@ describe('production composition', () => {
5918
5942
  launchAppServer: liveAppServer(handles),
5919
5943
  });
5920
5944
  const supportedSession = await createComposedSession(first);
5921
- const legacySession = await createComposedSession(first);
5945
+ await mkdir(join(root, 'workspace-legacy'));
5946
+ const legacySession = await createComposedSession(first, 'workspace-legacy');
5922
5947
  await vi.waitFor(() => expect(handles.filter((handle) => handle.calls.includes('thread/start'))).toHaveLength(2));
5923
5948
  const started = handles.filter((handle) => handle.calls.includes('thread/start'));
5924
5949
  const supportedRequest = started[0].request(attentionCall(901));
@@ -5980,6 +6005,127 @@ describe('production composition', () => {
5980
6005
  });
5981
6006
  });
5982
6007
  describeCompositionConcern('lifecycle', () => {
6008
+ it('requires the prior session to stop, then fences it while a supervisor owns its workspace', async () => {
6009
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6010
+ const app = await f.open();
6011
+ try {
6012
+ const idleId = await createComposedSession(app);
6013
+ const payload = await f.prepare(app);
6014
+ const busy = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6015
+ expect(busy).toMatchObject({
6016
+ kind: 'blocked',
6017
+ code: 'WORKSPACE_BUSY',
6018
+ existingSessionId: idleId,
6019
+ });
6020
+ expect((await app.inject({ method: 'POST', url: `/api/sessions/${idleId}/stop` })).statusCode).toBe(202);
6021
+ const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6022
+ expect(launched).toMatchObject({ kind: 'started' });
6023
+ expect(launched.session.id).not.toBe(idleId);
6024
+ const otherTurn = await app.inject({
6025
+ method: 'POST',
6026
+ url: `/api/sessions/${idleId}/turns`,
6027
+ payload: { text: 'Continue work' },
6028
+ });
6029
+ expect(otherTurn.statusCode).toBe(409);
6030
+ expect(otherTurn.json()).toMatchObject({ code: 'SESSION_WORKSPACE_LOCKED' });
6031
+ expect(f.requests('turn/start')).toHaveLength(1);
6032
+ expect((await app.inject({ method: 'DELETE', url: `/api/sessions/${launched.session.id}` }))
6033
+ .statusCode).toBe(204);
6034
+ expect(await createComposedSession(app)).toEqual(expect.any(String));
6035
+ }
6036
+ finally {
6037
+ await app.close();
6038
+ }
6039
+ });
6040
+ it('blocks Execute while another session has accepted work in the workspace', async () => {
6041
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6042
+ const app = await f.open();
6043
+ try {
6044
+ const id = await createComposedSession(app);
6045
+ const payload = await f.prepare(app);
6046
+ expect((await app.inject({
6047
+ method: 'POST',
6048
+ url: `/api/sessions/${id}/turns`,
6049
+ payload: { text: 'Work' },
6050
+ })).statusCode).toBe(202);
6051
+ const launch = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6052
+ expect(launch).toMatchObject({
6053
+ kind: 'blocked',
6054
+ code: 'ACTIVE_SUPERVISION',
6055
+ existingSessionId: id,
6056
+ });
6057
+ expect(launch.reason).toContain('Stop its work');
6058
+ expect((await app.inject('/api/sessions')).json()).toHaveLength(1);
6059
+ }
6060
+ finally {
6061
+ await app.close();
6062
+ }
6063
+ });
6064
+ it('executes a validated plan on Codex 0.167.0 with supervision instructions and exclusive workspace ownership', async () => {
6065
+ const f = await orgPlanActivationFixture('codex-cli 0.167.0');
6066
+ const app = await f.open();
6067
+ try {
6068
+ const payload = await f.prepare(app);
6069
+ const launched = (await app.inject({ method: 'POST', url: '/api/plans/execute', payload })).json();
6070
+ expect(launched).toMatchObject({ kind: 'started', bootstrap: { kind: 'accepted' } });
6071
+ const turns = f.requests('turn/start');
6072
+ expect(turns).toHaveLength(1);
6073
+ expect(JSON.stringify(turns[0].params)).toContain('Use $gestalt:org-plan');
6074
+ expect(JSON.stringify(turns[0].params)).toContain('.gestalt/activation.org');
6075
+ const prepare = (await app.inject({
6076
+ method: 'POST',
6077
+ url: '/api/plans/prepare',
6078
+ payload: payload.reference,
6079
+ })).json();
6080
+ expect(prepare).toMatchObject({
6081
+ kind: 'blocked',
6082
+ code: 'ACTIVE_SUPERVISION',
6083
+ existingSessionId: launched.session.id,
6084
+ });
6085
+ const other = await app.inject({
6086
+ method: 'POST',
6087
+ url: '/api/sessions',
6088
+ payload: {
6089
+ workspaceId: payload.reference.workspaceId,
6090
+ profile: 'default',
6091
+ provider: 'codex',
6092
+ model: 'gpt-6.1-sol',
6093
+ },
6094
+ });
6095
+ expect(other.statusCode).toBe(409);
6096
+ expect(other.json()).toMatchObject({ code: 'SESSION_WORKSPACE_LOCKED' });
6097
+ expect((await app.inject('/api/sessions')).json()).toHaveLength(1);
6098
+ expect(f.requests('thread/start')).toHaveLength(1);
6099
+ }
6100
+ finally {
6101
+ await app.close();
6102
+ }
6103
+ });
6104
+ it.each(['codex-cli 0.166.0', 'codex-cli 1.0.0', 'custom development build', null])('explains the exact Codex admission blocker for %s', async (version) => {
6105
+ const f = await orgPlanActivationFixture(version);
6106
+ const app = await f.open();
6107
+ try {
6108
+ const workspace = (await app.inject('/api/bootstrap'))
6109
+ .json()
6110
+ .workspaces[0].children.find((item) => item.name === 'workspace');
6111
+ const result = (await app.inject({
6112
+ method: 'POST',
6113
+ url: '/api/plans/prepare',
6114
+ payload: {
6115
+ kind: 'workspace',
6116
+ workspaceId: workspace.id,
6117
+ planName: '.gestalt/activation.org',
6118
+ },
6119
+ })).json();
6120
+ expect(result).toMatchObject(version ? { kind: 'eligible' } : { kind: 'blocked', code: 'CODEX_NOT_FOUND' });
6121
+ if (!version)
6122
+ expect(result.reason).toContain('not found');
6123
+ expect(f.requests('thread/start')).toHaveLength(0);
6124
+ }
6125
+ finally {
6126
+ await app.close();
6127
+ }
6128
+ });
5983
6129
  it('recovers a published Org-plan supervisor after initial runtime failure without replacing its session', async () => {
5984
6130
  const f = await orgPlanActivationFixture();
5985
6131
  const app = await f.open();
@@ -6684,7 +6830,12 @@ describe('production composition', () => {
6684
6830
  launchId: 'after-forget',
6685
6831
  },
6686
6832
  })).json();
6687
- expect(nextLaunch).toMatchObject(recoveryScenario === 'uncertain-manual'
6833
+ expect(nextLaunch, JSON.stringify({
6834
+ kind: nextLaunch.kind,
6835
+ stage: nextLaunch.stage,
6836
+ reason: nextLaunch.reason,
6837
+ state: nextLaunch.session?.state,
6838
+ })).toMatchObject(recoveryScenario === 'uncertain-manual'
6688
6839
  ? { kind: 'partial', stage: 'bootstrap', bootstrap: { kind: 'pending' } }
6689
6840
  : { kind: 'started', bootstrap: { kind: 'accepted' } });
6690
6841
  expect(nextLaunch.session.id).not.toBe(id);
@@ -6820,6 +6971,75 @@ describe('production composition', () => {
6820
6971
  runtimeStart.mockRestore();
6821
6972
  }
6822
6973
  });
6974
+ it.each(['TODO', 'WIP'])('keeps a validated %s plan passive in the visualizer until Execute is confirmed', async (state) => {
6975
+ const f = await orgPlanActivationFixture();
6976
+ let app = await f.open();
6977
+ try {
6978
+ const authorId = await createComposedSession(app);
6979
+ const planPath = join(f.workspacePath, '.gestalt', 'activation.org');
6980
+ await writeFile(planPath, state === 'TODO' ? autopilotPlanText().replace('* WIP', '* TODO') : autopilotPlanText());
6981
+ for (let opened = 0; opened < 2; opened++) {
6982
+ const view = await app.inject({
6983
+ method: 'PUT',
6984
+ url: `/api/sessions/${authorId}/plan`,
6985
+ payload: { planName: '.gestalt/activation.org' },
6986
+ });
6987
+ expect(view.statusCode, view.body).toBe(200);
6988
+ expect((await app.inject(`/api/sessions/${authorId}`)).json()).toMatchObject({
6989
+ lastOrgPlan: { attached: true, supervision: false },
6990
+ autopilot: { enabled: false },
6991
+ });
6992
+ await f.prepare(app);
6993
+ expect(f.requests('turn/start')).toHaveLength(0);
6994
+ expect(f.database((db) => db.prepare('SELECT count(*) AS n FROM org_plan_launches').get())).toEqual({ n: 0 });
6995
+ }
6996
+ // A deliberate Execute must report the occupied workspace and release
6997
+ // its unpublished claim, rather than poisoning all subsequent retries.
6998
+ const busyInput = await f.prepare(app);
6999
+ const busy = await app.inject({
7000
+ method: 'POST',
7001
+ url: '/api/plans/execute',
7002
+ payload: busyInput,
7003
+ });
7004
+ expect(busy.statusCode, busy.body).toBe(409);
7005
+ expect(busy.json()).toMatchObject({
7006
+ kind: 'blocked',
7007
+ code: 'WORKSPACE_BUSY',
7008
+ existingSessionId: authorId,
7009
+ });
7010
+ expect(f.requests('turn/start')).toHaveLength(0);
7011
+ expect((await app.inject('/api/sessions')).json()).toHaveLength(1);
7012
+ await app.close();
7013
+ await rm(planStatusDirectoryPath(f.workspacePath, authorId), {
7014
+ recursive: true,
7015
+ force: true,
7016
+ });
7017
+ app = await f.open();
7018
+ await app.listen({ host: '127.0.0.1', port: 0 });
7019
+ expect((await app.inject(`/api/sessions/${authorId}`)).json()).toMatchObject({
7020
+ lastOrgPlan: { attached: true, supervision: false },
7021
+ autopilot: { enabled: false },
7022
+ });
7023
+ expect(f.requests('turn/start')).toHaveLength(0);
7024
+ const input = await f.prepare(app);
7025
+ const execute = await app.inject({
7026
+ method: 'POST',
7027
+ url: '/api/plans/execute',
7028
+ payload: input,
7029
+ });
7030
+ expect(execute.json()).toMatchObject({
7031
+ kind: 'started',
7032
+ bootstrap: { kind: 'accepted' },
7033
+ });
7034
+ expect(f.requests('turn/start')).toHaveLength(1);
7035
+ const supervisorId = execute.json().session.id;
7036
+ expect(supervisorId).not.toBe(authorId);
7037
+ expect((await app.inject(`/api/sessions/${authorId}`)).json().autopilot.enabled).toBe(false);
7038
+ }
7039
+ finally {
7040
+ await app.close();
7041
+ }
7042
+ });
6823
7043
  it.each(['authoring-start', 'resync'])('executes a draft retained through %s in one new supervisor, including after restart', async (reason) => {
6824
7044
  const f = await orgPlanActivationFixture();
6825
7045
  let app = await f.open();