@cortex-agent/server 2026.9.14 → 2026.9.15

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 (102) hide show
  1. package/defaults/plugins/cortex-commission/.claude-plugin/plugin.json +2 -2
  2. package/defaults/plugins/cortex-commission/plugin.json +2 -2
  3. package/defaults/plugins/cortex-commission/skills/commission/SKILL.md +3 -3
  4. package/dist/agent-adapter/claude/adapter.d.ts +0 -6
  5. package/dist/agent-adapter/claude/adapter.js +0 -8
  6. package/dist/agent-adapter/claude/defaults.d.ts +10 -7
  7. package/dist/agent-adapter/claude/defaults.js +18 -16
  8. package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
  9. package/dist/agent-adapter/claude/spawn-args.js +16 -16
  10. package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +11 -2
  11. package/dist/agent-adapter/pi/mcp-bridge-logic.js +32 -1
  12. package/dist/agent-adapter/pi/mcp-bridge.js +16 -15
  13. package/dist/agent-adapter/pi/session-options.d.ts +0 -6
  14. package/dist/agent-adapter/pi/session-options.js +1 -8
  15. package/dist/agent-adapter/types.d.ts +0 -1
  16. package/dist/core/mcp-tool-gate.d.ts +3 -17
  17. package/dist/core/mcp-tool-gate.js +3 -19
  18. package/dist/core/settings-spec.d.ts +1 -1
  19. package/dist/core/settings-spec.js +5 -1
  20. package/dist/domain/agents/config.d.ts +1 -1
  21. package/dist/domain/agents/config.js +1 -1
  22. package/dist/domain/agents/profile-switch.d.ts +1 -1
  23. package/dist/domain/agents/profile-switch.js +3 -5
  24. package/dist/domain/agents/subagent/runner.js +0 -1
  25. package/dist/domain/commissions/commission-draft.d.ts +58 -0
  26. package/dist/domain/commissions/commission-draft.js +87 -4
  27. package/dist/domain/commissions/commission-finalize.d.ts +8 -3
  28. package/dist/domain/commissions/commission-finalize.js +14 -0
  29. package/dist/domain/mcp/tools/commission-tools.d.ts +12 -1
  30. package/dist/domain/mcp/tools/commission-tools.js +68 -14
  31. package/dist/domain/remote/client-manager.js +66 -7
  32. package/dist/domain/remote/client-ssh-tunnel.d.ts +16 -5
  33. package/dist/domain/remote/client-ssh-tunnel.js +12 -5
  34. package/dist/domain/runs/builders.js +0 -1
  35. package/dist/domain/runs/compact.js +0 -1
  36. package/dist/domain/runs/engine-spec.d.ts +11 -4
  37. package/dist/domain/runs/engine-spec.js +7 -4
  38. package/dist/domain/runs/prompt.js +16 -10
  39. package/dist/domain/runs/request.d.ts +0 -1
  40. package/dist/domain/sessions/session-hooks.d.ts +5 -12
  41. package/dist/domain/sessions/session-hooks.js +6 -13
  42. package/dist/domain/sessions/session-lifecycle.d.ts +4 -4
  43. package/dist/domain/sessions/session-lifecycle.js +5 -6
  44. package/dist/domain/sessions/session-retention.d.ts +1 -3
  45. package/dist/domain/sessions/session-retention.js +9 -26
  46. package/dist/domain/sessions/session-use.d.ts +32 -0
  47. package/dist/domain/sessions/session-use.js +63 -0
  48. package/dist/domain/sessions/session.js +6 -5
  49. package/dist/domain/system/server-update-check.js +29 -1
  50. package/dist/domain/system/update-ui-state.d.ts +32 -0
  51. package/dist/domain/system/update-ui-state.js +63 -0
  52. package/dist/domain/threads/runner.js +0 -1
  53. package/dist/domain/ui-service/app-router.d.ts +30 -0
  54. package/dist/domain/ui-service/app-router.js +5 -1
  55. package/dist/domain/ui-service/input-schemas.d.ts +32 -0
  56. package/dist/domain/ui-service/input-schemas.js +22 -0
  57. package/dist/domain/ui-service/mutate/sessions.d.ts +13 -1
  58. package/dist/domain/ui-service/mutate/sessions.js +69 -3
  59. package/dist/domain/ui-service/mutate/system.d.ts +3 -1
  60. package/dist/domain/ui-service/mutate/system.js +13 -0
  61. package/dist/domain/ui-service/query/system.d.ts +2 -1
  62. package/dist/domain/ui-service/query/system.js +4 -0
  63. package/dist/domain/ui-service/types.d.ts +44 -3
  64. package/dist/domain/ui-service/ui-service.js +7 -3
  65. package/dist/entry/app.js +11 -23
  66. package/dist/entry/start-ui-http.js +3 -1
  67. package/dist/events/event-types.d.ts +5 -0
  68. package/dist/orchestration/agent-runner.d.ts +1 -1
  69. package/dist/orchestration/agent-runner.js +8 -11
  70. package/dist/orchestration/conversation-request.d.ts +26 -8
  71. package/dist/orchestration/conversation-request.js +49 -20
  72. package/dist/orchestration/edit-retry.js +2 -1
  73. package/dist/orchestration/interactions/ask-user-resume.js +2 -1
  74. package/dist/orchestration/interactions/ui-update-prompt.d.ts +8 -0
  75. package/dist/orchestration/interactions/ui-update-prompt.js +47 -0
  76. package/dist/orchestration/resume-dispatcher.js +2 -2
  77. package/dist/orchestration/routing/webhook.js +47 -0
  78. package/dist/orchestration/session-compact.d.ts +3 -0
  79. package/dist/orchestration/session-compact.js +3 -2
  80. package/dist/orchestration/session-events.d.ts +6 -0
  81. package/dist/orchestration/session-events.js +5 -0
  82. package/dist/orchestration/turn/turn-prep.js +2 -1
  83. package/dist/platform/ui-http/app-update.d.ts +11 -0
  84. package/dist/platform/ui-http/app-update.js +3 -0
  85. package/dist/store/conversation-ledger-repo.d.ts +10 -19
  86. package/dist/store/conversation-ledger-repo.js +143 -152
  87. package/dist/store/session-registry-import.d.ts +34 -0
  88. package/dist/store/session-registry-import.js +182 -0
  89. package/dist/store/session-registry-journal.d.ts +107 -0
  90. package/dist/store/session-registry-journal.js +307 -18
  91. package/dist/store/session-registry-repo.d.ts +113 -28
  92. package/dist/store/session-registry-repo.js +287 -104
  93. package/dist/store/version-migrations.d.ts +16 -0
  94. package/dist/store/version-migrations.js +34 -0
  95. package/package.json +1 -1
  96. package/web/dist/assets/{index-aHbOZSP6.js → index-CEZ0DSei.js} +1 -1
  97. package/web/dist/assets/{index-CCPxQ94C.css → index-CRDJo39X.css} +1 -1
  98. package/web/dist/assets/index-DjuPJVZE.js +444 -0
  99. package/web/dist/index.html +2 -2
  100. package/dist/store/session-repo.d.ts +0 -65
  101. package/dist/store/session-repo.js +0 -184
  102. package/web/dist/assets/index-BuXbCsuz.js +0 -444
