gestalt-mobile 0.44.1 → 0.44.3

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 (24) hide show
  1. package/README.md +22 -6
  2. package/dist/client/assets/index-DEVCzFB9.css +1 -0
  3. package/dist/client/assets/index-DYZT_mLU.js +108 -0
  4. package/dist/client/index.html +2 -2
  5. package/dist/server/server/composition.contracts.js +188 -3
  6. package/dist/server/server/composition.js +53 -12
  7. package/dist/server/server/features/agent-activity/registry.js +12 -2
  8. package/dist/server/server/features/autopilot/application/service.js +184 -61
  9. package/dist/server/server/features/autopilot/domain/executor-commands.js +28 -0
  10. package/dist/server/server/features/autopilot/domain/persisted-state-error.js +14 -0
  11. package/dist/server/server/features/autopilot/domain/plan-fingerprint.js +24 -0
  12. package/dist/server/server/features/autopilot/domain/supervised-lifecycle.js +33 -7
  13. package/dist/server/server/features/org-plan-checkpoint/application/validate.js +45 -16
  14. package/dist/server/server/features/sessions/application/resume-command.js +3 -1
  15. package/dist/server/server/platform/codex/session-runtime.js +49 -13
  16. package/dist/server/server/platform/persistence/migrate.js +1 -0
  17. package/dist/server/server/platform/persistence/sqlite-autopilot-store.js +73 -14
  18. package/dist/server/server/platform/persistence/sqlite-event-journal.js +16 -0
  19. package/dist/server/shared/contracts/attention-report.js +12 -0
  20. package/dist/server/shared/contracts/org-plan-health.js +21 -0
  21. package/dist/server/shared/contracts/plan-signal.js +2 -1
  22. package/package.json +1 -1
  23. package/dist/client/assets/index-6WgZCe9g.js +0 -107
  24. package/dist/client/assets/index-BKls66uM.css +0 -1
@@ -3,13 +3,14 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { checkpointTarget } from '../../autopilot/domain/supervised-lifecycle.js';
6
7
  /** Terminal roster entries remain visible and are not active implementation writers. */
7
8
  export function hasActiveL1Writer(snapshot, position) {
8
9
  return snapshot.subagents.some((child) => child.canonicalPosition === position &&
9
10
  ['working', 'awaitingAgent', 'awaitingHuman'].includes(child.state));
10
11
  }
11
12
  /** Expands a host-owned compact boundary signal from authoritative plan state. */
