crewly 1.20.89 → 1.20.90
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/config/roles/orchestrator/fragments/communication.md +3 -3
- package/config/roles/orchestrator/fragments/recovery.md +5 -6
- package/config/skills/orchestrator/get-tasks/SKILL.md +13 -1
- package/config/skills/orchestrator/get-tasks/execute.sh +53 -14
- package/dist/backend/backend/src/constants.d.ts +32 -0
- package/dist/backend/backend/src/constants.d.ts.map +1 -1
- package/dist/backend/backend/src/constants.js +32 -0
- package/dist/backend/backend/src/constants.js.map +1 -1
- package/dist/backend/backend/src/controllers/chat/chat.controller.d.ts +8 -0
- package/dist/backend/backend/src/controllers/chat/chat.controller.d.ts.map +1 -1
- package/dist/backend/backend/src/controllers/chat/chat.controller.js +14 -1
- package/dist/backend/backend/src/controllers/chat/chat.controller.js.map +1 -1
- package/dist/backend/backend/src/services/agent/agent-registration.service.d.ts +18 -0
- package/dist/backend/backend/src/services/agent/agent-registration.service.d.ts.map +1 -1
- package/dist/backend/backend/src/services/agent/agent-registration.service.js +73 -4
- package/dist/backend/backend/src/services/agent/agent-registration.service.js.map +1 -1
- package/dist/backend/backend/src/services/agent/runtime-session-recovery.d.ts +35 -0
- package/dist/backend/backend/src/services/agent/runtime-session-recovery.d.ts.map +1 -1
- package/dist/backend/backend/src/services/agent/runtime-session-recovery.js +140 -1
- package/dist/backend/backend/src/services/agent/runtime-session-recovery.js.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.d.ts.map +1 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.js +9 -1
- package/dist/backend/backend/src/services/ai/prompt-modules/lifecycle.module.js.map +1 -1
- package/dist/backend/build-info.json +2 -2
- package/dist/cli/backend/src/constants.d.ts +32 -0
- package/dist/cli/backend/src/constants.d.ts.map +1 -1
- package/dist/cli/backend/src/constants.js +32 -0
- package/dist/cli/backend/src/constants.js.map +1 -1
- package/dist/cli/backend/src/services/agent/agent-registration.service.d.ts +18 -0
- package/dist/cli/backend/src/services/agent/agent-registration.service.d.ts.map +1 -1
- package/dist/cli/backend/src/services/agent/agent-registration.service.js +73 -4
- package/dist/cli/backend/src/services/agent/agent-registration.service.js.map +1 -1
- package/dist/cli/backend/src/services/agent/runtime-session-recovery.d.ts +35 -0
- package/dist/cli/backend/src/services/agent/runtime-session-recovery.d.ts.map +1 -1
- package/dist/cli/backend/src/services/agent/runtime-session-recovery.js +140 -1
- package/dist/cli/backend/src/services/agent/runtime-session-recovery.js.map +1 -1
- package/dist/cli/backend/src/services/ai/prompt-modules/lifecycle.module.d.ts.map +1 -1
- package/dist/cli/backend/src/services/ai/prompt-modules/lifecycle.module.js +9 -1
- package/dist/cli/backend/src/services/ai/prompt-modules/lifecycle.module.js.map +1 -1
- package/package.json +1 -1
|
@@ -214,6 +214,22 @@ export declare class AgentRegistrationService {
|
|
|
214
214
|
* @returns The plan
|
|
215
215
|
*/
|
|
216
216
|
private planSessionRecovery;
|
|
217
|
+
/**
|
|
218
|
+
* Decide whether the orchestrator's stored conversation is too big to
|
|
219
|
+
* resume, and if so write the handover file its fresh one will read.
|
|
220
|
+
*
|
|
221
|
+
* Only the orchestrator, only Claude Code, and only here — at a launch —
|
|
222
|
+
* so a conversation is never cut in the middle of anything. Its real
|
|
223
|
+
* state (tasks, teams, OKRs, wiki) lives in Crewly and is read back at
|
|
224
|
+
* startup; the handover keeps the tail of what was said.
|
|
225
|
+
*
|
|
226
|
+
* @param sessionName - Session being launched
|
|
227
|
+
* @param runtimeType - Its runtime
|
|
228
|
+
* @param storedSessionId - The conversation it would resume
|
|
229
|
+
* @param cwd - Its working directory
|
|
230
|
+
* @returns True when it should start fresh instead
|
|
231
|
+
*/
|
|
232
|
+
private closeOversizedOrcConversation;
|
|
217
233
|
/**
|
|
218
234
|
* For a freshly launched Codex agent, learn its conversation id from the
|
|
219
235
|
* rollout file it writes right after start and persist it. Runs in the
|
|
@@ -297,6 +313,8 @@ export declare class AgentRegistrationService {
|
|
|
297
313
|
* Such sessions get an explicit register-self kickoff instead.
|
|
298
314
|
*/
|
|
299
315
|
private readonly resumedSessions;
|
|
316
|
+
/** Handover file for an orchestrator that was just given a fresh conversation, by session. */
|
|
317
|
+
private readonly pendingHandovers;
|
|
300
318
|
/**
|
|
301
319
|
* Assemble the orchestrator prompt at the *other* profile and log the
|
|
302
320
|
* module count + token estimate of both tiers side by side, so the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-registration.service.d.ts","sourceRoot":"","sources":["../../../../../../backend/src/services/agent/agent-registration.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-registration.service.d.ts","sourceRoot":"","sources":["../../../../../../backend/src/services/agent/agent-registration.service.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,iCAAiC,EAAE,MAAM,yDAAyD,CAAC;AAK5G,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EACN,gBAAgB,EAMhB,WAAW,EAUX,MAAM,oBAAoB,CAAC;AAsE5B,MAAM,WAAW,kBAAkB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;aACnB,QAAQ,EAAE,OAAO;gBAAjB,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM;CAc/D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,IAAI,MAAM,CAQzF;AAED;;;;;;;;;GASG;AACH,qBAAa,wBAAwB;IACpC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,cAAc,CAAqC;IAC3D,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,C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AClB,CAAC;QACF,KAAK,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IAuCF;;;;;;;;;;;;;OAaG;YACW,kBAAkB;IA2LhC;;;;;;;;;OASG;IACG,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,SAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAW3E"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import * as path from 'path';
|
|
2
2
|
import * as os from 'os';
|
|
3
3
|
import { readFile, readdir, stat, mkdir, writeFile, access } from 'fs/promises';
|
|
4
|
+
import * as fsSync from 'fs';
|
|
4
5
|
import { existsSync } from 'fs';
|
|
5
6
|
import { LoggerService } from '../core/logger.service.js';
|
|
6
7
|
import { createSessionCommandHelper, getSessionBackendSync, createSessionBackend, getSessionStatePersistence, } from '../session/index.js';
|
|
7
8
|
import { RuntimeServiceFactory } from './runtime-service.factory.js';
|
|
8
9
|
import { registerInProcessRuntime, unregisterInProcessRuntime, } from './crewly-agent/in-process-runtime-registry.js';
|
|
9
10
|
import { getCrewlyHomePath } from '../core/crewly-home.utils.js';
|
|
10
|
-
import { CREWLY_CONSTANTS, ENV_CONSTANTS, AGENT_TIMEOUTS, ORCHESTRATOR_SESSION_NAME, ORCHESTRATOR_ROLE, RUNTIME_TYPES, SESSION_COMMAND_DELAYS, SESSION_RECREATION_CONSTANTS, EVENT_DELIVERY_CONSTANTS, TERMINAL_PATTERNS, GEMINI_SHELL_MODE_CONSTANTS, GEMINI_STUCK_CONNECTIVITY_PATTERN, GEMINI_ERROR_STATE_CONSTANTS, REGISTRATION_DELIVERY_CONSTANTS, } from '../../constants.js';
|
|
11
|
+
import { CREWLY_CONSTANTS, ENV_CONSTANTS, AGENT_TIMEOUTS, ORCHESTRATOR_SESSION_NAME, ORCHESTRATOR_ROLE, RUNTIME_TYPES, SESSION_COMMAND_DELAYS, SESSION_RECREATION_CONSTANTS, EVENT_DELIVERY_CONSTANTS, TERMINAL_PATTERNS, GEMINI_SHELL_MODE_CONSTANTS, GEMINI_STUCK_CONNECTIVITY_PATTERN, GEMINI_ERROR_STATE_CONSTANTS, REGISTRATION_DELIVERY_CONSTANTS, ORC_CONVERSATION_CONSTANTS, } from '../../constants.js';
|
|
11
12
|
import { WEB_CONSTANTS } from '../../../../config/constants.js';
|
|
12
13
|
import { delay } from '../../utils/async.utils.js';
|
|
13
14
|
import { buildRuntimeModelFlags } from '../../utils/runtime-model-flags.utils.js';
|
|
@@ -28,7 +29,7 @@ import { stripAnsiCodes } from '../../utils/terminal-output.utils.js';
|
|
|
28
29
|
import { isPromptLine, containsSpinnerOrWorkingIndicator, containsProcessingIndicator, containsBusyStatusBar, containsRewindMode, extractChatPrefix, stripTuiLineBorders, matchTuiPromptLine, } from '../../utils/terminal-string-ops.js';
|
|
29
30
|
import { PtyActivityTrackerService } from './pty-activity-tracker.service.js';
|
|
30
31
|
import { synthesizeSlackConversationId } from '../chat-v2/legacy-dto.utils.js';
|
|
31
|
-
import { conversationExists, planRuntimeSessionFlags, waitForCodexSessionId } from './runtime-session-recovery.js';
|
|
32
|
+
import { buildHandoverSummary, claudeTranscriptPath, conversationExists, lastTurnContextTokens, orcFreshContextTokens, planRuntimeSessionFlags, waitForCodexSessionId, } from './runtime-session-recovery.js';
|
|
32
33
|
/**
|
|
33
34
|
* Whether a file exists (readable).
|
|
34
35
|
*
|
|
@@ -687,11 +688,16 @@ export class AgentRegistrationService {
|
|
|
687
688
|
});
|
|
688
689
|
}
|
|
689
690
|
const storedSessionId = persistence?.getSessionId(sessionName) ?? null;
|
|
691
|
+
// An orchestrator whose conversation has grown too big starts over here,
|
|
692
|
+
// at a restart, rather than re-reading it on every turn.
|
|
693
|
+
const freshInstead = autoResume && storedSessionId && cwd
|
|
694
|
+
? this.closeOversizedOrcConversation(sessionName, runtimeType, storedSessionId, cwd)
|
|
695
|
+
: false;
|
|
690
696
|
const plan = planRuntimeSessionFlags({
|
|
691
697
|
runtimeType,
|
|
692
698
|
isRestored: persistence?.isRestoredSession(sessionName) ?? false,
|
|
693
699
|
storedSessionId,
|
|
694
|
-
autoResume,
|
|
700
|
+
autoResume: autoResume && !freshInstead,
|
|
695
701
|
conversationExists: storedSessionId && cwd ? conversationExists({ runtimeType, sessionId: storedSessionId, cwd }) : undefined,
|
|
696
702
|
});
|
|
697
703
|
effectiveFlags.push(...plan.flags);
|
|
@@ -714,6 +720,61 @@ export class AgentRegistrationService {
|
|
|
714
720
|
});
|
|
715
721
|
return plan;
|
|
716
722
|
}
|
|
723
|
+
/**
|
|
724
|
+
* Decide whether the orchestrator's stored conversation is too big to
|
|
725
|
+
* resume, and if so write the handover file its fresh one will read.
|
|
726
|
+
*
|
|
727
|
+
* Only the orchestrator, only Claude Code, and only here — at a launch —
|
|
728
|
+
* so a conversation is never cut in the middle of anything. Its real
|
|
729
|
+
* state (tasks, teams, OKRs, wiki) lives in Crewly and is read back at
|
|
730
|
+
* startup; the handover keeps the tail of what was said.
|
|
731
|
+
*
|
|
732
|
+
* @param sessionName - Session being launched
|
|
733
|
+
* @param runtimeType - Its runtime
|
|
734
|
+
* @param storedSessionId - The conversation it would resume
|
|
735
|
+
* @param cwd - Its working directory
|
|
736
|
+
* @returns True when it should start fresh instead
|
|
737
|
+
*/
|
|
738
|
+
closeOversizedOrcConversation(sessionName, runtimeType, storedSessionId, cwd) {
|
|
739
|
+
if (sessionName !== ORCHESTRATOR_SESSION_NAME || runtimeType !== RUNTIME_TYPES.CLAUDE_CODE)
|
|
740
|
+
return false;
|
|
741
|
+
const transcript = claudeTranscriptPath({ sessionId: storedSessionId, cwd });
|
|
742
|
+
const tokens = lastTurnContextTokens(transcript);
|
|
743
|
+
const threshold = orcFreshContextTokens();
|
|
744
|
+
if (tokens === null || tokens < threshold)
|
|
745
|
+
return false;
|
|
746
|
+
try {
|
|
747
|
+
const dir = path.join(getCrewlyHomePath(), ORC_CONVERSATION_CONSTANTS.HANDOVER_DIR);
|
|
748
|
+
fsSync.mkdirSync(dir, { recursive: true });
|
|
749
|
+
const file = path.join(dir, `${sessionName}-${new Date().toISOString().replace(/[:.]/g, '-')}.md`);
|
|
750
|
+
const body = buildHandoverSummary(transcript);
|
|
751
|
+
fsSync.writeFileSync(file, [
|
|
752
|
+
`# Handover from your previous conversation`,
|
|
753
|
+
``,
|
|
754
|
+
`Your previous conversation (${storedSessionId}) had grown to ${tokens.toLocaleString('en-US')} tokens per turn and was closed at a restart.`,
|
|
755
|
+
`Everything Crewly tracks — tasks, teams, OKRs, wiki — is still there; this file keeps only the end of what was said.`,
|
|
756
|
+
`The full transcript: ${transcript}`,
|
|
757
|
+
``,
|
|
758
|
+
body || '_Nothing readable was found at the end of the old conversation._',
|
|
759
|
+
``,
|
|
760
|
+
].join('\n'), 'utf-8');
|
|
761
|
+
this.pendingHandovers.set(sessionName, { path: file, tokens });
|
|
762
|
+
this.logger.info('Orchestrator conversation too big to resume — starting fresh with a handover', {
|
|
763
|
+
sessionName,
|
|
764
|
+
tokens,
|
|
765
|
+
threshold,
|
|
766
|
+
handover: file,
|
|
767
|
+
});
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
catch (err) {
|
|
771
|
+
this.logger.warn('Could not write the orchestrator handover — resuming the old conversation', {
|
|
772
|
+
sessionName,
|
|
773
|
+
error: err instanceof Error ? err.message : String(err),
|
|
774
|
+
});
|
|
775
|
+
return false;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
717
778
|
/**
|
|
718
779
|
* For a freshly launched Codex agent, learn its conversation id from the
|
|
719
780
|
* rollout file it writes right after start and persist it. Runs in the
|
|
@@ -863,6 +924,8 @@ export class AgentRegistrationService {
|
|
|
863
924
|
* Such sessions get an explicit register-self kickoff instead.
|
|
864
925
|
*/
|
|
865
926
|
resumedSessions = new Map();
|
|
927
|
+
/** Handover file for an orchestrator that was just given a fresh conversation, by session. */
|
|
928
|
+
pendingHandovers = new Map();
|
|
866
929
|
/**
|
|
867
930
|
* Assemble the orchestrator prompt at the *other* profile and log the
|
|
868
931
|
* module count + token estimate of both tiers side by side, so the
|
|
@@ -5073,8 +5136,14 @@ Loop until done, blocked, or explicitly reassigned:
|
|
|
5073
5136
|
// Gemini CLI / other runtimes: need the file-read instruction since the prompt
|
|
5074
5137
|
// was NOT loaded via system prompt.
|
|
5075
5138
|
const resumedRole = this.resumedSessions.get(sessionName);
|
|
5139
|
+
const handover = this.pendingHandovers.get(sessionName);
|
|
5140
|
+
if (handover)
|
|
5141
|
+
this.pendingHandovers.delete(sessionName);
|
|
5076
5142
|
const messageToSend = isClaudeCode
|
|
5077
|
-
? 'Begin your work now. Follow the step-by-step instructions in your agent definition EXACTLY — start with Step 1, then Step 2, then Step 3 (register-self). Do NOT skip or reorder steps. Registration is required before the system will deliver messages to you.'
|
|
5143
|
+
? 'Begin your work now. Follow the step-by-step instructions in your agent definition EXACTLY — start with Step 1, then Step 2, then Step 3 (register-self). Do NOT skip or reorder steps. Registration is required before the system will deliver messages to you.' +
|
|
5144
|
+
(handover
|
|
5145
|
+
? ` This is a fresh conversation: your previous one had grown to ${handover.tokens} tokens and was closed. After registering, read ${handover.path} once — it holds the end of what was said before.`
|
|
5146
|
+
: '')
|
|
5078
5147
|
: resumedRole
|
|
5079
5148
|
? this.resumedKickoff(sessionName, resumedRole, promptFilePath)
|
|
5080
5149
|
: `Read the file at ${promptFilePath} and follow all instructions in it.`;
|