@@ -1,7 +1,11 @@
1
1
  import type { SessionContextUsage } from '../core/types/agent-types.js';
2
- import { deriveSessionOrigin, type SessionDeleteCleanup, type SessionBrowserOption, type SessionOrigin, type SessionRecord, type SessionRegistryJournalOptions } from './session-registry-journal.js';
2
+ import { deriveSessionOrigin, type ConversationFields, type ConversationHeader, type SessionDeleteCleanup, type SessionBrowserOption, type SessionOrigin, type SessionRecord, type SessionRegistryJournalOptions, type TurnRecord } from './session-registry-journal.js';
3
3
  export declare const REGISTRY_FILE: string;
4
- export { deriveSessionOrigin, type SessionOrigin };
4
+ export { deriveSessionOrigin, type SessionOrigin, type TurnRecord, type ConversationFields, type ConversationHeader, };
5
+ /** In-memory channel→sessionId resolver (never persisted). A resolver that returns a string wins
6
+ * over any persisted bind; returning `null`/`undefined` falls through to the next resolver, then to
7
+ * the persisted bindings index. Registered by conduit-aware platforms (TUI, app.ts). */
8
+ export type ConduitResolver = (channel: string) => string | null | undefined;
5
9
  export interface Session extends Omit<SessionRecord, 'contextUsage'> {
6
10
  contextUsage?: SessionContextUsage;
7
11
  }