12
- export function resolveOrgPlanCheckpointSignal(kind, plan, planIdentity, publicationReason = null) {
13
+ export function resolveOrgPlanCheckpointSignal(kind, plan, planIdentity, publicationReason = null, completedTargets = [], pendingTarget) {
13
14
  if (kind === 'terminalReviewAccepted')
14
15
  return {
15
16
  version: 1,
@@ -17,16 +18,34 @@ export function resolveOrgPlanCheckpointSignal(kind, plan, planIdentity, publica
17
18
  planIdentity,
18
19
  verdict: 'ACCEPT',
19
20
  };
20
- const reviewedId = publicationReason?.match(/^review:([^:]{1,128}):REVIEWED$/)?.[1];
21
+ const pending = pendingTarget ? JSON.parse(pendingTarget) : undefined;
22
+ const reviewedId = (pending?.[0] === 'l1' ? pending[1] : undefined) ??
23
+ publicationReason?.match(/^review:([^:]{1,128}):REVIEWED$/)?.[1];
24
+ const completedId = (pending?.[0] === 'l2' ? pending[2] : undefined) ??
25
+ publicationReason?.match(/^l2:([^:]{1,128}):DONE$/)?.[1];
26
+ // Publication identifies the actual transition, regardless of list order.
27
+ // Without it, expand only an unambiguous boundary; never guess the last row.
28
+ const allReviewed = plan.steps.filter((step) => step.state === 'DONE' && step.reviewStatus === 'REVIEWED');
29
+ const unreportedReviewed = allReviewed.filter((step) => !completedTargets.includes(checkpointTarget('l1', step.id)));
30
+ const reviewed = reviewedId || !unreportedReviewed.length ? allReviewed : unreportedReviewed;
31
+ const allCompleted = plan.steps.flatMap((parent) => parent.reviewStatus === 'UNREVIEWED'
32
+ ? parent.children
33
+ .filter((child) => child.state === 'DONE' &&
34
+ (!completedId || child.id === completedId) &&
35
+ (pending?.[0] !== 'l2' || parent.id === pending[1]))
36
+ .map((child) => ({ parent, child }))
37
+ : []);
38
+ const unreportedCompleted = allCompleted.filter(({ parent, child }) => !completedTargets.includes(checkpointTarget('l2', parent.id, child.id)));
39
+ const completed = completedId || !unreportedCompleted.length ? allCompleted : unreportedCompleted;
21
40
  const selected = kind === 'l1Accepted'
22
- ? ((reviewedId
23
- ? plan.steps.find((step) => step.id === reviewedId && step.state === 'DONE' && step.reviewStatus === 'REVIEWED')
24
- : undefined) ??
25
- [...plan.steps]
26
- .reverse()
27
- .find((step) => step.state === 'DONE' && step.reviewStatus === 'REVIEWED'))
28
- : (plan.steps.find((step) => step.id === plan.currentStepId) ??
29
- [...plan.steps].reverse().find((step) => step.state === 'DONE' || step.state === 'WIP'));
41
+ ? reviewedId
42
+ ? reviewed.find((step) => step.id === reviewedId)
43
+ : reviewed.length === 1
44
+ ? reviewed[0]
45
+ : undefined
46
+ : completed.length === 1
47
+ ? completed[0]?.parent
48
+ : undefined;
30
49
  if (!selected)
31
50
  return null;
32
51
  const l1Position = `L${plan.steps.indexOf(selected) + 1}`;
@@ -40,7 +59,7 @@ export function resolveOrgPlanCheckpointSignal(kind, plan, planIdentity, publica
40
59
  verdict: 'ACCEPT',
41
60
  commit: { kind: 'notRequired' },
42
61
  };
43
- const child = [...selected.children].reverse().find((step) => step.state === 'DONE');
62
+ const child = completed[0]?.child;
44
63
  if (!child)
45
64
  return null;
46
65
  return {
@@ -65,10 +84,17 @@ export function validateOrgPlanCheckpoint(input) {
65
84
  return { valid: false, reasonCode: 'rootNotOwner' };
66
85
  if (checkpoint.planIdentity !== planIdentity)
67
86
  return { valid: false, reasonCode: 'planIdentityMismatch' };
68
- if (checkpoint.kind === 'terminalReviewAccepted')
69
- return plan.steps.every((step) => step.state === 'DONE' && step.reviewStatus === 'REVIEWED')
70
- ? { valid: true }
71
- : { valid: false, reasonCode: 'terminalReviewIncomplete' };
87
+ if (checkpoint.kind === 'terminalReviewAccepted') {
88
+ if (!plan.steps.length ||
89
+ !plan.steps.every((step) => step.state === 'DONE' && step.reviewStatus === 'REVIEWED'))
90
+ return { valid: false, reasonCode: 'terminalReviewIncomplete' };
91
+ for (const [index, step] of plan.steps.entries()) {
92
+ const result = validateCompletedChildren(step, input.hasActiveL1Writer(`L${index + 1}`));
93
+ if (!result.valid)
94
+ return result;
95
+ }
96
+ return { valid: true };
97
+ }
72
98
  const l1 = plan.steps.find((step) => step.id === checkpoint.l1Id);
73
99
  if (!l1)
74
100
  return { valid: false, reasonCode: 'l1NotFound' };
@@ -117,6 +143,9 @@ export function validateOrgPlanCheckpoint(input) {
117
143
  expected: { reviewStatus: 'REVIEWED' },
118
144
  observed: { reviewStatus: l1.reviewStatus ?? null },
119
145
  };
146
+ return validateCompletedChildren(l1, input.hasActiveL1Writer(position));
147
+ }
148
+ function validateCompletedChildren(l1, activeWriter) {
120
149
  const incompleteChild = l1.children.find((child) => child.state !== 'DONE');
121
150
  if (incompleteChild)
122
151
  return {
@@ -125,7 +154,7 @@ export function validateOrgPlanCheckpoint(input) {
125
154
  expected: { childrenDone: true },
126
155
  observed: { childrenDone: false, childState: incompleteChild.state },
127
156
  };
128
- if (input.hasActiveL1Writer(position))
157
+ if (activeWriter)
129
158
  return {
130
159
  valid: false,
131
160
  reasonCode: 'executorStillActive',
@@ -8,7 +8,9 @@ export function buildResumeCommand(session) {
8
8
  if (!session.threadId)
9
9
  throw new Error('THREAD_REQUIRED');
10
10
  return [
11
- 'codex',
11
+ 'gestalt',
12
+ 'cli',
13
+ '--',
12
14
  'resume',
13
15
  session.threadId,
14
16
  '-C',
@@ -10,6 +10,7 @@ import { canRebindMissingRollout, rebindMissingRollout, } from '../../features/s
10
10
  import { gestaltQuizDynamicTool } from '../../../shared/contracts/quiz.js';
11
11
  import { gestaltOrgPlanAttentionDynamicTool } from '../../../shared/contracts/org-plan-attention.js';
12
12
  import { gestaltOrgPlanCheckpointDynamicTool } from '../../../shared/contracts/org-plan-checkpoint.js';
13
+ import { gestaltOrgPlanHealthDynamicTool } from '../../../shared/contracts/org-plan-health.js';
13
14
  import { gestaltAutopilotWaitLeaseDynamicTool } from '../../../shared/contracts/autopilot-wait-lease.js';
14
15
  import { gestaltAgentCapacityRecoveryDynamicTool } from '../../../shared/contracts/agent-capacity-recovery.js';
15
16
  import { countDiffLines } from '../../../shared/contracts/file-change.js';
@@ -19,14 +20,13 @@ import { isCodexThreadWriterBusy, isMissingCodexThreadRollout } from './json-rpc
19
20
  import { resolvedServerRequestId } from './server-request.js';
20
21
  /** Sticky thread config keeps skill paths out of the app-server process argv. */
21
22
  export function threadSkillConfig(skillsConfig, modelConfig = {}) {
22
- return skillsConfig === undefined && !Object.keys(modelConfig).length
23
- ? {}
24
- : {
25
- config: {
26
- ...modelConfig,
27
- ...(skillsConfig === undefined ? {} : { skills: { config: skillsConfig } }),
28
- },
29
- };
23
+ return {
24
+ config: {
25
+ ...modelConfig,
26
+ 'tools.update_plan.enabled': true,
27
+ ...(skillsConfig === undefined ? {} : { skills: { config: skillsConfig } }),
28
+ },
29
+ };
30
30
  }
31
31
  /** One private owner for every resource acquired for a live Codex child. */
32
32
  class SessionResource {
@@ -341,6 +341,35 @@ export class CodexSessionRuntime {
341
341
  const token = this.sessions.get(sessionId)?.planMeasurementToken;
342
342
  return Boolean(token && authorization === `Bearer ${token}`);
343
343
  }
344
+ /** Activity needs status, not turn history (untouched threads may not support list_turns). */
345
+ async readActivity(session) {
346
+ if (!session.threadId)
347
+ throw new Error('CODEX_THREAD_ID_MISSING');
348
+ const owned = this.sessions.get(session.id);
349
+ const process = owned?.process ??
350
+ this.launch({ profile: session.profile, cwd: this.readerCwd ?? session.workspacePath });
351
+ try {
352
+ if (!owned)
353
+ await process.rpc.request('initialize', {
354
+ clientInfo: { name: 'gestalt-mobile', version: '0.1.0' },
355
+ capabilities: { experimentalApi: true },
356
+ });
357
+ const response = (await process.rpc.request('thread/read', {
358
+ threadId: session.threadId,
359
+ includeTurns: false,
360
+ }));
361
+ if (response?.thread?.id !== session.threadId)
362
+ throw new Error('CODEX_ACTIVITY_STATUS_UNAVAILABLE');
363
+ const status = response.thread.status?.type;
364
+ if (status !== 'idle' && status !== 'active')
365
+ throw new Error('CODEX_ACTIVITY_STATUS_UNAVAILABLE');
366
+ return { active: status === 'active' };
367
+ }
368
+ finally {
369
+ if (!owned)
370
+ process.close();
371
+ }
372
+ }
344
373
  async readHistory(session) {
345
374
  if (!session.threadId)
346
375
  throw new Error('CODEX_THREAD_ID_MISSING');
@@ -705,6 +734,7 @@ export class CodexSessionRuntime {
705
734
  gestaltQuizDynamicTool,
706
735
  gestaltOrgPlanAttentionDynamicTool,
707
736
  gestaltOrgPlanCheckpointDynamicTool,
737
+ gestaltOrgPlanHealthDynamicTool,
708
738
  gestaltAutopilotWaitLeaseDynamicTool,
709
739
  gestaltAgentCapacityRecoveryDynamicTool,
710
740
  ],
@@ -773,17 +803,22 @@ export class CodexSessionRuntime {
773
803
  return Promise.reject(new Error('CODEX_SERVER_REQUEST_DUPLICATE'));
774
804
  return new Promise((resolve, reject) => {
775
805
  resource.pendingRequests.set(requestId, { resolve, reject });
776
- let accepted = false;
806
+ const unsupported = () => {
807
+ if (resource.pendingRequests.delete(requestId))
808
+ reject(new Error('CODEX_SERVER_REQUEST_UNSUPPORTED'));
809
+ };
777
810
  try {
778
- accepted =
779
- this.onServerRequest?.(resource.sessionId, request, this.resolveNotificationOrigin(resource, request)) === true;
811
+ const accepted = this.onServerRequest?.(resource.sessionId, request, this.resolveNotificationOrigin(resource, request));
812
+ void Promise.resolve(accepted).then((value) => {
813
+ if (value !== true)
814
+ unsupported();
815
+ }, unsupported);
780
816
  }
781
817
  catch {
782
818
  // Publication failures are protocol failures, not permission to retain
783
819
  // an unreachable app-server request.
820
+ unsupported();
784
821
  }
785
- if (!accepted && resource.pendingRequests.delete(requestId))
786
- reject(new Error('CODEX_SERVER_REQUEST_UNSUPPORTED'));
787
822
  });
788
823
  }
789
824
  async startThread(process, session, skillsConfig, modelConfig = {}) {
@@ -798,6 +833,7 @@ export class CodexSessionRuntime {
798
833
  gestaltQuizDynamicTool,
799
834
  gestaltOrgPlanAttentionDynamicTool,
800
835
  gestaltOrgPlanCheckpointDynamicTool,
836
+ gestaltOrgPlanHealthDynamicTool,
801
837
  gestaltAutopilotWaitLeaseDynamicTool,
802
838
  gestaltAgentCapacityRecoveryDynamicTool,
803
839
  ],
@@ -28,6 +28,7 @@ function migrateWorkspaceGitDefaults(database) {
28
28
  }
29
29
  export function migrate(database) {
30
30
  database.exec(schema);
31
+ database.exec('CREATE TABLE IF NOT EXISTS autopilot_state_quarantine (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL REFERENCES relay_sessions(id) ON DELETE CASCADE, record_json TEXT NOT NULL, created_at TEXT NOT NULL)');
31
32
  database.exec("CREATE INDEX IF NOT EXISTS session_events_autopilot_audit_tail_v3 ON session_events(session_id, type, sequence DESC) WHERE type IN ('autopilot.continuation-scheduled','autopilot.control-issued','autopilot.turn-started','autopilot.turn-failed','autopilot.progress-reset','autopilot.final-rejected','autopilot.executor-resumed','autopilot.process-monitoring','autopilot.process-result-consumed','autopilot.process-terminated','autopilot.updated','org-plan.attention-required','org-plan.attention-resolved')");
32
33
  const columns = database.prepare('PRAGMA table_info(relay_sessions)').all();
33
34
  if (!columns.some((column) => column.name === 'effective_skill_selection_json'))
@@ -3,7 +3,10 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { disabledAutopilot, } from '../../features/autopilot/domain/autopilot-session.js';
7
+ import { AutopilotStateError } from '../../features/autopilot/domain/persisted-state-error.js';
6
8
  import { parsePersistedSupervisedLifecycle } from '../../features/autopilot/domain/supervised-lifecycle.js';
9
+ import { MAX_AUTOPILOT_RECORD_BYTES, parsePlanFingerprint, } from '../../features/autopilot/domain/plan-fingerprint.js';
7
10
  export class SqliteAutopilotStore {
8
11
  db;
9
12
  constructor(db) {
@@ -15,15 +18,20 @@ export class SqliteAutopilotStore {
15
18
  .get(sessionId);
16
19
  if (!row)
17
20
  return null;
21
+ return this.decodeRow(row);
22
+ }
23
+ decodeRow(row) {
18
24
  const lifecycle = parseLifecycle(row.lifecycle_json);
19
- if (![
20
- 'disabled',
21
- 'monitoring',
22
- 'backoff',
23
- 'attentionRequired',
24
- 'completed',
25
- 'safetyPaused',
26
- ].includes(String(row.state)) ||
25
+ if (Buffer.byteLength(JSON.stringify(row), 'utf8') > MAX_AUTOPILOT_RECORD_BYTES ||
26
+ (row.plan_fingerprint !== null && parsePlanFingerprint(row.plan_fingerprint) === undefined) ||
27
+ ![
28
+ 'disabled',
29
+ 'monitoring',
30
+ 'backoff',
31
+ 'attentionRequired',
32
+ 'completed',
33
+ 'safetyPaused',
34
+ ].includes(String(row.state)) ||
27
35
  ![
28
36
  'manualDisabled',
29
37
  'planRequired',
@@ -46,7 +54,7 @@ export class SqliteAutopilotStore {
46
54
  Number(row.no_progress_count) < 0 ||
47
55
  ![0, 1].includes(Number(row.requested_enabled)) ||
48
56
  lifecycle === null)
49
- return null;
57
+ throw new AutopilotStateError(String(row.session_id));
50
58
  return {
51
59
  sessionId: String(row.session_id),
52
60
  state: row.state,
@@ -63,16 +71,67 @@ export class SqliteAutopilotStore {
63
71
  };
64
72
  }
65
73
  save(state) {
66
- this.db
67
- .prepare('INSERT INTO autopilot_sessions (session_id,state,requested_enabled,plan_identity,plan_fingerprint,generation,no_progress_count,next_evaluation_at,last_control_id,stop_reason,lifecycle_json,updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(session_id) DO UPDATE SET state=excluded.state,requested_enabled=excluded.requested_enabled,plan_identity=excluded.plan_identity,plan_fingerprint=excluded.plan_fingerprint,generation=excluded.generation,no_progress_count=excluded.no_progress_count,next_evaluation_at=excluded.next_evaluation_at,last_control_id=excluded.last_control_id,stop_reason=excluded.stop_reason,lifecycle_json=excluded.lifecycle_json,updated_at=excluded.updated_at')
68
- .run(state.sessionId, state.state, state.requestedEnabled ? 1 : 0, state.planIdentity, state.planFingerprint, state.generation, state.consecutiveNoProgress, state.nextEvaluationAt, state.lastControlId, state.stopReason, state.executor || state.blocking || state.supervision || state.checkpoints
74
+ const lifecycleJson = [
75
+ state.executor,
76
+ state.blocking,
77
+ state.supervision,
78
+ state.checkpoints,
79
+ ].some((value) => value !== undefined)
69
80
  ? JSON.stringify({
70
81
  executor: state.executor,
71
82
  blocking: state.blocking,
72
83
  supervision: state.supervision,
73
84
  checkpoints: state.checkpoints,
74
85
  })
75
- : null, state.updatedAt);
86
+ : null;
87
+ // Use the reader's exact contract before any write (including transaction/outbox writes).
88
+ this.decodeRow({
89
+ session_id: state.sessionId,
90
+ state: state.state,
91
+ requested_enabled: state.requestedEnabled ? 1 : 0,
92
+ plan_identity: state.planIdentity,
93
+ plan_fingerprint: state.planFingerprint,
94
+ generation: state.generation,
95
+ no_progress_count: state.consecutiveNoProgress,
96
+ next_evaluation_at: state.nextEvaluationAt,
97
+ last_control_id: state.lastControlId,
98
+ stop_reason: state.stopReason,
99
+ lifecycle_json: lifecycleJson,
100
+ updated_at: state.updatedAt,
101
+ });
102
+ this.db
103
+ .prepare('INSERT INTO autopilot_sessions (session_id,state,requested_enabled,plan_identity,plan_fingerprint,generation,no_progress_count,next_evaluation_at,last_control_id,stop_reason,lifecycle_json,updated_at) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(session_id) DO UPDATE SET state=excluded.state,requested_enabled=excluded.requested_enabled,plan_identity=excluded.plan_identity,plan_fingerprint=excluded.plan_fingerprint,generation=excluded.generation,no_progress_count=excluded.no_progress_count,next_evaluation_at=excluded.next_evaluation_at,last_control_id=excluded.last_control_id,stop_reason=excluded.stop_reason,lifecycle_json=excluded.lifecycle_json,updated_at=excluded.updated_at')
104
+ .run(state.sessionId, state.state, state.requestedEnabled ? 1 : 0, state.planIdentity, state.planFingerprint, state.generation, state.consecutiveNoProgress, state.nextEvaluationAt, state.lastControlId, state.stopReason, lifecycleJson, state.updatedAt);
105
+ }
106
+ /** Explicit manual Off recovery only. Preserve the original row for local diagnosis. */
107
+ recoverInvalid(sessionId, now) {
108
+ this.db.exec('BEGIN IMMEDIATE');
109
+ try {
110
+ const row = this.db
111
+ .prepare('SELECT * FROM autopilot_sessions WHERE session_id = ?')
112
+ .get(sessionId);
113
+ if (row) {
114
+ try {
115
+ this.decodeRow(row);
116
+ }
117
+ catch (error) {
118
+ if (!(error instanceof AutopilotStateError))
119
+ throw error;
120
+ this.db
121
+ .prepare('INSERT INTO autopilot_state_quarantine (session_id,record_json,created_at) VALUES (?,?,?)')
122
+ .run(sessionId, JSON.stringify(row), now);
123
+ this.save(disabledAutopilot(sessionId, now));
124
+ this.db
125
+ .prepare("UPDATE autopilot_controls SET status = 'cancelled', updated_at = ? WHERE session_id = ? AND status = 'scheduled'")
126
+ .run(now, sessionId);
127
+ }
128
+ }
129
+ this.db.exec('COMMIT');
130
+ }
131
+ catch (error) {
132
+ this.db.exec('ROLLBACK');
133
+ throw error;
134
+ }
76
135
  }
77
136
  findControl(sessionId, controlId) {
78
137
  const row = this.db
@@ -180,7 +239,7 @@ export class SqliteAutopilotStore {
180
239
  function parseLifecycle(value) {
181
240
  if (value === null || value === undefined)
182
241
  return {};
183
- if (typeof value !== 'string' || value.length > 256_000)
242
+ if (typeof value !== 'string' || Buffer.byteLength(value, 'utf8') > MAX_AUTOPILOT_RECORD_BYTES)
184
243
  return null;
185
244
  try {
186
245
  return parsePersistedSupervisedLifecycle(JSON.parse(value)) ?? null;
@@ -3,6 +3,7 @@
3
3
  * Designed by Denis Roio <jaromil@dyne.org>
4
4
  * SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  */
6
+ import { boundedAttentionReport } from '../../../shared/contracts/attention-report.js';
6
7
  export const autopilotAuditEventTypes = [
7
8
  'autopilot.turn-started',
8
9
  'autopilot.turn-failed',
@@ -89,6 +90,21 @@ export class SqliteEventJournal {
89
90
  payload: JSON.parse(row.payload_json),
90
91
  }));
91
92
  }
93
+ /** Same-turn root final only: never borrow another session, child, or commentary. */
94
+ attentionReport(sessionId, turnId, requestedAt) {
95
+ const row = this.db
96
+ .prepare(`
97
+ SELECT substr(json_extract(payload_json, '$.text'), 1, 4001) AS text
98
+ FROM session_events
99
+ WHERE session_id = ? AND type = 'agentMessageCompleted' AND occurred_at >= ?
100
+ AND json_extract(payload_json, '$.turnId') = ?
101
+ AND json_extract(payload_json, '$.phase') = 'final_answer'
102
+ AND json_type(payload_json, '$.text') = 'text'
103
+ ORDER BY sequence DESC LIMIT 1
104
+ `)
105
+ .get(sessionId, requestedAt, turnId);
106
+ return boundedAttentionReport(row?.text);
107
+ }
92
108
  /** Bounded chronological tail for redacted timeline projections. */
93
109
  tail(sessionId, limit) {
94
110
  const safeLimit = Math.max(1, Math.min(limit, 200));
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ /** Presentation context only; supervisor prose never changes control authority. */
7
+ export function boundedAttentionReport(value) {
8
+ if (typeof value !== 'string' || !value.trim())
9
+ return undefined;
10
+ const text = value.trim();
11
+ return text.length <= 4_000 ? text : `${text.slice(0, 3_999)}…`;
12
+ }
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright (C) 2026 Dyne.org foundation
3
+ * Designed by Denis Roio <jaromil@dyne.org>
4
+ * SPDX-License-Identifier: AGPL-3.0-or-later
5
+ */
6
+ export const gestaltOrgPlanHealthDynamicTool = {
7
+ type: 'function',
8
+ name: 'gestalt_org_plan_health',
9
+ description: 'Read the current session’s authoritative Org execution health, using the same controller state as Mobile. Read-only; does not enable, resume, checkpoint, or change the Org Plan.',
10
+ inputSchema: { type: 'object', additionalProperties: false, properties: {} },
11
+ };
12
+ export function isOrgPlanHealthCall(input) {
13
+ if (input.method !== 'item/tool/call' || !input.params || typeof input.params !== 'object')
14
+ return false;
15
+ const params = input.params;
16
+ return (params.tool === gestaltOrgPlanHealthDynamicTool.name &&
17
+ params.arguments !== null &&
18
+ typeof params.arguments === 'object' &&
19
+ !Array.isArray(params.arguments) &&
20
+ Object.keys(params.arguments).length === 0);
21
+ }
@@ -15,5 +15,6 @@ export const planSignalReasons = [
15
15
  export function isPlanSignalReason(value) {
16
16
  return (typeof value === 'string' &&
17
17
  (planSignalReasons.includes(value) ||
18
- /^review:[A-Za-z0-9._-]{1,128}:REVIEWED$/.test(value)));
18
+ /^review:[A-Za-z0-9._-]{1,128}:REVIEWED$/.test(value) ||
19
+ /^l2:[A-Za-z0-9._-]{1,128}:(WIP|DONE)$/.test(value)));
19
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.44.1",
3
+ "version": "0.44.3",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",