praxis-agent 0.20.16 → 0.20.18
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/dist/application/scheduled-prompt-manager.d.ts +4 -0
- package/dist/application/scheduled-prompt-manager.js +31 -2
- package/dist/application/session-service.d.ts +6 -1
- package/dist/application/session-service.js +97 -13
- package/dist/compatibility/claude/paths.d.ts +15 -0
- package/dist/compatibility/claude/paths.js +101 -1
- package/package.json +1 -1
|
@@ -38,6 +38,7 @@ export declare class ScheduledPromptManager {
|
|
|
38
38
|
private readonly sessionTasks;
|
|
39
39
|
private readonly dueAt;
|
|
40
40
|
private readonly dueQueue;
|
|
41
|
+
private readonly pendingConfirmations;
|
|
41
42
|
private readonly dynamicWakeups;
|
|
42
43
|
private readonly dynamicLoopStates;
|
|
43
44
|
private readonly durableIds;
|
|
@@ -54,6 +55,9 @@ export declare class ScheduledPromptManager {
|
|
|
54
55
|
create(input: CreateScheduledPromptInput): Promise<ListedScheduledPrompt>;
|
|
55
56
|
list(): Promise<ListedScheduledPrompt[]>;
|
|
56
57
|
delete(id: string): Promise<boolean>;
|
|
58
|
+
pendingScheduledPrompts(): ScheduledPrompt[];
|
|
59
|
+
approveScheduledPrompt(id: string): boolean;
|
|
60
|
+
declineScheduledPrompt(id: string): boolean;
|
|
57
61
|
scheduleWakeup(input: {
|
|
58
62
|
delaySeconds: number;
|
|
59
63
|
prompt: string;
|
|
@@ -97,6 +97,7 @@ export class ScheduledPromptManager {
|
|
|
97
97
|
sessionTasks = new Map();
|
|
98
98
|
dueAt = new Map();
|
|
99
99
|
dueQueue = [];
|
|
100
|
+
pendingConfirmations = new Map();
|
|
100
101
|
dynamicWakeups = new Map();
|
|
101
102
|
dynamicLoopStates = new Map();
|
|
102
103
|
durableIds = new Set();
|
|
@@ -181,10 +182,29 @@ export class ScheduledPromptManager {
|
|
|
181
182
|
async delete(id) {
|
|
182
183
|
await this.initialize();
|
|
183
184
|
const removed = await this.removeTask(id);
|
|
184
|
-
|
|
185
|
+
const declined = this.pendingConfirmations.delete(id);
|
|
186
|
+
if (removed || declined) {
|
|
185
187
|
this.dueAt.delete(id);
|
|
186
188
|
this.notifyChange();
|
|
187
189
|
}
|
|
190
|
+
return removed || declined;
|
|
191
|
+
}
|
|
192
|
+
pendingScheduledPrompts() {
|
|
193
|
+
return [...this.pendingConfirmations.values()];
|
|
194
|
+
}
|
|
195
|
+
approveScheduledPrompt(id) {
|
|
196
|
+
const pending = this.pendingConfirmations.get(id);
|
|
197
|
+
if (!pending)
|
|
198
|
+
return false;
|
|
199
|
+
this.pendingConfirmations.delete(id);
|
|
200
|
+
this.dueQueue.push(pending);
|
|
201
|
+
this.notifyChange();
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
declineScheduledPrompt(id) {
|
|
205
|
+
const removed = this.pendingConfirmations.delete(id);
|
|
206
|
+
if (removed)
|
|
207
|
+
this.notifyChange();
|
|
188
208
|
return removed;
|
|
189
209
|
}
|
|
190
210
|
scheduleWakeup(input) {
|
|
@@ -278,6 +298,7 @@ export class ScheduledPromptManager {
|
|
|
278
298
|
this.sessionTasks.clear();
|
|
279
299
|
this.dueAt.clear();
|
|
280
300
|
this.durableIds.clear();
|
|
301
|
+
this.pendingConfirmations.clear();
|
|
281
302
|
this.dueQueue.length = 0;
|
|
282
303
|
this.notifyChange();
|
|
283
304
|
}
|
|
@@ -316,7 +337,15 @@ export class ScheduledPromptManager {
|
|
|
316
337
|
if (this.closed)
|
|
317
338
|
return;
|
|
318
339
|
this.durableIds.delete(task.id);
|
|
319
|
-
|
|
340
|
+
if (task.recurring) {
|
|
341
|
+
this.dueQueue.push({ id: task.id, prompt: task.prompt });
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
this.pendingConfirmations.set(task.id, {
|
|
345
|
+
id: task.id,
|
|
346
|
+
prompt: task.prompt,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
320
349
|
}
|
|
321
350
|
}
|
|
322
351
|
}
|
|
@@ -13,6 +13,7 @@ import type { ClaudeHookRunner } from '../hooks/claude-hooks.js';
|
|
|
13
13
|
import { type TranscriptParseIssue } from '../persistence/claude-transcript-store.js';
|
|
14
14
|
import type { ClaudeCostStateStore } from '../persistence/claude-cost-state-store.js';
|
|
15
15
|
import { type AgentPermissionMode } from './subagent-service.js';
|
|
16
|
+
import { type ScheduledPrompt } from './scheduled-prompt-manager.js';
|
|
16
17
|
import { type WorkflowTaskSnapshot } from './workflow-manager.js';
|
|
17
18
|
import type { WorkspaceContext } from './session-worktree.js';
|
|
18
19
|
import { type ClaudeSessionCostSnapshot } from './session-cost-tracker.js';
|
|
@@ -157,6 +158,7 @@ export declare class ClaudeSessionService {
|
|
|
157
158
|
private readonly backgroundTasks;
|
|
158
159
|
private readonly worktreeManager;
|
|
159
160
|
private readonly sessionCwds;
|
|
161
|
+
private readonly discoveredProjectRoots;
|
|
160
162
|
private readonly sessionPermissionUpdates;
|
|
161
163
|
private readonly hostedSubagents;
|
|
162
164
|
private readonly hostedSubagentsByRegistry;
|
|
@@ -169,7 +171,9 @@ export declare class ClaudeSessionService {
|
|
|
169
171
|
private closeCostSavePromise;
|
|
170
172
|
private runtimeCwd;
|
|
171
173
|
constructor(options: ClaudeSessionServiceOptions);
|
|
172
|
-
nextScheduledPrompt(signal?: AbortSignal): Promise<
|
|
174
|
+
nextScheduledPrompt(signal?: AbortSignal): Promise<ScheduledPrompt | null>;
|
|
175
|
+
private nextScheduledPromptForManager;
|
|
176
|
+
private confirmPendingScheduledPrompt;
|
|
173
177
|
workflows(): readonly WorkflowTaskSnapshot[];
|
|
174
178
|
mcpInspect(): Promise<readonly ClaudeMcpServerStatus[]>;
|
|
175
179
|
mcpReconnect(name: string): Promise<void>;
|
|
@@ -231,6 +235,7 @@ export declare class ClaudeSessionService {
|
|
|
231
235
|
private activeCwd;
|
|
232
236
|
private restoreWorktree;
|
|
233
237
|
private paths;
|
|
238
|
+
private discoverProjectRoot;
|
|
234
239
|
private appendCdCommand;
|
|
235
240
|
private appendAgentColorUsage;
|
|
236
241
|
private appendSystemLocalCommand;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { appendFile, copyFile, link, lstat, mkdir, readdir, realpath, stat, unlink, } from 'node:fs/promises';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { basename, extname, isAbsolute, join, relative } from 'node:path';
|
|
4
|
+
import { basename, extname, isAbsolute, join, relative, resolve, } from 'node:path';
|
|
5
5
|
import { AGENT_COLOR_DEFAULT, agentColorMessage, getClaudeEffectiveAgentColor, } from '../compatibility/claude/agent-color.js';
|
|
6
6
|
import { createClaudeCompactEntries, formatClaudeCompactSummary, getCumulativeDroppedTokens, } from '../compatibility/claude/compaction.js';
|
|
7
|
-
import { isClaudeSessionId, resolveClaudePaths, resolveClaudeScheduledTaskFile, } from '../compatibility/claude/paths.js';
|
|
7
|
+
import { discoverClaudeProjectRoot, isClaudeSessionId, resolveClaudePaths, resolveClaudeScheduledTaskFile, } from '../compatibility/claude/paths.js';
|
|
8
8
|
import { downloadClaudeFileResources, } from '../compatibility/claude/file-resources.js';
|
|
9
9
|
import { createClaudeNativeFork } from '../compatibility/claude/fork.js';
|
|
10
10
|
import { selectClaudeActiveTranscript, selectClaudeTranscriptAtMessage, } from '../compatibility/claude/history.js';
|
|
@@ -24,7 +24,7 @@ import { ClaudeTranscriptStore, } from '../persistence/claude-transcript-store.j
|
|
|
24
24
|
import { InMemoryTranscriptStore } from '../persistence/in-memory-transcript-store.js';
|
|
25
25
|
import { ModelCompactor } from './model-compactor.js';
|
|
26
26
|
import { agentMemoryPrompt, ClaudeSubagentExecutor, StructuredOutputRegistry, } from './subagent-service.js';
|
|
27
|
-
import { ScheduledPromptManager } from './scheduled-prompt-manager.js';
|
|
27
|
+
import { ScheduledPromptManager, } from './scheduled-prompt-manager.js';
|
|
28
28
|
import { ClaudeScheduledToolRegistry } from '../tools/claude-scheduled-tools.js';
|
|
29
29
|
import { ClaudeTaskToolRegistry } from '../tools/claude-task-tools.js';
|
|
30
30
|
import { ClaudeWorkflowToolRegistry } from '../tools/claude-workflow-tools.js';
|
|
@@ -312,6 +312,7 @@ export class ClaudeSessionService {
|
|
|
312
312
|
backgroundTasks;
|
|
313
313
|
worktreeManager;
|
|
314
314
|
sessionCwds = new Map();
|
|
315
|
+
discoveredProjectRoots = new Map();
|
|
315
316
|
sessionPermissionUpdates = new Map();
|
|
316
317
|
hostedSubagents = new Set();
|
|
317
318
|
hostedSubagentsByRegistry = new WeakMap();
|
|
@@ -359,7 +360,53 @@ export class ClaudeSessionService {
|
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
362
|
nextScheduledPrompt(signal) {
|
|
362
|
-
|
|
363
|
+
const manager = this.scheduledPrompts;
|
|
364
|
+
if (!manager)
|
|
365
|
+
return Promise.resolve(null);
|
|
366
|
+
return this.nextScheduledPromptForManager(manager, signal);
|
|
367
|
+
}
|
|
368
|
+
async nextScheduledPromptForManager(manager, signal) {
|
|
369
|
+
// Scan durable tasks so a missed one-shot surfaces as a pending
|
|
370
|
+
// confirmation instead of silently entering the normal due drain.
|
|
371
|
+
await manager.list();
|
|
372
|
+
const pending = manager.pendingScheduledPrompts()[0];
|
|
373
|
+
if (!pending)
|
|
374
|
+
return manager.next(signal);
|
|
375
|
+
const askUser = this.options.interactiveTools?.callbacks.askUser;
|
|
376
|
+
if (!askUser)
|
|
377
|
+
return manager.next(signal);
|
|
378
|
+
const approved = await this.confirmPendingScheduledPrompt(manager, pending, askUser, signal);
|
|
379
|
+
if (!approved)
|
|
380
|
+
return null;
|
|
381
|
+
// Consume the approved prompt from the scheduler due queue exactly once.
|
|
382
|
+
return manager.next(signal);
|
|
383
|
+
}
|
|
384
|
+
async confirmPendingScheduledPrompt(manager, pending, askUser, signal) {
|
|
385
|
+
const question = {
|
|
386
|
+
header: 'Missed scheduled prompt',
|
|
387
|
+
question: pending.prompt,
|
|
388
|
+
options: [
|
|
389
|
+
{
|
|
390
|
+
label: 'Run now',
|
|
391
|
+
description: 'Run this scheduled prompt that was missed while Praxis was not running.',
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
label: 'Skip',
|
|
395
|
+
description: 'Decline this scheduled prompt and discard it.',
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
multiSelect: false,
|
|
399
|
+
};
|
|
400
|
+
const result = await askUser([question], signal);
|
|
401
|
+
const decision = result?.answers[question.question];
|
|
402
|
+
if (decision === 'Run now') {
|
|
403
|
+
return manager.approveScheduledPrompt(pending.id);
|
|
404
|
+
}
|
|
405
|
+
if (decision === 'Skip') {
|
|
406
|
+
manager.declineScheduledPrompt(pending.id);
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
return false;
|
|
363
410
|
}
|
|
364
411
|
workflows() {
|
|
365
412
|
return this.workflowManager?.list() ?? [];
|
|
@@ -817,23 +864,31 @@ export class ClaudeSessionService {
|
|
|
817
864
|
return validSessionName(metrics.text);
|
|
818
865
|
}
|
|
819
866
|
async sessions() {
|
|
820
|
-
const
|
|
867
|
+
const discoveredRoot = await discoverClaudeProjectRoot({
|
|
868
|
+
configRoot: this.options.configRoot,
|
|
869
|
+
cwd: this.activeCwd(),
|
|
870
|
+
});
|
|
871
|
+
const projectRoot = discoveredRoot ?? this.paths(randomUUID()).projectRoot;
|
|
821
872
|
let names;
|
|
822
873
|
try {
|
|
823
|
-
names = await readdir(
|
|
874
|
+
names = await readdir(projectRoot);
|
|
824
875
|
}
|
|
825
876
|
catch (error) {
|
|
826
877
|
if (error.code === 'ENOENT')
|
|
827
878
|
return [];
|
|
828
879
|
throw error;
|
|
829
880
|
}
|
|
830
|
-
const
|
|
881
|
+
const sessionIds = names
|
|
831
882
|
.filter((name) => extname(name) === '.jsonl')
|
|
832
|
-
.map(
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
883
|
+
.map((name) => basename(name, '.jsonl'))
|
|
884
|
+
.filter((sessionId) => isClaudeSessionId(sessionId));
|
|
885
|
+
if (discoveredRoot !== undefined) {
|
|
886
|
+
for (const sessionId of sessionIds) {
|
|
887
|
+
this.discoveredProjectRoots.set(sessionId, projectRoot);
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
const summaries = await Promise.all(sessionIds.map(async (sessionId) => {
|
|
891
|
+
const sessionFile = join(projectRoot, `${sessionId}.jsonl`);
|
|
837
892
|
try {
|
|
838
893
|
const metadata = await lstat(sessionFile);
|
|
839
894
|
if (!metadata.isFile())
|
|
@@ -872,6 +927,7 @@ export class ClaudeSessionService {
|
|
|
872
927
|
}
|
|
873
928
|
async inspect(sessionId) {
|
|
874
929
|
this.assertSessionPersistence();
|
|
930
|
+
await this.discoverProjectRoot(sessionId);
|
|
875
931
|
const paths = this.paths(sessionId);
|
|
876
932
|
let metadata;
|
|
877
933
|
try {
|
|
@@ -912,6 +968,7 @@ export class ClaudeSessionService {
|
|
|
912
968
|
}
|
|
913
969
|
async export(sessionId) {
|
|
914
970
|
this.assertSessionPersistence();
|
|
971
|
+
await this.discoverProjectRoot(sessionId);
|
|
915
972
|
try {
|
|
916
973
|
return await this.store(sessionId).exportReadOnly();
|
|
917
974
|
}
|
|
@@ -923,6 +980,7 @@ export class ClaudeSessionService {
|
|
|
923
980
|
}
|
|
924
981
|
}
|
|
925
982
|
async transcript(sessionId, resumeSessionAt) {
|
|
983
|
+
await this.discoverProjectRoot(sessionId);
|
|
926
984
|
try {
|
|
927
985
|
const recovery = await this.store(sessionId).loadReadOnly();
|
|
928
986
|
if (recovery.entries.length === 0) {
|
|
@@ -1048,6 +1106,9 @@ export class ClaudeSessionService {
|
|
|
1048
1106
|
if (relocated.status === 'conflict') {
|
|
1049
1107
|
throw new Error(`Claude transcript relocation conflict: ${relocated.reason}`);
|
|
1050
1108
|
}
|
|
1109
|
+
// The transcript moved to the exact root for the new cwd; any
|
|
1110
|
+
// previously discovered alternate-hash root is now stale.
|
|
1111
|
+
this.discoveredProjectRoots.delete(sessionId);
|
|
1051
1112
|
}
|
|
1052
1113
|
else {
|
|
1053
1114
|
await this.appendCdCommand(sessionId, cwd);
|
|
@@ -1664,6 +1725,9 @@ export class ClaudeSessionService {
|
|
|
1664
1725
|
this.options.workspace?.setCwd(pinnedCwd);
|
|
1665
1726
|
}
|
|
1666
1727
|
this.runtimeCwd = pinnedCwd;
|
|
1728
|
+
if (requireExisting) {
|
|
1729
|
+
await this.discoverProjectRoot(sessionId);
|
|
1730
|
+
}
|
|
1667
1731
|
const sessionPaths = this.paths(sessionId);
|
|
1668
1732
|
const toolResultDirectory = join(sessionPaths.projectRoot, sessionId, 'tool-results');
|
|
1669
1733
|
const store = this.turnStore(sessionId);
|
|
@@ -3091,11 +3155,31 @@ export class ClaudeSessionService {
|
|
|
3091
3155
|
this.worktreeManager.restore(state);
|
|
3092
3156
|
}
|
|
3093
3157
|
paths(sessionId) {
|
|
3094
|
-
|
|
3158
|
+
const exact = resolveClaudePaths({
|
|
3095
3159
|
configDir: this.options.configRoot,
|
|
3096
3160
|
cwd: this.sessionCwds.get(sessionId) ?? this.activeCwd(),
|
|
3097
3161
|
sessionId,
|
|
3098
3162
|
});
|
|
3163
|
+
const discovered = this.discoveredProjectRoots.get(sessionId);
|
|
3164
|
+
if (discovered === undefined)
|
|
3165
|
+
return exact;
|
|
3166
|
+
return {
|
|
3167
|
+
...exact,
|
|
3168
|
+
projectRoot: discovered,
|
|
3169
|
+
sessionFile: resolve(discovered, `${sessionId}.jsonl`),
|
|
3170
|
+
};
|
|
3171
|
+
}
|
|
3172
|
+
async discoverProjectRoot(sessionId) {
|
|
3173
|
+
if (this.discoveredProjectRoots.has(sessionId))
|
|
3174
|
+
return;
|
|
3175
|
+
const discovered = await discoverClaudeProjectRoot({
|
|
3176
|
+
configRoot: this.options.configRoot,
|
|
3177
|
+
cwd: this.sessionCwds.get(sessionId) ?? this.activeCwd(),
|
|
3178
|
+
sessionId,
|
|
3179
|
+
});
|
|
3180
|
+
if (discovered !== undefined) {
|
|
3181
|
+
this.discoveredProjectRoots.set(sessionId, discovered);
|
|
3182
|
+
}
|
|
3099
3183
|
}
|
|
3100
3184
|
async appendCdCommand(sessionId, cwd) {
|
|
3101
3185
|
const result = await this.store(sessionId).withLease(async (lease) => {
|
|
@@ -12,6 +12,21 @@ export interface ClaudePaths {
|
|
|
12
12
|
praxisRoot: string;
|
|
13
13
|
}
|
|
14
14
|
export declare function sanitizeClaudeProjectPath(path: string): string;
|
|
15
|
+
export interface DiscoverClaudeProjectRootOptions {
|
|
16
|
+
configRoot: string;
|
|
17
|
+
cwd: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Locates the Claude project directory for a cwd, preferring the exact
|
|
22
|
+
* sanitized hash path and falling back to a long-path truncated-prefix
|
|
23
|
+
* candidate when Claude used a different runtime hash. When a sessionId is
|
|
24
|
+
* supplied, the exact directory only matches if it contains the requested
|
|
25
|
+
* regular session file; an existing exact directory without that file still
|
|
26
|
+
* falls through to the long-path prefix scan. Candidate selection is
|
|
27
|
+
* directory-prefix based and never uses mtime; ambiguous prefixes are rejected.
|
|
28
|
+
*/
|
|
29
|
+
export declare function discoverClaudeProjectRoot({ configRoot, cwd, sessionId, }: DiscoverClaudeProjectRootOptions): Promise<string | undefined>;
|
|
15
30
|
export declare function resolveClaudeScheduledTaskFile(cwd: string): string;
|
|
16
31
|
export declare function resolveClaudePaths({ cwd, sessionId, configDir, }: ResolveClaudePathsOptions): ClaudePaths;
|
|
17
32
|
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { lstat, readdir } from 'node:fs/promises';
|
|
1
2
|
import { homedir } from 'node:os';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
3
|
+
import { extname, resolve } from 'node:path';
|
|
3
4
|
import { getDataOwnership } from './ownership.js';
|
|
4
5
|
const MAX_SANITIZED_LENGTH = 200;
|
|
5
6
|
const SESSION_ID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -21,6 +22,105 @@ export function sanitizeClaudeProjectPath(path) {
|
|
|
21
22
|
}
|
|
22
23
|
return `${sanitized.slice(0, MAX_SANITIZED_LENGTH)}-${stablePathHash(path).toString(36)}`;
|
|
23
24
|
}
|
|
25
|
+
async function isDirectory(path) {
|
|
26
|
+
try {
|
|
27
|
+
return (await lstat(path)).isDirectory();
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error.code === 'ENOENT')
|
|
31
|
+
return false;
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function isRegularFile(path) {
|
|
36
|
+
try {
|
|
37
|
+
return (await lstat(path)).isFile();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (error.code === 'ENOENT')
|
|
41
|
+
return false;
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function hasClaudeSessionTranscript(directory) {
|
|
46
|
+
let names;
|
|
47
|
+
try {
|
|
48
|
+
names = await readdir(directory);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error.code === 'ENOENT')
|
|
52
|
+
return false;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
for (const name of names) {
|
|
56
|
+
if (extname(name) !== '.jsonl')
|
|
57
|
+
continue;
|
|
58
|
+
if (!isClaudeSessionId(name.slice(0, -'.jsonl'.length)))
|
|
59
|
+
continue;
|
|
60
|
+
if (await isRegularFile(resolve(directory, name)))
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Locates the Claude project directory for a cwd, preferring the exact
|
|
67
|
+
* sanitized hash path and falling back to a long-path truncated-prefix
|
|
68
|
+
* candidate when Claude used a different runtime hash. When a sessionId is
|
|
69
|
+
* supplied, the exact directory only matches if it contains the requested
|
|
70
|
+
* regular session file; an existing exact directory without that file still
|
|
71
|
+
* falls through to the long-path prefix scan. Candidate selection is
|
|
72
|
+
* directory-prefix based and never uses mtime; ambiguous prefixes are rejected.
|
|
73
|
+
*/
|
|
74
|
+
export async function discoverClaudeProjectRoot({ configRoot, cwd, sessionId, }) {
|
|
75
|
+
if (sessionId !== undefined && !isClaudeSessionId(sessionId)) {
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
const sanitized = sanitizeClaudeProjectPath(cwd);
|
|
79
|
+
const exactProjectRoot = resolve(configRoot, 'projects', sanitized);
|
|
80
|
+
if (sessionId !== undefined) {
|
|
81
|
+
// A sessionId targets a concrete transcript; an existing exact directory
|
|
82
|
+
// only matches when it actually holds the requested session file. Praxis
|
|
83
|
+
// may have created an empty exact directory before the transcript landed
|
|
84
|
+
// in an alternate long-path prefix directory, so fall through to the
|
|
85
|
+
// prefix scan instead of returning the empty exact directory.
|
|
86
|
+
if (await isRegularFile(resolve(exactProjectRoot, `${sessionId}.jsonl`))) {
|
|
87
|
+
return exactProjectRoot;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (await isDirectory(exactProjectRoot)) {
|
|
91
|
+
return exactProjectRoot;
|
|
92
|
+
}
|
|
93
|
+
if (sanitized.length <= MAX_SANITIZED_LENGTH)
|
|
94
|
+
return undefined;
|
|
95
|
+
const prefix = sanitized.slice(0, MAX_SANITIZED_LENGTH);
|
|
96
|
+
let names;
|
|
97
|
+
try {
|
|
98
|
+
names = await readdir(resolve(configRoot, 'projects'));
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if (error.code === 'ENOENT')
|
|
102
|
+
return undefined;
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
const candidates = [];
|
|
106
|
+
for (const name of names) {
|
|
107
|
+
if (!name.startsWith(`${prefix}-`))
|
|
108
|
+
continue;
|
|
109
|
+
const candidate = resolve(configRoot, 'projects', name);
|
|
110
|
+
if (!(await isDirectory(candidate)))
|
|
111
|
+
continue;
|
|
112
|
+
if (sessionId !== undefined) {
|
|
113
|
+
if (await isRegularFile(resolve(candidate, `${sessionId}.jsonl`))) {
|
|
114
|
+
candidates.push(candidate);
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (await hasClaudeSessionTranscript(candidate)) {
|
|
119
|
+
candidates.push(candidate);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
123
|
+
}
|
|
24
124
|
export function resolveClaudeScheduledTaskFile(cwd) {
|
|
25
125
|
const policy = getDataOwnership('scheduled-prompts');
|
|
26
126
|
if (policy.plane !== 'shared' ||
|