@@ -14,6 +18,39 @@ export type SessionRegistryRepoOptions = SessionRegistryJournalOptions;
14
18
  type UpdateFields = Partial<Pick<Session, 'lastUsedAt' | 'label' | 'profileName' | 'backendSessionId' | 'contextUsage' | 'browser'>> & {
15
19
  sessionId?: never;
16
20
  };
21
+ export interface RegisterSessionOpts {
22
+ sessionId: string;
23
+ channel: string;
24
+ backend: string;
25
+ kind: 'local' | 'scheduled';
26
+ origin?: SessionOrigin;
27
+ projectId?: string;
28
+ label?: string | null;
29
+ profileName?: string | null;
30
+ backendSessionId?: string | null;
31
+ scheduleId?: string | null;
32
+ browser?: SessionBrowserOption | null;
33
+ commissionId?: string | null;
34
+ commissionDraft?: string | null;
35
+ }
36
+ /** Mutators available inside `batch(fn)` — each shares the one locked state so several events land
37
+ * in a single critical section (§5). Read APIs are not exposed; read from the returned records. */
38
+ export interface SessionRegistryBatch {
39
+ registerSession(name: string, opts: RegisterSessionOpts): Promise<void>;
40
+ updateSession(name: string, updates: UpdateFields): Promise<void>;
41
+ updateById(sessionId: string, mutate: (record: Session) => Session): Promise<Session | null>;
42
+ bindChannel(channel: string, sessionId: string): Promise<void>;
43
+ unbindChannel(channel: string): Promise<void>;
44
+ beginTurn(channel: string, turn: TurnRecord): Promise<void>;
45
+ patchTurn(channel: string, turnIndex: number, fields: Partial<TurnRecord>): Promise<void>;
46
+ truncateTurns(channel: string, fromIndex: number): Promise<void>;
47
+ clearTurns(channel: string): Promise<void>;
48
+ setConversation(channel: string, fields: ConversationFields): Promise<void>;
49
+ clearConversation(channel: string): Promise<void>;
50
+ /** Synchronous reads off the shared locked state — let a façade find-turn / set-if-missing atomically. */
51
+ getTurns(channel: string): TurnRecord[];
52
+ getConversationHeader(channel: string): ConversationHeader | null;
53
+ }
17
54
  export declare function effectiveBackendSessionId(rec: Pick<Session, 'sessionId' | 'backendSessionId'>): string | null;
