@cortex-agent/server 2026.9.21 → 2026.9.25
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.
- package/defaults/config/thread-templates/agents/creative.json +17 -0
- package/defaults/prompts/systemPrompts/creative.md +13 -0
- package/defaults/prompts/systemPrompts/direct.md +1 -1
- package/dist/agent-adapter/claude/adapter.d.ts +12 -0
- package/dist/agent-adapter/claude/adapter.js +19 -1
- package/dist/agent-adapter/claude/spawn-args.d.ts +7 -0
- package/dist/agent-adapter/claude/spawn-args.js +10 -0
- package/dist/agent-adapter/pi/child-runner.d.ts +4 -2
- package/dist/agent-adapter/pi/child-runner.js +5 -1
- package/dist/agent-adapter/pi/event-parser.d.ts +3 -2
- package/dist/agent-adapter/pi/event-parser.js +46 -2
- package/dist/agent-adapter/pi/extensions.d.ts +7 -1
- package/dist/agent-adapter/pi/extensions.js +10 -3
- package/dist/agent-adapter/pi/mcp-bridge.js +8 -8
- package/dist/agent-adapter/pi/pi-session.js +5 -0
- package/dist/agent-adapter/pi/runtime.js +3 -0
- package/dist/agent-adapter/pi/session-options.js +5 -1
- package/dist/agent-adapter/pi/subagent.d.ts +15 -3
- package/dist/agent-adapter/pi/subagent.js +18 -0
- package/dist/agent-adapter/pi/tool-shims.d.ts +6 -1
- package/dist/agent-adapter/pi/tool-shims.js +34 -1
- package/dist/agent-adapter/types.d.ts +5 -0
- package/dist/core/agents/subagent/types.d.ts +3 -0
- package/dist/core/config-generator.js +17 -2
- package/dist/core/debug-mode.d.ts +11 -10
- package/dist/core/debug-mode.js +12 -18
- package/dist/core/exec-async.d.ts +26 -0
- package/dist/core/exec-async.js +47 -0
- package/dist/core/locales/en.d.ts +14 -1
- package/dist/core/locales/slices/commands.d.ts +12 -1
- package/dist/core/locales/slices/commands.js +24 -2
- package/dist/core/locales/slices/startup.d.ts +2 -0
- package/dist/core/locales/slices/startup.js +4 -0
- package/dist/core/rebuild-progress.d.ts +58 -0
- package/dist/core/rebuild-progress.js +103 -0
- package/dist/core/resilient-watch.js +5 -3
- package/dist/core/run-registry.d.ts +7 -0
- package/dist/core/run-registry.js +6 -0
- package/dist/core/types/thread-types.d.ts +23 -4
- package/dist/domain/agents/agent-state.d.ts +7 -0
- package/dist/domain/agents/agent-state.js +9 -1
- package/dist/domain/agents/agent-switch.d.ts +38 -0
- package/dist/domain/agents/agent-switch.js +106 -0
- package/dist/domain/agents/config.d.ts +20 -2
- package/dist/domain/agents/config.js +58 -4
- package/dist/domain/agents/index.d.ts +1 -0
- package/dist/domain/agents/index.js +1 -0
- package/dist/domain/agents/profile-manager.d.ts +6 -0
- package/dist/domain/agents/profile-manager.js +14 -1
- package/dist/domain/executions/registry.d.ts +2 -0
- package/dist/domain/executions/registry.js +84 -7
- package/dist/domain/plugins/runtime.js +1 -1
- package/dist/domain/plugins/skill-projection.d.ts +8 -2
- package/dist/domain/plugins/skill-projection.js +76 -19
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-hot-reload.d.ts +1 -1
- package/dist/domain/remote/client-hot-reload.js +27 -23
- package/dist/domain/runs/engine-spec.js +4 -0
- package/dist/domain/runs/request.d.ts +6 -0
- package/dist/domain/runs/run.js +1 -0
- package/dist/domain/runs/spec-loader.d.ts +4 -3
- package/dist/domain/runs/spec-loader.js +4 -3
- package/dist/domain/scheduling/jobs/sync-public.js +6 -6
- package/dist/domain/scheduling/scheduler.js +14 -12
- package/dist/domain/sessions/session-lifecycle.d.ts +5 -0
- package/dist/domain/sessions/session-lifecycle.js +13 -1
- package/dist/domain/system/rebuild-hold.d.ts +44 -0
- package/dist/domain/system/rebuild-hold.js +91 -0
- package/dist/domain/system/server-update-check.d.ts +2 -1
- package/dist/domain/system/server-update-check.js +15 -13
- package/dist/domain/tasks/archiver.js +21 -13
- package/dist/domain/tasks/mutator.js +60 -59
- package/dist/domain/tasks/system/task-completion.d.ts +7 -2
- package/dist/domain/tasks/system/task-completion.js +69 -6
- package/dist/domain/tasks/system/task-lifecycle-edit.d.ts +6 -1
- package/dist/domain/tasks/system/task-lifecycle-edit.js +21 -2
- package/dist/domain/tasks/system/task-lock.d.ts +23 -0
- package/dist/domain/tasks/system/task-lock.js +29 -1
- package/dist/domain/tasks/system/task-mutations.d.ts +14 -1
- package/dist/domain/tasks/system/task-mutations.js +25 -2
- package/dist/domain/tasks/system/task-state.d.ts +12 -1
- package/dist/domain/tasks/system/task-state.js +19 -2
- package/dist/domain/threads/prompt-builder.d.ts +9 -6
- package/dist/domain/threads/prompt-builder.js +28 -10
- package/dist/domain/threads/runner.js +7 -3
- package/dist/domain/threads/state-machine.js +15 -11
- package/dist/domain/threads/template-loader.js +6 -4
- package/dist/domain/threads/template-validate.d.ts +43 -6
- package/dist/domain/threads/template-validate.js +12 -0
- package/dist/domain/ui-service/app-router.d.ts +10 -0
- package/dist/domain/ui-service/app-router.js +2 -1
- package/dist/domain/ui-service/input-schemas.d.ts +11 -0
- package/dist/domain/ui-service/input-schemas.js +11 -0
- package/dist/domain/ui-service/mutate/sessions.d.ts +2 -1
- package/dist/domain/ui-service/mutate/sessions.js +40 -0
- package/dist/domain/ui-service/mutate/tasks.js +4 -3
- package/dist/domain/ui-service/query/config.js +19 -1
- package/dist/domain/ui-service/query/memory.js +28 -34
- package/dist/domain/ui-service/query/sessions.js +89 -12
- package/dist/domain/ui-service/query/system.js +19 -0
- package/dist/domain/ui-service/query-input-schemas.d.ts +1 -0
- package/dist/domain/ui-service/query-input-schemas.js +2 -0
- package/dist/domain/ui-service/types.d.ts +97 -3
- package/dist/domain/ui-service/ui-service.js +2 -1
- package/dist/entry/app.js +23 -4
- package/dist/entry/daemon-notice.d.ts +10 -1
- package/dist/entry/daemon-notice.js +16 -1
- package/dist/entry/daemon.d.ts +43 -2
- package/dist/entry/daemon.js +163 -9
- package/dist/orchestration/agent-runner.js +16 -0
- package/dist/orchestration/conversation-request.d.ts +33 -0
- package/dist/orchestration/conversation-request.js +78 -16
- package/dist/orchestration/mid-turn-inject.d.ts +3 -0
- package/dist/orchestration/mid-turn-inject.js +9 -4
- package/dist/orchestration/resume-dispatcher.js +4 -2
- package/dist/orchestration/routing/commands/mode.js +114 -63
- package/dist/orchestration/thread-executor.js +13 -0
- package/dist/orchestration/turn/turn.js +1 -0
- package/dist/store/conversation-display-projection.d.ts +9 -1
- package/dist/store/conversation-display-projection.js +13 -6
- package/dist/store/conversation-history-reader.d.ts +19 -0
- package/dist/store/conversation-history-reader.js +163 -44
- package/dist/store/conversation-history-repo.d.ts +37 -10
- package/dist/store/conversation-history-repo.js +161 -139
- package/dist/store/session-registry-journal.d.ts +4 -0
- package/dist/store/session-registry-journal.js +4 -0
- package/dist/store/session-registry-repo.d.ts +2 -1
- package/dist/store/session-registry-repo.js +2 -0
- package/dist/store/task-repo.d.ts +6 -3
- package/dist/store/task-repo.js +26 -10
- package/package.json +2 -1
- package/web/dist/AGENTS.md +10 -0
- package/web/dist/assets/index-B1dBi8Za.css +1 -0
- package/web/dist/assets/{index-DZTuqUO4.js → index-BAeLybF0.js} +1 -1
- package/web/dist/assets/index-BcQI8Fh5.js +445 -0
- package/web/dist/index.html +12 -4
- package/web/dist/theme.css +211 -40
- package/web/dist/assets/index-CwwQNMpP.css +0 -1
- package/web/dist/assets/index-DLSfgq3o.js +0 -444
|
@@ -160,6 +160,10 @@ export declare const sessionsSetProfileInput: z.ZodObject<{
|
|
|
160
160
|
sessionId: z.ZodString;
|
|
161
161
|
profileName: z.ZodString;
|
|
162
162
|
}, z.core.$strip>;
|
|
163
|
+
export declare const sessionsSetAgentInput: z.ZodObject<{
|
|
164
|
+
sessionId: z.ZodString;
|
|
165
|
+
agentName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
166
|
+
}, z.core.$strip>;
|
|
163
167
|
export declare const sessionsSetSelectionInput: z.ZodObject<{
|
|
164
168
|
sessionId: z.ZodString;
|
|
165
169
|
profileName: z.ZodOptional<z.ZodString>;
|
|
@@ -200,6 +204,7 @@ export declare const sessionsRewindInput: z.ZodObject<{
|
|
|
200
204
|
export declare const sessionsCreateAndSendInput: z.ZodObject<{
|
|
201
205
|
projectId: z.ZodString;
|
|
202
206
|
profileName: z.ZodOptional<z.ZodString>;
|
|
207
|
+
agentName: z.ZodOptional<z.ZodString>;
|
|
203
208
|
selection: z.ZodOptional<z.ZodObject<{
|
|
204
209
|
model: z.ZodOptional<z.ZodString>;
|
|
205
210
|
provider: z.ZodOptional<z.ZodString>;
|
|
@@ -610,6 +615,7 @@ export declare const queryInputSchemas: {
|
|
|
610
615
|
'sessions.transcript': z.ZodObject<{
|
|
611
616
|
sessionId: z.ZodString;
|
|
612
617
|
compactSubagents: z.ZodOptional<z.ZodBoolean>;
|
|
618
|
+
since: z.ZodOptional<z.ZodString>;
|
|
613
619
|
}, z.core.$strip>;
|
|
614
620
|
'sessions.subagentTranscript': z.ZodObject<{
|
|
615
621
|
sessionId: z.ZodString;
|
|
@@ -775,6 +781,10 @@ export declare const mutateInputSchemas: {
|
|
|
775
781
|
sessionId: z.ZodString;
|
|
776
782
|
profileName: z.ZodString;
|
|
777
783
|
}, z.core.$strip>;
|
|
784
|
+
'sessions.setAgent': z.ZodObject<{
|
|
785
|
+
sessionId: z.ZodString;
|
|
786
|
+
agentName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
787
|
+
}, z.core.$strip>;
|
|
778
788
|
'sessions.setSelection': z.ZodObject<{
|
|
779
789
|
sessionId: z.ZodString;
|
|
780
790
|
profileName: z.ZodOptional<z.ZodString>;
|
|
@@ -799,6 +809,7 @@ export declare const mutateInputSchemas: {
|
|
|
799
809
|
'sessions.createAndSend': z.ZodObject<{
|
|
800
810
|
projectId: z.ZodString;
|
|
801
811
|
profileName: z.ZodOptional<z.ZodString>;
|
|
812
|
+
agentName: z.ZodOptional<z.ZodString>;
|
|
802
813
|
selection: z.ZodOptional<z.ZodObject<{
|
|
803
814
|
model: z.ZodOptional<z.ZodString>;
|
|
804
815
|
provider: z.ZodOptional<z.ZodString>;
|
|
@@ -141,6 +141,15 @@ export const sessionsSetProfileInput = z.object({
|
|
|
141
141
|
sessionId: z.string(),
|
|
142
142
|
profileName: z.string().min(1),
|
|
143
143
|
});
|
|
144
|
+
// sessions.setAgent — which agent template (execution environment) the session runs as. "Follow the
|
|
145
|
+
// global default again" is sayable two ways, `null` and absent, because the browser client cannot
|
|
146
|
+
// say the first one: this project compiles without strictNullChecks, so the `| null` of an INFERRED
|
|
147
|
+
// schema type is stripped from the emitted declaration the web typechecks against. Both forms mean
|
|
148
|
+
// the same thing to the handler.
|
|
149
|
+
export const sessionsSetAgentInput = z.object({
|
|
150
|
+
sessionId: z.string(),
|
|
151
|
+
agentName: z.string().min(1).nullable().optional(),
|
|
152
|
+
});
|
|
144
153
|
/** What a session runs on top of its profile. Stated WHOLE, never patched: a field the object does
|
|
145
154
|
* not carry is a field that follows the profile, so "go back to the profile's model" needs no null
|
|
146
155
|
* (which the typed tRPC client cannot express through an optional input anyway). */
|
|
@@ -188,6 +197,7 @@ export const sessionsRewindInput = z.object({
|
|
|
188
197
|
export const sessionsCreateAndSendInput = z.object({
|
|
189
198
|
projectId: z.string(),
|
|
190
199
|
profileName: z.string().optional(),
|
|
200
|
+
agentName: z.string().min(1).optional(),
|
|
191
201
|
selection: sessionSelectionInput.optional(),
|
|
192
202
|
browser: sessionBrowserInput.nullish(),
|
|
193
203
|
commission: sessionCommissionInput.nullish(),
|
|
@@ -720,6 +730,7 @@ export const mutateInputSchemas = {
|
|
|
720
730
|
'sessions.cancel': sessionsCancelInput,
|
|
721
731
|
'sessions.compact': sessionsCompactInput,
|
|
722
732
|
'sessions.setProfile': sessionsSetProfileInput,
|
|
733
|
+
'sessions.setAgent': sessionsSetAgentInput,
|
|
723
734
|
'sessions.setSelection': sessionsSetSelectionInput,
|
|
724
735
|
'sessions.setCommission': sessionsSetCommissionInput,
|
|
725
736
|
'sessions.createAndSend': sessionsCreateAndSendInput,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UiServiceDeps, Result, SessionsCreateArgs, SessionsCreateReturn, SessionsSendArgs, SessionsSendReturn, SessionsCancelArgs, SessionsCompactArgs, SessionsCompactReturn, SessionsMarkReadArgs, SessionsMarkManyReadArgs, SessionsMarkManyReadReturn, SessionsCancelReturn, SessionsSetProfileArgs, SessionsSetProfileReturn, SessionsSetSelectionArgs, SessionsSetSelectionReturn, SessionsSetCommissionArgs, SessionsSetCommissionReturn, SessionsCreateAndSendArgs, SessionsCreateAndSendReturn, SessionsAnswerQuestionArgs, SessionsRespondPlanArgs, SessionsRespondDecisionArgs, SessionsRespondDecisionReturn, SessionsInteractionMutateReturn, SessionsRewindArgs, SessionsRewindReturn, SessionsCancelResumeArgs, SessionsCancelResumeReturn } from '../types.js';
|
|
1
|
+
import type { UiServiceDeps, Result, SessionsCreateArgs, SessionsCreateReturn, SessionsSendArgs, SessionsSendReturn, SessionsCancelArgs, SessionsCompactArgs, SessionsCompactReturn, SessionsMarkReadArgs, SessionsMarkManyReadArgs, SessionsMarkManyReadReturn, SessionsCancelReturn, SessionsSetProfileArgs, SessionsSetProfileReturn, SessionsSetAgentArgs, SessionsSetAgentReturn, SessionsSetSelectionArgs, SessionsSetSelectionReturn, SessionsSetCommissionArgs, SessionsSetCommissionReturn, SessionsCreateAndSendArgs, SessionsCreateAndSendReturn, SessionsAnswerQuestionArgs, SessionsRespondPlanArgs, SessionsRespondDecisionArgs, SessionsRespondDecisionReturn, SessionsInteractionMutateReturn, SessionsRewindArgs, SessionsRewindReturn, SessionsCancelResumeArgs, SessionsCancelResumeReturn } from '../types.js';
|
|
2
2
|
export declare function handleCreateSession(deps: UiServiceDeps, args: SessionsCreateArgs): Promise<Result<SessionsCreateReturn>>;
|
|
3
3
|
/**
|
|
4
4
|
* Switch a LIVE session in or out of commission mode (DR-0037 v4).
|
|
@@ -22,6 +22,7 @@ export declare function handleMarkReadSession(deps: UiServiceDeps, args: Session
|
|
|
22
22
|
export declare function handleMarkManyReadSessions(deps: UiServiceDeps, args: SessionsMarkManyReadArgs): Promise<Result<SessionsMarkManyReadReturn>>;
|
|
23
23
|
export declare function handleCreateAndSend(deps: UiServiceDeps, args: SessionsCreateAndSendArgs): Promise<Result<SessionsCreateAndSendReturn>>;
|
|
24
24
|
export declare function handleSetProfile(deps: UiServiceDeps, args: SessionsSetProfileArgs): Promise<Result<SessionsSetProfileReturn>>;
|
|
25
|
+
export declare function handleSetAgent(deps: UiServiceDeps, args: SessionsSetAgentArgs): Promise<Result<SessionsSetAgentReturn>>;
|
|
25
26
|
export declare function handleSetSelection(deps: UiServiceDeps, args: SessionsSetSelectionArgs): Promise<Result<SessionsSetSelectionReturn>>;
|
|
26
27
|
export declare function handleRewindSession(deps: UiServiceDeps, args: SessionsRewindArgs): Promise<Result<SessionsRewindReturn>>;
|
|
27
28
|
export declare function handleAnswerQuestion(deps: UiServiceDeps, args: SessionsAnswerQuestionArgs): Promise<Result<SessionsInteractionMutateReturn>>;
|
|
@@ -207,6 +207,10 @@ export async function handleCreateAndSend(deps, args) {
|
|
|
207
207
|
const { sessionId, channel } = await deps.createDirectSession({
|
|
208
208
|
projectId: args.projectId,
|
|
209
209
|
profileName: args.profileName ?? null,
|
|
210
|
+
// The draft composer's environment choice, applied at creation for the same reason as the
|
|
211
|
+
// selection below: the agent decides the spawned process's prompt and tool surface, and there
|
|
212
|
+
// is no session to `setAgent` on before the first turn.
|
|
213
|
+
agentName: args.agentName ?? null,
|
|
210
214
|
// The draft composer's model/thinking choice, applied at creation so the FIRST turn already
|
|
211
215
|
// runs it — there is no session to `setSelection` on before this call. A composer that sends
|
|
212
216
|
// none is stating the empty selection ("follow the profile"), not staying silent: this is the
|
|
@@ -259,6 +263,42 @@ export async function handleSetProfile(deps, args) {
|
|
|
259
263
|
}
|
|
260
264
|
return { ok: true, data: { profileName: res.name, backendChanged: res.backendChanged } };
|
|
261
265
|
}
|
|
266
|
+
// Switch the session's agent — its execution environment — under the shared agent-switch rule (the
|
|
267
|
+
// same `switchChannelAgent` the Slack/Feishu `!agent` command uses, injected as `switchSessionAgent`).
|
|
268
|
+
// The error mapping is `handleSetProfile`'s, for the same reasons:
|
|
269
|
+
// • unknown-agent → invalid-args
|
|
270
|
+
// • cross-backend-live-session → conflict (an agent pinning a profile on the other backend is a
|
|
271
|
+
// backend move; a live conversation can't be resumed there)
|
|
272
|
+
// A null `agentName` clears the selection: the session follows the global default again.
|
|
273
|
+
export async function handleSetAgent(deps, args) {
|
|
274
|
+
const session = await deps.sessionStore.getById(args.sessionId);
|
|
275
|
+
if (!session) {
|
|
276
|
+
return { ok: false, code: 'not-found', message: `Session not found: ${args.sessionId}` };
|
|
277
|
+
}
|
|
278
|
+
if (!deps.switchSessionAgent) {
|
|
279
|
+
return { ok: false, code: 'not-available', message: 'Agent selection is not available' };
|
|
280
|
+
}
|
|
281
|
+
const name = args.agentName ?? null;
|
|
282
|
+
const res = await deps.switchSessionAgent({ channel: session.channel, name });
|
|
283
|
+
if (!res.ok) {
|
|
284
|
+
if (res.reason === 'unknown-agent') {
|
|
285
|
+
return { ok: false, code: 'invalid-args', message: `Unknown agent: ${String(name)}` };
|
|
286
|
+
}
|
|
287
|
+
return {
|
|
288
|
+
ok: false,
|
|
289
|
+
code: 'backend-locked', // maps to CONFLICT in the tRPC layer
|
|
290
|
+
message: `Can't switch to "${String(name)}" (${res.targetBackend}) — this conversation runs on ${res.currentBackend}. Start a new session to change backend.`,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
ok: true,
|
|
295
|
+
data: {
|
|
296
|
+
agentName: res.agentName,
|
|
297
|
+
profileName: res.effectiveProfile,
|
|
298
|
+
backendChanged: res.backendChanged,
|
|
299
|
+
},
|
|
300
|
+
};
|
|
301
|
+
}
|
|
262
302
|
// Change what the session's next turn runs — its profile, its model, its PI provider, its thinking
|
|
263
303
|
// level, or any combination — through the ONE domain rule (`applyChannelSelection`, injected as
|
|
264
304
|
// `applySessionSelection`). The composer's greying-out is a preview of that rule; this is where it
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// output: claim/unclaim/complete/block/unblock handlers → Ok<void> | Err
|
|
3
3
|
// pos: mutate handlers for 'tasks.{claim,unclaim,complete,block,unblock}'
|
|
4
4
|
import { taskMutator } from '../../tasks/mutator.js';
|
|
5
|
-
import {
|
|
5
|
+
import { acquireLockAsync, releaseLockAsync, getOwnerIdentity } from '../../tasks/system/task-lock.js';
|
|
6
6
|
async function withTaskLock(deps, projectId, fn) {
|
|
7
7
|
const owner = getOwnerIdentity();
|
|
8
|
-
|
|
8
|
+
// Async lock: the UI mutation must not park the event loop while another process holds the lock.
|
|
9
|
+
const acq = await acquireLockAsync(projectId, { owner });
|
|
9
10
|
if (!acq.acquired) {
|
|
10
11
|
return { ok: false, code: 'task-lock-busy', message: acq.message || 'Task lock is busy' };
|
|
11
12
|
}
|
|
@@ -14,7 +15,7 @@ async function withTaskLock(deps, projectId, fn) {
|
|
|
14
15
|
return { ok: true, data: result };
|
|
15
16
|
}
|
|
16
17
|
finally {
|
|
17
|
-
|
|
18
|
+
await releaseLockAsync(projectId, owner);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
export async function handleClaimTask(deps, args) {
|
|
@@ -19,6 +19,22 @@ async function readJson(file) {
|
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
/** The agent templates, read as documents rather than filenames: a picker has to say what each
|
|
23
|
+
* environment is for and which profile it pins. Read from the same directory the bare listing
|
|
24
|
+
* comes from, so the snapshot stays hermetic to `configDir`; a malformed file is skipped rather
|
|
25
|
+
* than failing the whole snapshot. */
|
|
26
|
+
async function readAgentEntries(dir, names) {
|
|
27
|
+
const entries = await Promise.all(names.map(async (name) => {
|
|
28
|
+
const raw = await readJson(path.join(dir, `${name}.json`));
|
|
29
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
30
|
+
return null;
|
|
31
|
+
const doc = raw;
|
|
32
|
+
const profile = typeof doc.profile === 'string' && doc.profile ? doc.profile : '__active__';
|
|
33
|
+
const description = typeof doc.description === 'string' && doc.description ? doc.description : undefined;
|
|
34
|
+
return { name, profile, ...(description ? { description } : {}) };
|
|
35
|
+
}));
|
|
36
|
+
return entries.filter((entry) => entry !== null);
|
|
37
|
+
}
|
|
22
38
|
async function listJsonBasenames(dir) {
|
|
23
39
|
try {
|
|
24
40
|
return (await fs.readdir(dir))
|
|
@@ -174,7 +190,9 @@ export async function readConfigSnapshot(configDir, liveSettings, lang) {
|
|
|
174
190
|
return {
|
|
175
191
|
platforms: await readPlatformSettings(path.join(configDir, '.env')),
|
|
176
192
|
budget: parseBudget(budget), profiles: parseProfiles(profiles), machines: parseMachines(machines),
|
|
177
|
-
mcp: parseMcp(mcp), threadTemplates,
|
|
193
|
+
mcp: parseMcp(mcp), threadTemplates,
|
|
194
|
+
agents: await readAgentEntries(path.join(tt, 'agents'), agents),
|
|
195
|
+
hooks, env, settings,
|
|
178
196
|
...(lang ? { lang } : {}),
|
|
179
197
|
};
|
|
180
198
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// absolute paths, and symlink escape are rejected. No write API is used.
|
|
6
6
|
import * as fs from 'node:fs';
|
|
7
7
|
import * as path from 'node:path';
|
|
8
|
-
import {
|
|
8
|
+
import { runFile } from '../../../core/exec-async.js';
|
|
9
9
|
// Canonical top-level memory files, in display order. Missing ones are omitted (not errored).
|
|
10
10
|
const TOP_LEVEL_FILES = ['mission.md', 'roadmap.md', 'STATUS.md', 'TASKS.yaml'];
|
|
11
11
|
// Memory subdirectories whose `*.md` entries are counted (excluding the auto-generated index.md).
|
|
@@ -95,22 +95,17 @@ export async function handleMemoryTree(deps, params) {
|
|
|
95
95
|
// never fabricated) when the project dir is not a git work tree, git is unavailable, or the diff is
|
|
96
96
|
// binary/unresolvable. Read-only; array args (no shell) — `relPath` is the already-validated
|
|
97
97
|
// project-relative path, so there is no injection surface.
|
|
98
|
-
function gitLineDiff(root, relPath) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
// git missing / not a repo / non-zero exit → unknown, not fabricated.
|
|
98
|
+
async function gitLineDiff(root, relPath) {
|
|
99
|
+
const result = await runFile('git', ['diff', '--numstat', 'HEAD', '--', relPath], {
|
|
100
|
+
cwd: root,
|
|
101
|
+
timeoutMs: 5000,
|
|
102
|
+
maxBuffer: 1024 * 1024,
|
|
103
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
104
|
+
});
|
|
105
|
+
// git missing / not a repo / non-zero exit → unknown, not fabricated.
|
|
106
|
+
if (!result.ok)
|
|
112
107
|
return null;
|
|
113
|
-
|
|
108
|
+
const out = result.stdout;
|
|
114
109
|
const line = out.split('\n').find((l) => l.trim().length > 0);
|
|
115
110
|
// No diff vs HEAD (e.g. a clean auto-committed file) → the real answer is 0/0.
|
|
116
111
|
if (!line)
|
|
@@ -166,36 +161,35 @@ export function parseBlamePorcelain(out) {
|
|
|
166
161
|
// Real per-line blame (commit hash + parsed task ref). Returns null (honest placeholder, never
|
|
167
162
|
// fabricated) when the project dir is not a git work tree, git is unavailable, or the file is
|
|
168
163
|
// binary/unblameable. Read-only; array args (no shell) — `relPath` is already validated.
|
|
169
|
-
function gitBlame(root, relPath) {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
// git missing / not a repo / binary / non-zero exit → unknown, not fabricated.
|
|
164
|
+
async function gitBlame(root, relPath) {
|
|
165
|
+
const result = await runFile('git', ['blame', '--line-porcelain', 'HEAD', '--', relPath], {
|
|
166
|
+
cwd: root,
|
|
167
|
+
timeoutMs: 5000,
|
|
168
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
169
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
170
|
+
});
|
|
171
|
+
// git missing / not a repo / binary / non-zero exit → unknown, not fabricated.
|
|
172
|
+
if (!result.ok)
|
|
183
173
|
return null;
|
|
184
|
-
|
|
185
|
-
return parseBlamePorcelain(out);
|
|
174
|
+
return parseBlamePorcelain(result.stdout);
|
|
186
175
|
}
|
|
187
176
|
export async function handleMemoryFile(deps, params) {
|
|
188
177
|
const root = resolveProjectRoot(deps, params.projectId);
|
|
189
178
|
const abs = resolveMemoryFilePath(root, params.path);
|
|
190
179
|
const st = fs.statSync(abs);
|
|
191
180
|
const content = fs.readFileSync(abs, 'utf8');
|
|
181
|
+
// Both git probes are independent child processes: run them concurrently.
|
|
182
|
+
const [lineDiff, blame] = await Promise.all([
|
|
183
|
+
gitLineDiff(root, params.path),
|
|
184
|
+
gitBlame(root, params.path),
|
|
185
|
+
]);
|
|
192
186
|
return {
|
|
193
187
|
projectId: params.projectId,
|
|
194
188
|
path: params.path,
|
|
195
189
|
content,
|
|
196
190
|
sizeBytes: st.size,
|
|
197
191
|
modifiedAt: st.mtime.toISOString(),
|
|
198
|
-
lineDiff
|
|
199
|
-
blame
|
|
192
|
+
lineDiff,
|
|
193
|
+
blame,
|
|
200
194
|
};
|
|
201
195
|
}
|
|
@@ -3,7 +3,7 @@ import { countWaitingOn } from './waitpoints.js';
|
|
|
3
3
|
import { sessionTotalsCarry } from '../../../store/session-totals-repo.js';
|
|
4
4
|
import { addTotalsAcc, emptyTotalsAcc, foldExecution, toSessionTotals, } from '../../../store/session-totals.js';
|
|
5
5
|
import { projectCompactHistory, projectSubagentHistory } from '../../../store/conversation-display-projection.js';
|
|
6
|
-
import { isDebugMode
|
|
6
|
+
import { isDebugMode } from '../../../core/debug-mode.js';
|
|
7
7
|
export async function handleSessionsList(deps, params) {
|
|
8
8
|
const { projectId, resumable, origin } = params;
|
|
9
9
|
let sessions;
|
|
@@ -68,6 +68,21 @@ export async function handleSessionsList(deps, params) {
|
|
|
68
68
|
const live = totalsBySession.get(sessionId);
|
|
69
69
|
totalsBySession.set(sessionId, addTotalsAcc(live ?? emptyTotalsAcc(), carried));
|
|
70
70
|
}
|
|
71
|
+
// Every row asks the same question — can this session's profile compact? — and the answer is a
|
|
72
|
+
// function of (backend, profileName) alone, of which a list holds a handful. Asking per row made
|
|
73
|
+
// a 300-session list resolve (and revalidate) profiles.json 300 times per request.
|
|
74
|
+
const compactionByProfile = new Map();
|
|
75
|
+
const supportsCompaction = (session) => {
|
|
76
|
+
if (!deps.supportsSessionCompaction)
|
|
77
|
+
return false;
|
|
78
|
+
const key = `${session.backend}\u0000${session.profileName ?? ''}`;
|
|
79
|
+
const known = compactionByProfile.get(key);
|
|
80
|
+
if (known !== undefined)
|
|
81
|
+
return known;
|
|
82
|
+
const supported = deps.supportsSessionCompaction(session);
|
|
83
|
+
compactionByProfile.set(key, supported);
|
|
84
|
+
return supported;
|
|
85
|
+
};
|
|
71
86
|
const resolveNumTurns = (sessionId, inTurn, liveNumTurns) => {
|
|
72
87
|
if (inTurn)
|
|
73
88
|
return liveNumTurns;
|
|
@@ -124,13 +139,15 @@ export async function handleSessionsList(deps, params) {
|
|
|
124
139
|
resumable: s.kind !== 'scheduled',
|
|
125
140
|
label: s.label ?? null,
|
|
126
141
|
profileName: s.profileName ?? null,
|
|
142
|
+
// The environment half of the same question: which agent template the session runs as.
|
|
143
|
+
agentName: s.agentName ?? null,
|
|
127
144
|
// The other half of "what will the next turn run": the profile alone would misreport every
|
|
128
145
|
// session whose model or thinking level the user picked in the composer.
|
|
129
146
|
selectionOverride: deps.getChannelSelectionOverride?.(s.channel) ?? null,
|
|
130
147
|
browser: s.browser ?? null,
|
|
131
148
|
contextUsage: s.contextUsage ?? null,
|
|
132
149
|
todos: deps.getSessionTodos?.(s.sessionId) ?? null,
|
|
133
|
-
contextCompactionSupported:
|
|
150
|
+
contextCompactionSupported: supportsCompaction({ backend: s.backend, profileName: s.profileName ?? null }),
|
|
134
151
|
running,
|
|
135
152
|
backgroundRunning: bgHeld,
|
|
136
153
|
awaitingInput,
|
|
@@ -181,8 +198,9 @@ function transcriptDebugDetails(ev) {
|
|
|
181
198
|
return undefined;
|
|
182
199
|
if (ev.type !== 'tool')
|
|
183
200
|
return ev.debug;
|
|
184
|
-
|
|
185
|
-
|
|
201
|
+
// Stamped by the fold from the row's own serialized size; the query trusts it rather than
|
|
202
|
+
// re-weighing the parsed input once per tool row per request.
|
|
203
|
+
const warned = ev.debug.overCharacterThreshold === true;
|
|
186
204
|
if (!ev.debug.toolRef && !warned)
|
|
187
205
|
return undefined;
|
|
188
206
|
return {
|
|
@@ -297,6 +315,55 @@ async function compactHistory(deps, sessionId) {
|
|
|
297
315
|
const history = await deps.conversationHistory.getHistory(sessionId, { includeToolDebug: false });
|
|
298
316
|
return history ? projectCompactHistory(history) : null;
|
|
299
317
|
}
|
|
318
|
+
/** Compact history plus the cursor a client passes back as `since`. Stores that cannot produce a
|
|
319
|
+
* cursor simply do not get deltas — every response stays a full transcript. */
|
|
320
|
+
async function compactHistoryAt(deps, sessionId) {
|
|
321
|
+
if (deps.conversationHistory.getCompactHistoryAt) {
|
|
322
|
+
return deps.conversationHistory.getCompactHistoryAt(sessionId);
|
|
323
|
+
}
|
|
324
|
+
return { value: await compactHistory(deps, sessionId), cursor: undefined };
|
|
325
|
+
}
|
|
326
|
+
/** A row whose rendered form depends on wall-clock time or live server state rather than on the
|
|
327
|
+
* stored history, so its revision cannot say whether it changed. Always re-sent in a delta. */
|
|
328
|
+
function isVolatileRow(event) {
|
|
329
|
+
// Only a PENDING interaction is derived: its card can expire on the clock or flip when the
|
|
330
|
+
// server stops holding the question open. Once resolved the row renders from stored fields.
|
|
331
|
+
return event.type === 'interaction' && !!event.id && (event.status ?? 'pending') === 'pending';
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Rows added or changed since `sinceRev`. Walks the whole event stream — `elapsedMs` is a
|
|
335
|
+
* difference against the PREVIOUS row, so the running timestamp has to be carried across rows that
|
|
336
|
+
* are not being sent — but only builds a DTO for the rows it emits, which is the part that costs.
|
|
337
|
+
*/
|
|
338
|
+
function transcriptDeltaRows(deps, events, revs, sinceRev) {
|
|
339
|
+
const changed = [];
|
|
340
|
+
let previousMs = null;
|
|
341
|
+
events.forEach((event, index) => {
|
|
342
|
+
const elapsed = eventElapsedMs(event, previousMs);
|
|
343
|
+
previousMs = nextPreviousMs(event);
|
|
344
|
+
if ((revs[index] ?? 0) <= sinceRev && !isVolatileRow(event))
|
|
345
|
+
return;
|
|
346
|
+
changed.push({ index, turnIndex: event.turnIndex, message: messageFromEvent(deps, event, elapsed) });
|
|
347
|
+
});
|
|
348
|
+
return changed;
|
|
349
|
+
}
|
|
350
|
+
/** `<epoch>:<revision>`; a differing epoch means the session was rewritten and the cursor is void. */
|
|
351
|
+
function parseCursor(cursor) {
|
|
352
|
+
if (!cursor)
|
|
353
|
+
return null;
|
|
354
|
+
const at = cursor.lastIndexOf(':');
|
|
355
|
+
if (at <= 0)
|
|
356
|
+
return null;
|
|
357
|
+
const revision = Number(cursor.slice(at + 1));
|
|
358
|
+
return Number.isSafeInteger(revision) && revision >= 0 ? { epoch: cursor.slice(0, at), revision } : null;
|
|
359
|
+
}
|
|
360
|
+
function transcriptDelta(deps, events, revs, since, cursor) {
|
|
361
|
+
const from = parseCursor(since);
|
|
362
|
+
const now = parseCursor(cursor);
|
|
363
|
+
if (!from || !now || !revs || from.epoch !== now.epoch || from.revision > now.revision)
|
|
364
|
+
return null;
|
|
365
|
+
return { changed: transcriptDeltaRows(deps, events, revs, from.revision), total: events.length };
|
|
366
|
+
}
|
|
300
367
|
async function subagentHistory(deps, sessionId, subagentId) {
|
|
301
368
|
if (deps.conversationHistory.getSubagentHistory) {
|
|
302
369
|
return deps.conversationHistory.getSubagentHistory(sessionId, subagentId);
|
|
@@ -316,8 +383,21 @@ async function fullTranscript(deps, params, pendingSnapshot) {
|
|
|
316
383
|
return sessionTranscript(deps, params.sessionId, history?.events ?? [], pendingMessages(pendingSnapshot, history?.committedSourceIds));
|
|
317
384
|
}
|
|
318
385
|
async function compactTranscript(deps, params, pendingSnapshot) {
|
|
319
|
-
const history = await
|
|
320
|
-
|
|
386
|
+
const { value: history, cursor } = await compactHistoryAt(deps, params.sessionId);
|
|
387
|
+
const events = history?.events ?? [];
|
|
388
|
+
const pendingUserMessages = pendingMessages(pendingSnapshot, history?.committedSourceIds);
|
|
389
|
+
const subagentSummaries = history?.subagentSummaries ?? [];
|
|
390
|
+
// Pending messages and subagent summaries are per-session, not per-row, and small: they ride
|
|
391
|
+
// every response whole, so a delta only ever has to describe transcript ROWS.
|
|
392
|
+
const delta = cursor === undefined
|
|
393
|
+
? null
|
|
394
|
+
: transcriptDelta(deps, events, history?.eventRevs, params.since, cursor);
|
|
395
|
+
// Built only when it is going to be sent — assembling every row's DTO is the server-side cost a
|
|
396
|
+
// delta exists to avoid, so the whole-transcript path must not run underneath it.
|
|
397
|
+
if (delta)
|
|
398
|
+
return { sessionId: params.sessionId, turns: [], pendingUserMessages, subagentSummaries, cursor, delta };
|
|
399
|
+
const base = sessionTranscript(deps, params.sessionId, events, pendingUserMessages, subagentSummaries);
|
|
400
|
+
return cursor === undefined ? base : { ...base, cursor };
|
|
321
401
|
}
|
|
322
402
|
export async function handleSessionsTranscript(deps, params) {
|
|
323
403
|
const pendingSnapshot = await pendingUserSnapshot(deps, params.sessionId);
|
|
@@ -336,12 +416,9 @@ export async function handleSessionsSubagentTranscript(deps, params) {
|
|
|
336
416
|
export async function handleSessionsDebugDetails(deps, params) {
|
|
337
417
|
if (!isDebugMode() || !deps.conversationHistory.getToolDebugDetails)
|
|
338
418
|
return null;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (!isDebugToolOverWarningThreshold(details))
|
|
343
|
-
return details;
|
|
344
|
-
return { ...details, overCharacterThreshold: true };
|
|
419
|
+
// The store stamps `overCharacterThreshold` while it reads the rows, so there is nothing left
|
|
420
|
+
// to derive here.
|
|
421
|
+
return await deps.conversationHistory.getToolDebugDetails(params.sessionId, params.ref);
|
|
345
422
|
}
|
|
346
423
|
// ── sessions.pendingInteraction ───────────────────────────────────
|
|
347
424
|
// Returns the current pending ask-user or plan approval for a session, if any.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { STORE_DIR } from '../../../core/paths.js';
|
|
4
|
+
import { readRebuildProgress } from '../../../core/rebuild-progress.js';
|
|
4
5
|
import { getThrottleState } from '../../costs/rate-limit-throttle.js';
|
|
5
6
|
import { getResumeCountsByProvider } from '../../costs/resume-registry.js';
|
|
6
7
|
import { usageService } from '../../costs/usage-service.js';
|
|
@@ -116,8 +117,26 @@ export async function handleSystemDaemonStatus(_params) {
|
|
|
116
117
|
return {
|
|
117
118
|
processes,
|
|
118
119
|
lastRestart: { at: lastRestartAt, reason: lastRestartReason },
|
|
120
|
+
rebuild: liveRebuildProgress(daemonPid, daemonAlive),
|
|
119
121
|
};
|
|
120
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The supervisor's published pipeline record, or null.
|
|
125
|
+
*
|
|
126
|
+
* A record left `running` by a supervisor that has since died would otherwise render as a rebuild
|
|
127
|
+
* that never ends, so it is dropped unless the daemon that wrote it is the one currently alive. A
|
|
128
|
+
* terminal record is kept regardless of who wrote it: "the last rebuild did X" stays true across
|
|
129
|
+
* supervisor restarts.
|
|
130
|
+
*/
|
|
131
|
+
function liveRebuildProgress(daemonPid, daemonAlive) {
|
|
132
|
+
const progress = readRebuildProgress();
|
|
133
|
+
if (!progress)
|
|
134
|
+
return null;
|
|
135
|
+
if (progress.status !== 'running')
|
|
136
|
+
return progress;
|
|
137
|
+
const ownerAlive = daemonAlive && daemonPid !== null && progress.daemonPid === daemonPid;
|
|
138
|
+
return ownerAlive ? progress : null;
|
|
139
|
+
}
|
|
121
140
|
export async function handleSystemRateLimitStatus(_params) {
|
|
122
141
|
const waiting = getResumeCountsByProvider();
|
|
123
142
|
const providers = getThrottleState().providers.map((provider) => ({
|
|
@@ -11,6 +11,7 @@ export declare const sessionsListInput: z.ZodObject<{
|
|
|
11
11
|
export declare const sessionsTranscriptInput: z.ZodObject<{
|
|
12
12
|
sessionId: z.ZodString;
|
|
13
13
|
compactSubagents: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
since: z.ZodOptional<z.ZodString>;
|
|
14
15
|
}, z.core.$strip>;
|
|
15
16
|
export declare const sessionsSubagentTranscriptInput: z.ZodObject<{
|
|
16
17
|
sessionId: z.ZodString;
|
|
@@ -7,6 +7,8 @@ export const sessionsListInput = z.object({
|
|
|
7
7
|
export const sessionsTranscriptInput = z.object({
|
|
8
8
|
sessionId: z.string(),
|
|
9
9
|
compactSubagents: z.boolean().optional(),
|
|
10
|
+
/** Cursor from a previous response. Asks for the rows that changed since it, not the transcript. */
|
|
11
|
+
since: z.string().max(64).optional(),
|
|
10
12
|
});
|
|
11
13
|
export const sessionsSubagentTranscriptInput = z.object({
|
|
12
14
|
sessionId: z.string(),
|