18
55
  export declare class SessionRegistryRepo {
19
56
  private readonly filePath;
@@ -21,28 +58,16 @@ export declare class SessionRegistryRepo {
21
58
  private readonly options;
22
59
  private state;
23
60
  private loaded;
24
- private activeUses;
61
+ private conduitResolvers;
25
62
  constructor(filePath?: string, options?: SessionRegistryRepoOptions);
26
63
  generateSessionName(): Promise<string>;
27
- registerSession(name: string, opts: {
28
- sessionId: string;
29
- channel: string;
30
- backend: string;
31
- kind: 'local' | 'scheduled';
32
- origin?: SessionOrigin;
33
- projectId?: string;
34
- label?: string | null;
35
- profileName?: string | null;
36
- backendSessionId?: string | null;
37
- scheduleId?: string | null;
38
- browser?: SessionBrowserOption | null;
39
- commissionId?: string | null;
40
- commissionDraft?: string | null;
41
- }): Promise<void>;
64
+ registerSession(name: string, opts: RegisterSessionOpts): Promise<void>;
65
+ private doRegisterSession;
42
66
  convertToDirect(sessionId: string, opts: {
43
67
  channel: string;
44
68
  }): Promise<Session | null>;
45
69
  updateSession(name: string, updates: UpdateFields): Promise<void>;
70
+ private doUpdateSession;
46
71
  updateContextUsage(sessionId: string, usage: SessionContextUsage | null): Promise<void>;
47
72
  lookupSession(name: string): Promise<Session | null>;
48
73
  lookupBySessionId(sessionId: string): Promise<string | null>;
@@ -51,30 +76,90 @@ export declare class SessionRegistryRepo {
51
76
  listByProject(projectId: string): Promise<Session[]>;
52
77
  listByOrigin(origin: SessionOrigin, projectId?: string): Promise<Session[]>;
53
78
  listResumable(projectId?: string): Promise<Session[]>;
54
- touchForUse(sessionId: string): Promise<boolean>;
55
- acquireSessionUse(sessionId: string): Promise<(() => void) | null>;
56
- withSessionUse<T>(sessionId: string, fn: () => Promise<T>): Promise<T | null>;
57
- markUsed(sessionId: string): Promise<void>;
79
+ /** Storage primitive behind use-count admission — the in-memory counter and lease semantics live
80
+ * in `@domain/sessions/session-use.ts`. Patches `lastUsedAt=now` iff the session is live and NOT
81
+ * pending deletion; returns whether the touch landed. */
82
+ touchSessionUse(sessionId: string): Promise<boolean>;
58
83
  markRead(sessionId: string): Promise<void>;
59
84
  /** Bind (or unbind with null) a session to a commission. Called by the commission finalize path
60
85
  * (DR-0037) and by commission-mode session creation. Binding also clears commissionDraft: once
61
- * the contract is named, the draft directory no longer exists under that name. */
86
+ * the contract is named, the draft directory no longer exists under that name.
87
+ *
88
+ * `commissionBlockFor` is deliberately left alone: binding CHANGES the key (`draft:x` →
89
+ * `active:id`), and that mismatch is exactly what makes the next turn deliver the active block. */
62
90
  bindCommission(sessionId: string, commissionId: string | null): Promise<Session | null>;
91
+ /** Enter (or leave, with null) the drafting half of commission mode. Called by
92
+ * `cortex_commission_start`, by the composer's "new" on a live session, and by session creation.
93
+ * Refuses to touch a session already bound to a commission — that is a terminal state. */
94
+ setCommissionDraft(sessionId: string, draftDir: string | null): Promise<Session | null>;
95
+ /** Record that the `[Commission]` block for `key` is now in this session's backend history. */
96
+ markCommissionBlockDelivered(sessionId: string, key: string): Promise<Session | null>;
97
+ /** Forget the delivery marker so the next turn re-injects the block. Called after compaction,
98
+ * which drops the copy that was in backend history. */
99
+ clearCommissionBlockDelivery(sessionId: string): Promise<Session | null>;
100
+ /** Register an in-memory conduit resolver. Never persisted; a resolver answer wins over a
101
+ * persisted bind (§6). Returns an unregister callback. */
102
+ registerConduitResolver(fn: ConduitResolver): () => void;
103
+ /** Resolve the conversation session for a channel: in-memory resolvers first (a string wins),
104
+ * then the persisted bindings index. */
105
+ getBoundSessionId(channel: string): Promise<string | null>;
106
+ bindChannel(channel: string, sessionId: string): Promise<void>;
107
+ unbindChannel(channel: string): Promise<void>;
108
+ /** Remove every binding pointing at one of `sessionIds`. Used when sessions are torn down.
109
+ * Returns the number of bindings removed. */
110
+ unbindBySessionIds(sessionIds: Iterable<string>): Promise<number>;
111
+ listBindings(): Promise<Array<{
112
+ channel: string;
113
+ sessionId: string;
114
+ }>>;
115
+ beginTurn(channel: string, turn: TurnRecord): Promise<void>;
116
+ patchTurn(channel: string, turnIndex: number, fields: Partial<TurnRecord>): Promise<void>;
117
+ truncateTurns(channel: string, fromIndex: number): Promise<void>;
118
+ clearTurns(channel: string): Promise<void>;
119
+ getTurns(channel: string): Promise<TurnRecord[]>;
120
+ findTurn(channel: string, pred: (turn: TurnRecord) => boolean): Promise<TurnRecord | null>;
121
+ getConversationHeader(channel: string): Promise<ConversationHeader | null>;
122
+ setConversation(channel: string, fields: ConversationFields): Promise<void>;
123
+ clearConversation(channel: string): Promise<void>;
124
+ /** Header + turns for a channel under ONE lock (or null when the channel has no header). */
125
+ readConversation(channel: string): Promise<{
126
+ header: ConversationHeader;
127
+ turns: TurnRecord[];
128
+ } | null>;
129
+ /** Every channel that has a conversation header, with its turns — one lock for the whole scan. */
130
+ listConversations(): Promise<Array<{
131
+ channel: string;
132
+ header: ConversationHeader;
133
+ turns: TurnRecord[];
134
+ }>>;
135
+ /** Run several mutations under ONE admission lock (T2/T3 need put+bind+turn atomically — never a
136
+ * put without its bind, §5). The ops mirror the top-level mutators but share the locked state. */
137
+ batch<T>(fn: (ops: SessionRegistryBatch) => Promise<T>): Promise<T>;
138
+ private batchOps;
139
+ private doBindChannel;
140
+ private doUnbindChannel;
141
+ private doBeginTurn;
142
+ private doPatchTurn;
143
+ private doTruncateTurns;
144
+ private doClearTurns;
145
+ private doSetConversation;
146
+ private doClearConversation;
63
147
  listPendingDeletions(): Promise<PendingDeletion[]>;
64
- beginDeleteExpired(cutoff: number | Date, protectedIds: Iterable<string>, prepareCleanup?: (session: Session) => Promise<SessionDeleteCleanup>): Promise<PendingDeletion[]>;
148
+ beginDeleteExpired(cutoff: number | Date, protectedIds: Iterable<string>, prepareCleanup?: (session: Session, turns: TurnRecord[]) => Promise<SessionDeleteCleanup>): Promise<PendingDeletion[]>;
65
149
  commitDeletion(sessionId: string): Promise<boolean>;
66
- pruneStale(maxAgeMs: number): Promise<number>;
67
- setOnPruneSession(_fn: ((sessionId: string) => void) | null): void;
68
150
  compactNow(): Promise<void>;
69
- /** `backend` is accepted and ignored — a channel has one session. */
151
+ /** `backend` is accepted and ignored — a channel has one session. Pure in-registry lookup:
152
+ * the channel's bound sessionId → the live record's name. */
70
153
  getActiveSessionName(channel: string, backend?: string): Promise<string | null>;
71
154
  invalidate(): void;
72
155
  flush(): Promise<void>;
73
156
  private withState;
74
157
  private loadState;
75
- private appendPut;
76
158
  private writePut;
77
159
  private updateById;
160
+ private doUpdateById;
161
+ /** Append a `patch` for the delta between `current` (live) and `next`. No-op when nothing changed. */
162
+ private writePatch;
78
163
  private maybeCompact;
79
164
  }
80
165
  export declare const sessionStore: SessionRegistryRepo;