@ai-devkit/agent-manager 0.45.0 → 0.45.1
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/durable/DurableAgent.d.ts +1 -0
- package/dist/durable/DurableAgent.d.ts.map +1 -1
- package/dist/durable/DurableAgent.js.map +1 -1
- package/dist/harnesses/pi/PiSessionLocator.d.ts +3 -2
- package/dist/harnesses/pi/PiSessionLocator.d.ts.map +1 -1
- package/dist/harnesses/pi/PiSessionLocator.js +15 -6
- package/dist/harnesses/pi/PiSessionLocator.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DurableAgent.d.ts","sourceRoot":"","sources":["../../src/durable/DurableAgent.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,UAAU,CAAC;AACjE,MAAM,MAAM,oBAAoB,GAAG,eAAe,GAAG,SAAS,GAAG,SAAS,GAAG,UAAU,CAAC;AACxF,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,QAAQ,GAAG,aAAa,CAAC;AACtE,MAAM,MAAM,gBAAgB,GACxB,oBAAoB,GACpB,oBAAoB,GACpB,YAAY,GACZ,aAAa,GACb,mBAAmB,GACnB,qBAAqB,GACrB,gBAAgB,CAAC;AAErB,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,gBAAgB,CAAC;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ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,GAAG,iBAAiB,GAAG,cAAc,CAAC;AAEnF,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,IAAI,EAAE,MAAM;gBAD5B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM;CAK/B;AAED,qBAAa,qBAAsB,SAAQ,iBAAiB;aAExC,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM,EAC/B,SAAS,EAAE,MAAM;CAKpB;AAED,qBAAa,yBAA0B,SAAQ,iBAAiB;aAClC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAI9C;AAED,qBAAa,2BAA4B,SAAQ,iBAAiB;gBACpD,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,6BAA8B,SAAQ,iBAAiB;aACtC,SAAS,EAAE,MAAM;gBAAjB,SAAS,EAAE,MAAM;CAI9C;AAED,qBAAa,gBAAiB,SAAQ,iBAAiB;gBACzC,OAAO,EAAE,MAAM,EAAE,IAAI,SAAwB;CAI1D;AAED,MAAM,MAAM,mBAAmB,GAC3B,gBAAgB,GAChB,eAAe,GACf,wBAAwB,GACxB,mBAAmB,GACnB,sBAAsB,GACtB,uBAAuB,GACvB,uBAAuB,CAAC;AAE5B,qBAAa,eAAgB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB;CAIvD;AAED,qBAAa,YAAa,SAAQ,iBAAiB;gBACrC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,gBAA+B;CAInE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/durable/DurableAgent.ts"],"sourcesContent":["export type DurableAgentState = \"ready\" | \"running\" | \"degraded\";\nexport type DurableSessionHealth = \"uninitialized\" | \"healthy\" | \"unknown\" | \"mismatch\";\nexport type DurableRunStatus = \"succeeded\" | \"failed\" | \"interrupted\";\nexport type PiPrintErrorCode =\n | \"PI_CLI_UNAVAILABLE\"\n | \"PI_CLI_UNSUPPORTED\"\n | \"PI_PROCESS\"\n | \"PI_PROTOCOL\"\n | \"PI_RESULT_MISSING\"\n | \"PI_SESSION_MISMATCH\"\n | \"PI_UNSUPPORTED\";\n\nexport const AGENT_MODES = {\n INTERACTIVE: \"interactive\",\n DURABLE: \"durable\",\n} as const;\n\nexport interface ProcessIdentity {\n pid: number;\n startedAt: string;\n}\n\nexport interface DurableActiveRun {\n token: string;\n owner: ProcessIdentity;\n provider: ProcessIdentity | null;\n startedAt: string;\n}\n\nexport interface DurableLastResult {\n status: DurableRunStatus;\n completedAt: string;\n exitCode: number | null;\n summary: string;\n}\n\nexport type DurableProvider = \"claude\" | \"codex\" | \"pi\";\n\nexport interface DurableAgentBase {\n id: string;\n name: string;\n mode: typeof AGENT_MODES.DURABLE;\n cwd: string;\n state: DurableAgentState;\n sessionHealth: DurableSessionHealth;\n createdAt: string;\n updatedAt: string;\n lastActiveAt: string | null;\n lastResult: DurableLastResult | null;\n activeRun: DurableActiveRun | null;\n}\n\nexport interface ClaudeDurableAgent extends DurableAgentBase {\n provider: \"claude\";\n providerSessionId: string;\n}\n\nexport interface CodexDurableAgent extends DurableAgentBase {\n provider: \"codex\";\n providerSessionId: string | null;\n}\n\nexport interface PiDurableAgent extends DurableAgentBase {\n provider: \"pi\";\n providerSessionId: string;\n}\n\nexport type DurableAgent = ClaudeDurableAgent | CodexDurableAgent | PiDurableAgent;\n\nexport class DurableAgentError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n ) {\n super(message);\n this.name = \"DurableAgentError\";\n }\n}\n\nexport class DurableAgentBusyError extends DurableAgentError {\n constructor(\n public readonly agentId: string,\n agentName: string,\n ) {\n super(`Durable agent \"${agentName}\" is busy.`, \"DURABLE_AGENT_BUSY\");\n this.name = \"DurableAgentBusyError\";\n }\n}\n\nexport class DurableAgentNotFoundError extends DurableAgentError {\n constructor(public readonly reference: string) {\n super(`Durable agent \"${reference}\" was not found.`, \"DURABLE_AGENT_NOT_FOUND\");\n this.name = \"DurableAgentNotFoundError\";\n }\n}\n\nexport class DurableAgentRepositoryError extends DurableAgentError {\n constructor(message: string) {\n super(message, \"DURABLE_AGENT_REPOSITORY\");\n this.name = \"DurableAgentRepositoryError\";\n }\n}\n\nexport class DurableAgentNameConflictError extends DurableAgentError {\n constructor(public readonly agentName: string) {\n super(`Durable agent name \"${agentName}\" is already in use.`, \"DURABLE_AGENT_NAME_CONFLICT\");\n this.name = \"DurableAgentNameConflictError\";\n }\n}\n\nexport class ClaudePrintError extends DurableAgentError {\n constructor(message: string, code = \"CLAUDE_PRINT_FAILED\") {\n super(message, code);\n this.name = \"ClaudePrintError\";\n }\n}\n\nexport type CodexPrintErrorCode =\n | \"CODEX_PROTOCOL\"\n | \"CODEX_PROCESS\"\n | \"CODEX_SESSION_MISMATCH\"\n | \"CODEX_UNSUPPORTED\"\n | \"CODEX_RESULT_MISSING\"\n | \"CODEX_CLI_UNSUPPORTED\"\n | \"CODEX_CLI_UNAVAILABLE\";\n\nexport class CodexPrintError extends DurableAgentError {\n constructor(message: string, code: CodexPrintErrorCode) {\n super(message, code);\n this.name = \"CodexPrintError\";\n }\n}\n\nexport class PiPrintError extends DurableAgentError {\n constructor(message: string, code: PiPrintErrorCode = \"PI_PROCESS\") {\n super(message, code);\n this.name = \"PiPrintError\";\n }\n}\n"],"names":["AGENT_MODES","INTERACTIVE","DURABLE","DurableAgentError","Error","message","code","name","DurableAgentBusyError","agentId","agentName","DurableAgentNotFoundError","reference","DurableAgentRepositoryError","DurableAgentNameConflictError","ClaudePrintError","CodexPrintError","PiPrintError"],"mappings":"AAYA,OAAO,MAAMA,cAAc;IACzBC,aAAa;IACbC,SAAS;AACX,EAAW;
|
|
1
|
+
{"version":3,"sources":["../../src/durable/DurableAgent.ts"],"sourcesContent":["export type DurableAgentState = \"ready\" | \"running\" | \"degraded\";\nexport type DurableSessionHealth = \"uninitialized\" | \"healthy\" | \"unknown\" | \"mismatch\";\nexport type DurableRunStatus = \"succeeded\" | \"failed\" | \"interrupted\";\nexport type PiPrintErrorCode =\n | \"PI_CLI_UNAVAILABLE\"\n | \"PI_CLI_UNSUPPORTED\"\n | \"PI_PROCESS\"\n | \"PI_PROTOCOL\"\n | \"PI_RESULT_MISSING\"\n | \"PI_SESSION_MISMATCH\"\n | \"PI_UNSUPPORTED\";\n\nexport const AGENT_MODES = {\n INTERACTIVE: \"interactive\",\n DURABLE: \"durable\",\n} as const;\n\nexport interface ProcessIdentity {\n pid: number;\n startedAt: string;\n}\n\nexport interface DurableActiveRun {\n token: string;\n owner: ProcessIdentity;\n provider: ProcessIdentity | null;\n startedAt: string;\n}\n\nexport interface DurableLastResult {\n status: DurableRunStatus;\n completedAt: string;\n exitCode: number | null;\n summary: string;\n}\n\nexport type DurableProvider = \"claude\" | \"codex\" | \"pi\";\n\nexport interface DurableAgentBase {\n id: string;\n name: string;\n mode: typeof AGENT_MODES.DURABLE;\n cwd: string;\n sessionFilePath?: string | null;\n state: DurableAgentState;\n sessionHealth: DurableSessionHealth;\n createdAt: string;\n updatedAt: string;\n lastActiveAt: string | null;\n lastResult: DurableLastResult | null;\n activeRun: DurableActiveRun | null;\n}\n\nexport interface ClaudeDurableAgent extends DurableAgentBase {\n provider: \"claude\";\n providerSessionId: string;\n}\n\nexport interface CodexDurableAgent extends DurableAgentBase {\n provider: \"codex\";\n providerSessionId: string | null;\n}\n\nexport interface PiDurableAgent extends DurableAgentBase {\n provider: \"pi\";\n providerSessionId: string;\n}\n\nexport type DurableAgent = ClaudeDurableAgent | CodexDurableAgent | PiDurableAgent;\n\nexport class DurableAgentError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n ) {\n super(message);\n this.name = \"DurableAgentError\";\n }\n}\n\nexport class DurableAgentBusyError extends DurableAgentError {\n constructor(\n public readonly agentId: string,\n agentName: string,\n ) {\n super(`Durable agent \"${agentName}\" is busy.`, \"DURABLE_AGENT_BUSY\");\n this.name = \"DurableAgentBusyError\";\n }\n}\n\nexport class DurableAgentNotFoundError extends DurableAgentError {\n constructor(public readonly reference: string) {\n super(`Durable agent \"${reference}\" was not found.`, \"DURABLE_AGENT_NOT_FOUND\");\n this.name = \"DurableAgentNotFoundError\";\n }\n}\n\nexport class DurableAgentRepositoryError extends DurableAgentError {\n constructor(message: string) {\n super(message, \"DURABLE_AGENT_REPOSITORY\");\n this.name = \"DurableAgentRepositoryError\";\n }\n}\n\nexport class DurableAgentNameConflictError extends DurableAgentError {\n constructor(public readonly agentName: string) {\n super(`Durable agent name \"${agentName}\" is already in use.`, \"DURABLE_AGENT_NAME_CONFLICT\");\n this.name = \"DurableAgentNameConflictError\";\n }\n}\n\nexport class ClaudePrintError extends DurableAgentError {\n constructor(message: string, code = \"CLAUDE_PRINT_FAILED\") {\n super(message, code);\n this.name = \"ClaudePrintError\";\n }\n}\n\nexport type CodexPrintErrorCode =\n | \"CODEX_PROTOCOL\"\n | \"CODEX_PROCESS\"\n | \"CODEX_SESSION_MISMATCH\"\n | \"CODEX_UNSUPPORTED\"\n | \"CODEX_RESULT_MISSING\"\n | \"CODEX_CLI_UNSUPPORTED\"\n | \"CODEX_CLI_UNAVAILABLE\";\n\nexport class CodexPrintError extends DurableAgentError {\n constructor(message: string, code: CodexPrintErrorCode) {\n super(message, code);\n this.name = \"CodexPrintError\";\n }\n}\n\nexport class PiPrintError extends DurableAgentError {\n constructor(message: string, code: PiPrintErrorCode = \"PI_PROCESS\") {\n super(message, code);\n this.name = \"PiPrintError\";\n }\n}\n"],"names":["AGENT_MODES","INTERACTIVE","DURABLE","DurableAgentError","Error","message","code","name","DurableAgentBusyError","agentId","agentName","DurableAgentNotFoundError","reference","DurableAgentRepositoryError","DurableAgentNameConflictError","ClaudePrintError","CodexPrintError","PiPrintError"],"mappings":"AAYA,OAAO,MAAMA,cAAc;IACzBC,aAAa;IACbC,SAAS;AACX,EAAW;AAuDX,OAAO,MAAMC,0BAA0BC;;IACrC,YACEC,OAAe,EACf,AAAgBC,IAAY,CAC5B;QACA,KAAK,CAACD,eAFUC,OAAAA;QAGhB,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMC,8BAA8BL;;IACzC,YACE,AAAgBM,OAAe,EAC/BC,SAAiB,CACjB;QACA,KAAK,CAAC,CAAC,eAAe,EAAEA,UAAU,UAAU,CAAC,EAAE,4BAH/BD,UAAAA;QAIhB,IAAI,CAACF,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMI,kCAAkCR;;IAC7C,YAAY,AAAgBS,SAAiB,CAAE;QAC7C,KAAK,CAAC,CAAC,eAAe,EAAEA,UAAU,gBAAgB,CAAC,EAAE,iCAD3BA,YAAAA;QAE1B,IAAI,CAACL,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMM,oCAAoCV;IAC/C,YAAYE,OAAe,CAAE;QAC3B,KAAK,CAACA,SAAS;QACf,IAAI,CAACE,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMO,sCAAsCX;;IACjD,YAAY,AAAgBO,SAAiB,CAAE;QAC7C,KAAK,CAAC,CAAC,oBAAoB,EAAEA,UAAU,oBAAoB,CAAC,EAAE,qCADpCA,YAAAA;QAE1B,IAAI,CAACH,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMQ,yBAAyBZ;IACpC,YAAYE,OAAe,EAAEC,OAAO,qBAAqB,CAAE;QACzD,KAAK,CAACD,SAASC;QACf,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAWA,OAAO,MAAMS,wBAAwBb;IACnC,YAAYE,OAAe,EAAEC,IAAyB,CAAE;QACtD,KAAK,CAACD,SAASC;QACf,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA,OAAO,MAAMU,qBAAqBd;IAChC,YAAYE,OAAe,EAAEC,OAAyB,YAAY,CAAE;QAClE,KAAK,CAACD,SAASC;QACf,IAAI,CAACC,IAAI,GAAG;IACd;AACF"}
|
|
@@ -20,8 +20,9 @@ export interface PiProcessSessionMatches {
|
|
|
20
20
|
* and only their head (<= 64 KiB) is read for session id and cwd;
|
|
21
21
|
* - heads are cached per file (dev/ino/size) across calls on one instance;
|
|
22
22
|
* - a project dir whose scan matched none of its processes is skipped until
|
|
23
|
-
* its mtime changes
|
|
24
|
-
*
|
|
23
|
+
* its mtime changes, its jsonl count changes (when mtime is in the current
|
|
24
|
+
* second — directory mtimes are often second-granular), or a process it has
|
|
25
|
+
* not seen needs it.
|
|
25
26
|
*
|
|
26
27
|
* Reuse one instance across refreshes to benefit from the caches.
|
|
27
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PiSessionLocator.d.ts","sourceRoot":"","sources":["../../../src/harnesses/pi/PiSessionLocator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"PiSessionLocator.d.ts","sourceRoot":"","sources":["../../../src/harnesses/pi/PiSessionLocator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAA4B,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAErF,OAAO,EAML,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAG9B,MAAM,WAAW,uBAAuB;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,WAAW,EAAE,CAAC;IAC7B,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB;AA4BD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAgB;IAQzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPzB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IACvD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmC;IAC/D,OAAO,CAAC,UAAU,CAAK;gBAGrB,OAAO,GAAE,uBAA4B,EACpB,MAAM,GAAE,eAAuC;IAKlE,qBAAqB,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,uBAAuB;IAoBxE;;;;OAIG;IACH,oBAAoB,CAAC,SAAS,GAAE,WAAW,EAAO,GAAG,WAAW,EAAE;IAIlE,8BAA8B,IAAI,MAAM,EAAE;IAI1C,8BAA8B,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAS3D;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAiDzB,OAAO,CAAC,sBAAsB;IAmC9B,sFAAsF;IACtF,OAAO,CAAC,QAAQ;IA2BhB,2FAA2F;IAC3F,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,iBAAiB;IAQzB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,gBAAgB;CAIzB"}
|
|
@@ -16,8 +16,9 @@ import { homeDir } from "../shared.js";
|
|
|
16
16
|
* and only their head (<= 64 KiB) is read for session id and cwd;
|
|
17
17
|
* - heads are cached per file (dev/ino/size) across calls on one instance;
|
|
18
18
|
* - a project dir whose scan matched none of its processes is skipped until
|
|
19
|
-
* its mtime changes
|
|
20
|
-
*
|
|
19
|
+
* its mtime changes, its jsonl count changes (when mtime is in the current
|
|
20
|
+
* second — directory mtimes are often second-granular), or a process it has
|
|
21
|
+
* not seen needs it.
|
|
21
22
|
*
|
|
22
23
|
* Reuse one instance across refreshes to benefit from the caches.
|
|
23
24
|
*/ export class PiSessionLocator {
|
|
@@ -107,11 +108,16 @@ import { homeDir } from "../shared.js";
|
|
|
107
108
|
// An unmatched process never held a session, so dropping one cannot free
|
|
108
109
|
// a session for another; only a dir change or an unseen process can.
|
|
109
110
|
const unchanged = noMatch !== undefined && noMatch.dirMtimeMs === scan.dirMtimeMs && scan.processes.every((proc)=>noMatch.processKeys.has(processKey(proc)));
|
|
110
|
-
if (unchanged) {
|
|
111
|
-
scans.delete(projectDir);
|
|
112
|
-
} else {
|
|
111
|
+
if (!unchanged) {
|
|
113
112
|
this.noMatchDirs.delete(projectDir);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const ambiguousMtimeSecond = Math.floor(scan.dirMtimeMs / 1000) === Math.floor(Date.now() / 1000);
|
|
116
|
+
if (ambiguousMtimeSecond && listJsonl(projectDir).length !== noMatch.jsonlCount) {
|
|
117
|
+
this.noMatchDirs.delete(projectDir);
|
|
118
|
+
continue;
|
|
114
119
|
}
|
|
120
|
+
scans.delete(projectDir);
|
|
115
121
|
}
|
|
116
122
|
return scans;
|
|
117
123
|
}
|
|
@@ -120,7 +126,9 @@ import { homeDir } from "../shared.js";
|
|
|
120
126
|
for (const [projectDir, scan] of scans){
|
|
121
127
|
const cwd = scan.processes[0]?.cwd ?? "";
|
|
122
128
|
const startTimes = scan.processes.map((proc)=>proc.startTime?.getTime() ?? 0);
|
|
123
|
-
|
|
129
|
+
const fileNames = listJsonl(projectDir);
|
|
130
|
+
scan.jsonlCount = fileNames.length;
|
|
131
|
+
for (const fileName of fileNames){
|
|
124
132
|
const filePath = path.join(projectDir, fileName);
|
|
125
133
|
const stat = safeStat(filePath);
|
|
126
134
|
if (!stat?.isFile()) continue;
|
|
@@ -170,6 +178,7 @@ import { homeDir } from "../shared.js";
|
|
|
170
178
|
if (scan.processes.some((proc)=>matchedPids.has(proc.pid))) continue;
|
|
171
179
|
this.noMatchDirs.set(projectDir, {
|
|
172
180
|
dirMtimeMs: scan.dirMtimeMs,
|
|
181
|
+
jsonlCount: scan.jsonlCount ?? listJsonl(projectDir).length,
|
|
173
182
|
processKeys: new Set(scan.processes.map(processKey))
|
|
174
183
|
});
|
|
175
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/harnesses/pi/PiSessionLocator.ts"],"sourcesContent":["import type * as fs from \"fs\";\nimport * as path from \"path\";\nimport type { ProcessInfo } from \"../../adapters/AgentAdapter.js\";\nimport { matchProcessesToSessions, type MatchResult } from \"../../utils/matching.js\";\nimport { MATCH_TOLERANCE_MS } from \"../../utils/matchingConstants.js\";\nimport {\n isDirectory,\n isSafePathSegment,\n listJsonl,\n safeReaddir,\n safeStat,\n type SessionFile,\n} from \"../../utils/session.js\";\nimport {\n PI_SESSION_HEAD_MAX_BYTES,\n PiSessionParser,\n type PiSessionHead,\n} from \"./PiSessionParser.js\";\nimport { homeDir } from \"../shared.js\";\n\nexport interface PiSessionLocatorOptions {\n sessionsDir?: string;\n}\n\nexport interface PiProcessSessionMatches {\n legacyMatches: MatchResult[];\n fallback: ProcessInfo[];\n}\n\n/** Pi session file names start with their creation time: `2026-06-10T08-58-20-754Z_<id>.jsonl`. */\nconst FILE_NAME_TIMESTAMP = /^(\\d{4}-\\d{2}-\\d{2})T(\\d{2})-(\\d{2})-(\\d{2})-(\\d{3})Z_/;\n\ninterface ProjectDirScan {\n dirMtimeMs: number;\n processes: ProcessInfo[];\n}\n\ninterface CachedHead {\n dev: number;\n ino: number;\n size: number;\n head: PiSessionHead;\n seen: number;\n}\n\n/** A project dir whose last scan matched none of the processes that scanned it. */\ninterface NoMatchEntry {\n dirMtimeMs: number;\n processKeys: Set<string>;\n}\n\n/**\n * Finds Pi session files for running processes that the registry and the\n * sessions.json tracker could not resolve.\n *\n * Live discovery is scoped so its cost follows live agents, not Pi history:\n * - only the project dir Pi derives from each process cwd is listed;\n * - only files created within MATCH_TOLERANCE_MS (the matcher's tolerance) of a\n * process start are opened,\n * and only their head (<= 64 KiB) is read for session id and cwd;\n * - heads are cached per file (dev/ino/size) across calls on one instance;\n * - a project dir whose scan matched none of its processes is skipped until\n * its mtime changes (a session file was added or removed) or a process it\n * has not seen needs it.\n *\n * Reuse one instance across refreshes to benefit from the caches.\n */\nexport class PiSessionLocator {\n private readonly sessionsDir: string;\n private readonly heads = new Map<string, CachedHead>();\n private readonly noMatchDirs = new Map<string, NoMatchEntry>();\n private generation = 0;\n\n constructor(\n options: PiSessionLocatorOptions = {},\n private readonly parser: PiSessionParser = new PiSessionParser(),\n ) {\n this.sessionsDir = options.sessionsDir ?? path.join(homeDir(), \".pi\", \"agent\", \"sessions\");\n }\n\n matchRunningProcesses(processes: ProcessInfo[]): PiProcessSessionMatches {\n this.generation++;\n try {\n if (processes.length === 0) return { legacyMatches: [], fallback: [] };\n\n const scans = this.groupByProjectDir(processes, true);\n const sessions = this.discoverSessionsInDirs(scans);\n if (sessions.length === 0) {\n this.rememberUnmatchedDirs(scans, []);\n return { legacyMatches: [], fallback: processes };\n }\n\n const legacyMatches = matchProcessesToSessions(processes, sessions);\n this.rememberUnmatchedDirs(scans, legacyMatches);\n return { legacyMatches, fallback: processes };\n } finally {\n this.pruneHeads();\n }\n }\n\n /**\n * Session files that could match `processes`: files in each process's\n * project dir created within the start-time window, with session id and\n * cwd taken from a bounded head read.\n */\n discoverLiveSessions(processes: ProcessInfo[] = []): SessionFile[] {\n return this.discoverSessionsInDirs(this.groupByProjectDir(processes, false));\n }\n\n discoverHistoricalSessionFiles(): string[] {\n return this.collectJsonlFiles(this.sessionsDir);\n }\n\n findHistoricalSessionFilesById(sessionId: string): string[] {\n if (!isSafePathSegment(sessionId)) return [];\n\n return this.collectJsonlFiles(this.sessionsDir).filter((filePath) => {\n const basename = path.basename(filePath, \".jsonl\");\n return basename === sessionId || basename.endsWith(`_${sessionId}`);\n });\n }\n\n /**\n * Group matchable processes (cwd and start time set) by the project dir Pi\n * stores their sessions in. With `skipUnchanged`, dirs whose previous scan\n * matched nothing and that have not changed since are left out.\n */\n private groupByProjectDir(\n processes: ProcessInfo[],\n skipUnchanged: boolean,\n ): Map<string, ProjectDirScan> {\n const scans = new Map<string, ProjectDirScan>();\n if (!isDirectory(this.sessionsDir)) return scans;\n\n for (const proc of processes) {\n if (!proc.cwd || !proc.startTime) continue;\n const projectDir = path.join(this.sessionsDir, this.encodeProjectDir(proc.cwd));\n const scan = scans.get(projectDir);\n if (scan) {\n scan.processes.push(proc);\n continue;\n }\n const stat = safeStat(projectDir);\n if (stat?.isDirectory()) {\n scans.set(projectDir, { dirMtimeMs: stat.mtimeMs, processes: [proc] });\n }\n }\n\n if (!skipUnchanged) return scans;\n\n for (const projectDir of this.noMatchDirs.keys()) {\n if (!scans.has(projectDir)) this.noMatchDirs.delete(projectDir);\n }\n for (const [projectDir, scan] of scans) {\n const noMatch = this.noMatchDirs.get(projectDir);\n // An unmatched process never held a session, so dropping one cannot free\n // a session for another; only a dir change or an unseen process can.\n const unchanged =\n noMatch !== undefined &&\n noMatch.dirMtimeMs === scan.dirMtimeMs &&\n scan.processes.every((proc) => noMatch.processKeys.has(processKey(proc)));\n if (unchanged) {\n scans.delete(projectDir);\n } else {\n this.noMatchDirs.delete(projectDir);\n }\n }\n return scans;\n }\n\n private discoverSessionsInDirs(scans: Map<string, ProjectDirScan>): SessionFile[] {\n const sessions: SessionFile[] = [];\n for (const [projectDir, scan] of scans) {\n const cwd = scan.processes[0]?.cwd ?? \"\";\n const startTimes = scan.processes.map((proc) => proc.startTime?.getTime() ?? 0);\n\n for (const fileName of listJsonl(projectDir)) {\n const filePath = path.join(projectDir, fileName);\n const stat = safeStat(filePath);\n if (!stat?.isFile()) continue;\n\n const birthtimeMs = stat.birthtimeMs || stat.mtimeMs;\n const createdMs = this.fileNameTimestamp(fileName);\n const inWindow = startTimes.some(\n (startMs) =>\n Math.abs(startMs - birthtimeMs) <= MATCH_TOLERANCE_MS ||\n (createdMs !== undefined && Math.abs(startMs - createdMs) <= MATCH_TOLERANCE_MS),\n );\n if (!inWindow) continue;\n\n const head = this.readHead(filePath, stat);\n sessions.push({\n sessionId: head?.sessionId || this.parser.sessionIdFromFile(filePath),\n filePath,\n projectDir,\n birthtimeMs,\n resolvedCwd: head?.projectPath || cwd,\n });\n }\n }\n return sessions;\n }\n\n /** Head metadata for `filePath`, re-read only when appended bytes could change it. */\n private readHead(filePath: string, stat: fs.Stats): PiSessionHead | null {\n const cached = this.heads.get(filePath);\n const reusable =\n cached !== undefined &&\n cached.dev === stat.dev &&\n cached.ino === stat.ino &&\n (cached.size === stat.size || (stat.size > cached.size && this.isHeadSettled(cached.head)));\n if (reusable) {\n cached.seen = this.generation;\n return cached.head;\n }\n\n const head = this.parser.readSessionHead(filePath);\n if (head) {\n this.heads.set(filePath, {\n dev: stat.dev,\n ino: stat.ino,\n size: stat.size,\n head,\n seen: this.generation,\n });\n } else {\n this.heads.delete(filePath);\n }\n return head;\n }\n\n /** Appending to a file cannot change a head that found both fields or hit the byte cap. */\n private isHeadSettled(head: PiSessionHead): boolean {\n return (\n (Boolean(head.sessionId) && Boolean(head.projectPath)) ||\n head.bytesRead >= PI_SESSION_HEAD_MAX_BYTES\n );\n }\n\n private rememberUnmatchedDirs(scans: Map<string, ProjectDirScan>, matches: MatchResult[]): void {\n const matchedPids = new Set(matches.map((match) => match.process.pid));\n for (const [projectDir, scan] of scans) {\n if (scan.processes.some((proc) => matchedPids.has(proc.pid))) continue;\n this.noMatchDirs.set(projectDir, {\n dirMtimeMs: scan.dirMtimeMs,\n processKeys: new Set(scan.processes.map(processKey)),\n });\n }\n }\n\n private pruneHeads(): void {\n for (const [filePath, entry] of this.heads) {\n if (entry.seen !== this.generation) this.heads.delete(filePath);\n }\n }\n\n private fileNameTimestamp(fileName: string): number | undefined {\n const match = FILE_NAME_TIMESTAMP.exec(fileName);\n if (!match) return undefined;\n const [, date, hours, minutes, seconds, millis] = match;\n const ms = Date.parse(`${date}T${hours}:${minutes}:${seconds}.${millis}Z`);\n return Number.isNaN(ms) ? undefined : ms;\n }\n\n private collectJsonlFiles(dir: string): string[] {\n const files: string[] = [];\n for (const entry of safeReaddir(dir)) {\n const fullPath = path.join(dir, entry);\n const stat = safeStat(fullPath);\n if (!stat) continue;\n if (stat.isDirectory()) {\n files.push(...this.collectJsonlFiles(fullPath));\n } else if (stat.isFile() && entry.endsWith(\".jsonl\")) {\n files.push(fullPath);\n }\n }\n return files;\n }\n\n private encodeProjectDir(cwd: string): string {\n const normalized = path.resolve(cwd);\n return `--${normalized.replace(/^\\//, \"\").replace(/\\//g, \"-\")}--`;\n }\n}\n\nfunction processKey(proc: ProcessInfo): string {\n return `${proc.pid}:${proc.startTime?.getTime() ?? \"\"}`;\n}\n"],"names":["path","matchProcessesToSessions","MATCH_TOLERANCE_MS","isDirectory","isSafePathSegment","listJsonl","safeReaddir","safeStat","PI_SESSION_HEAD_MAX_BYTES","PiSessionParser","homeDir","FILE_NAME_TIMESTAMP","PiSessionLocator","sessionsDir","heads","Map","noMatchDirs","generation","options","parser","join","matchRunningProcesses","processes","length","legacyMatches","fallback","scans","groupByProjectDir","sessions","discoverSessionsInDirs","rememberUnmatchedDirs","pruneHeads","discoverLiveSessions","discoverHistoricalSessionFiles","collectJsonlFiles","findHistoricalSessionFilesById","sessionId","filter","filePath","basename","endsWith","skipUnchanged","proc","cwd","startTime","projectDir","encodeProjectDir","scan","get","push","stat","set","dirMtimeMs","mtimeMs","keys","has","delete","noMatch","unchanged","undefined","every","processKeys","processKey","startTimes","map","getTime","fileName","isFile","birthtimeMs","createdMs","fileNameTimestamp","inWindow","some","startMs","Math","abs","head","readHead","sessionIdFromFile","resolvedCwd","projectPath","cached","reusable","dev","ino","size","isHeadSettled","seen","readSessionHead","Boolean","bytesRead","matches","matchedPids","Set","match","process","pid","entry","exec","date","hours","minutes","seconds","millis","ms","Date","parse","Number","isNaN","dir","files","fullPath","normalized","resolve","replace"],"mappings":"AACA,YAAYA,UAAU,OAAO;AAE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AIA,KAAK/C,WAAW,IAAI;gBACtB2G,MAAM7D,IAAI,IAAI,IAAI,CAACf,iBAAiB,CAAC6E;YACvC,OAAO,IAAI7D,KAAKiB,MAAM,MAAM8B,MAAMzD,QAAQ,CAAC,WAAW;gBACpDsE,MAAM7D,IAAI,CAAC8D;YACb;QACF;QACA,OAAOD;IACT;IAEQhE,iBAAiBH,GAAW,EAAU;QAC5C,MAAMqE,aAAahH,KAAKiH,OAAO,CAACtE;QAChC,OAAO,CAAC,EAAE,EAAEqE,WAAWE,OAAO,CAAC,OAAO,IAAIA,OAAO,CAAC,OAAO,KAAK,EAAE,CAAC;IACnE;AACF;AAEA,SAASpD,WAAWpB,IAAiB;IACnC,OAAO,GAAGA,KAAKsD,GAAG,CAAC,CAAC,EAAEtD,KAAKE,SAAS,EAAEqB,aAAa,IAAI;AACzD"}
|
|
1
|
+
{"version":3,"sources":["../../../src/harnesses/pi/PiSessionLocator.ts"],"sourcesContent":["import type * as fs from \"fs\";\nimport * as path from \"path\";\nimport type { ProcessInfo } from \"../../adapters/AgentAdapter.js\";\nimport { matchProcessesToSessions, type MatchResult } from \"../../utils/matching.js\";\nimport { MATCH_TOLERANCE_MS } from \"../../utils/matchingConstants.js\";\nimport {\n isDirectory,\n isSafePathSegment,\n listJsonl,\n safeReaddir,\n safeStat,\n type SessionFile,\n} from \"../../utils/session.js\";\nimport {\n PI_SESSION_HEAD_MAX_BYTES,\n PiSessionParser,\n type PiSessionHead,\n} from \"./PiSessionParser.js\";\nimport { homeDir } from \"../shared.js\";\n\nexport interface PiSessionLocatorOptions {\n sessionsDir?: string;\n}\n\nexport interface PiProcessSessionMatches {\n legacyMatches: MatchResult[];\n fallback: ProcessInfo[];\n}\n\n/** Pi session file names start with their creation time: `2026-06-10T08-58-20-754Z_<id>.jsonl`. */\nconst FILE_NAME_TIMESTAMP = /^(\\d{4}-\\d{2}-\\d{2})T(\\d{2})-(\\d{2})-(\\d{2})-(\\d{3})Z_/;\n\ninterface ProjectDirScan {\n dirMtimeMs: number;\n /** .jsonl files seen in the last listing of this project dir. */\n jsonlCount?: number;\n processes: ProcessInfo[];\n}\n\ninterface CachedHead {\n dev: number;\n ino: number;\n size: number;\n head: PiSessionHead;\n seen: number;\n}\n\n/** A project dir whose last scan matched none of the processes that scanned it. */\ninterface NoMatchEntry {\n dirMtimeMs: number;\n /** Session file count when the dir was last scanned (dir mtime alone is coarse). */\n jsonlCount: number;\n processKeys: Set<string>;\n}\n\n/**\n * Finds Pi session files for running processes that the registry and the\n * sessions.json tracker could not resolve.\n *\n * Live discovery is scoped so its cost follows live agents, not Pi history:\n * - only the project dir Pi derives from each process cwd is listed;\n * - only files created within MATCH_TOLERANCE_MS (the matcher's tolerance) of a\n * process start are opened,\n * and only their head (<= 64 KiB) is read for session id and cwd;\n * - heads are cached per file (dev/ino/size) across calls on one instance;\n * - a project dir whose scan matched none of its processes is skipped until\n * its mtime changes, its jsonl count changes (when mtime is in the current\n * second — directory mtimes are often second-granular), or a process it has\n * not seen needs it.\n *\n * Reuse one instance across refreshes to benefit from the caches.\n */\nexport class PiSessionLocator {\n private readonly sessionsDir: string;\n private readonly heads = new Map<string, CachedHead>();\n private readonly noMatchDirs = new Map<string, NoMatchEntry>();\n private generation = 0;\n\n constructor(\n options: PiSessionLocatorOptions = {},\n private readonly parser: PiSessionParser = new PiSessionParser(),\n ) {\n this.sessionsDir = options.sessionsDir ?? path.join(homeDir(), \".pi\", \"agent\", \"sessions\");\n }\n\n matchRunningProcesses(processes: ProcessInfo[]): PiProcessSessionMatches {\n this.generation++;\n try {\n if (processes.length === 0) return { legacyMatches: [], fallback: [] };\n\n const scans = this.groupByProjectDir(processes, true);\n const sessions = this.discoverSessionsInDirs(scans);\n if (sessions.length === 0) {\n this.rememberUnmatchedDirs(scans, []);\n return { legacyMatches: [], fallback: processes };\n }\n\n const legacyMatches = matchProcessesToSessions(processes, sessions);\n this.rememberUnmatchedDirs(scans, legacyMatches);\n return { legacyMatches, fallback: processes };\n } finally {\n this.pruneHeads();\n }\n }\n\n /**\n * Session files that could match `processes`: files in each process's\n * project dir created within the start-time window, with session id and\n * cwd taken from a bounded head read.\n */\n discoverLiveSessions(processes: ProcessInfo[] = []): SessionFile[] {\n return this.discoverSessionsInDirs(this.groupByProjectDir(processes, false));\n }\n\n discoverHistoricalSessionFiles(): string[] {\n return this.collectJsonlFiles(this.sessionsDir);\n }\n\n findHistoricalSessionFilesById(sessionId: string): string[] {\n if (!isSafePathSegment(sessionId)) return [];\n\n return this.collectJsonlFiles(this.sessionsDir).filter((filePath) => {\n const basename = path.basename(filePath, \".jsonl\");\n return basename === sessionId || basename.endsWith(`_${sessionId}`);\n });\n }\n\n /**\n * Group matchable processes (cwd and start time set) by the project dir Pi\n * stores their sessions in. With `skipUnchanged`, dirs whose previous scan\n * matched nothing and that have not changed since are left out.\n */\n private groupByProjectDir(\n processes: ProcessInfo[],\n skipUnchanged: boolean,\n ): Map<string, ProjectDirScan> {\n const scans = new Map<string, ProjectDirScan>();\n if (!isDirectory(this.sessionsDir)) return scans;\n\n for (const proc of processes) {\n if (!proc.cwd || !proc.startTime) continue;\n const projectDir = path.join(this.sessionsDir, this.encodeProjectDir(proc.cwd));\n const scan = scans.get(projectDir);\n if (scan) {\n scan.processes.push(proc);\n continue;\n }\n const stat = safeStat(projectDir);\n if (stat?.isDirectory()) {\n scans.set(projectDir, { dirMtimeMs: stat.mtimeMs, processes: [proc] });\n }\n }\n\n if (!skipUnchanged) return scans;\n\n for (const projectDir of this.noMatchDirs.keys()) {\n if (!scans.has(projectDir)) this.noMatchDirs.delete(projectDir);\n }\n for (const [projectDir, scan] of scans) {\n const noMatch = this.noMatchDirs.get(projectDir);\n // An unmatched process never held a session, so dropping one cannot free\n // a session for another; only a dir change or an unseen process can.\n const unchanged =\n noMatch !== undefined &&\n noMatch.dirMtimeMs === scan.dirMtimeMs &&\n scan.processes.every((proc) => noMatch.processKeys.has(processKey(proc)));\n if (!unchanged) {\n this.noMatchDirs.delete(projectDir);\n continue;\n }\n const ambiguousMtimeSecond =\n Math.floor(scan.dirMtimeMs / 1000) === Math.floor(Date.now() / 1000);\n if (ambiguousMtimeSecond && listJsonl(projectDir).length !== noMatch.jsonlCount) {\n this.noMatchDirs.delete(projectDir);\n continue;\n }\n scans.delete(projectDir);\n }\n return scans;\n }\n\n private discoverSessionsInDirs(scans: Map<string, ProjectDirScan>): SessionFile[] {\n const sessions: SessionFile[] = [];\n for (const [projectDir, scan] of scans) {\n const cwd = scan.processes[0]?.cwd ?? \"\";\n const startTimes = scan.processes.map((proc) => proc.startTime?.getTime() ?? 0);\n\n const fileNames = listJsonl(projectDir);\n scan.jsonlCount = fileNames.length;\n for (const fileName of fileNames) {\n const filePath = path.join(projectDir, fileName);\n const stat = safeStat(filePath);\n if (!stat?.isFile()) continue;\n\n const birthtimeMs = stat.birthtimeMs || stat.mtimeMs;\n const createdMs = this.fileNameTimestamp(fileName);\n const inWindow = startTimes.some(\n (startMs) =>\n Math.abs(startMs - birthtimeMs) <= MATCH_TOLERANCE_MS ||\n (createdMs !== undefined && Math.abs(startMs - createdMs) <= MATCH_TOLERANCE_MS),\n );\n if (!inWindow) continue;\n\n const head = this.readHead(filePath, stat);\n sessions.push({\n sessionId: head?.sessionId || this.parser.sessionIdFromFile(filePath),\n filePath,\n projectDir,\n birthtimeMs,\n resolvedCwd: head?.projectPath || cwd,\n });\n }\n }\n return sessions;\n }\n\n /** Head metadata for `filePath`, re-read only when appended bytes could change it. */\n private readHead(filePath: string, stat: fs.Stats): PiSessionHead | null {\n const cached = this.heads.get(filePath);\n const reusable =\n cached !== undefined &&\n cached.dev === stat.dev &&\n cached.ino === stat.ino &&\n (cached.size === stat.size || (stat.size > cached.size && this.isHeadSettled(cached.head)));\n if (reusable) {\n cached.seen = this.generation;\n return cached.head;\n }\n\n const head = this.parser.readSessionHead(filePath);\n if (head) {\n this.heads.set(filePath, {\n dev: stat.dev,\n ino: stat.ino,\n size: stat.size,\n head,\n seen: this.generation,\n });\n } else {\n this.heads.delete(filePath);\n }\n return head;\n }\n\n /** Appending to a file cannot change a head that found both fields or hit the byte cap. */\n private isHeadSettled(head: PiSessionHead): boolean {\n return (\n (Boolean(head.sessionId) && Boolean(head.projectPath)) ||\n head.bytesRead >= PI_SESSION_HEAD_MAX_BYTES\n );\n }\n\n private rememberUnmatchedDirs(scans: Map<string, ProjectDirScan>, matches: MatchResult[]): void {\n const matchedPids = new Set(matches.map((match) => match.process.pid));\n for (const [projectDir, scan] of scans) {\n if (scan.processes.some((proc) => matchedPids.has(proc.pid))) continue;\n this.noMatchDirs.set(projectDir, {\n dirMtimeMs: scan.dirMtimeMs,\n jsonlCount: scan.jsonlCount ?? listJsonl(projectDir).length,\n processKeys: new Set(scan.processes.map(processKey)),\n });\n }\n }\n\n private pruneHeads(): void {\n for (const [filePath, entry] of this.heads) {\n if (entry.seen !== this.generation) this.heads.delete(filePath);\n }\n }\n\n private fileNameTimestamp(fileName: string): number | undefined {\n const match = FILE_NAME_TIMESTAMP.exec(fileName);\n if (!match) return undefined;\n const [, date, hours, minutes, seconds, millis] = match;\n const ms = Date.parse(`${date}T${hours}:${minutes}:${seconds}.${millis}Z`);\n return Number.isNaN(ms) ? undefined : ms;\n }\n\n private collectJsonlFiles(dir: string): string[] {\n const files: string[] = [];\n for (const entry of safeReaddir(dir)) {\n const fullPath = path.join(dir, entry);\n const stat = safeStat(fullPath);\n if (!stat) continue;\n if (stat.isDirectory()) {\n files.push(...this.collectJsonlFiles(fullPath));\n } else if (stat.isFile() && entry.endsWith(\".jsonl\")) {\n files.push(fullPath);\n }\n }\n return files;\n }\n\n private encodeProjectDir(cwd: string): string {\n const normalized = path.resolve(cwd);\n return `--${normalized.replace(/^\\//, \"\").replace(/\\//g, \"-\")}--`;\n }\n}\n\nfunction processKey(proc: ProcessInfo): string {\n return `${proc.pid}:${proc.startTime?.getTime() ?? \"\"}`;\n}\n"],"names":["path","matchProcessesToSessions","MATCH_TOLERANCE_MS","isDirectory","isSafePathSegment","listJsonl","safeReaddir","safeStat","PI_SESSION_HEAD_MAX_BYTES","PiSessionParser","homeDir","FILE_NAME_TIMESTAMP","PiSessionLocator","sessionsDir","heads","Map","noMatchDirs","generation","options","parser","join","matchRunningProcesses","processes","length","legacyMatches","fallback","scans","groupByProjectDir","sessions","discoverSessionsInDirs","rememberUnmatchedDirs","pruneHeads","discoverLiveSessions","discoverHistoricalSessionFiles","collectJsonlFiles","findHistoricalSessionFilesById","sessionId","filter","filePath","basename","endsWith","skipUnchanged","proc","cwd","startTime","projectDir","encodeProjectDir","scan","get","push","stat","set","dirMtimeMs","mtimeMs","keys","has","delete","noMatch","unchanged","undefined","every","processKeys","processKey","ambiguousMtimeSecond","Math","floor","Date","now","jsonlCount","startTimes","map","getTime","fileNames","fileName","isFile","birthtimeMs","createdMs","fileNameTimestamp","inWindow","some","startMs","abs","head","readHead","sessionIdFromFile","resolvedCwd","projectPath","cached","reusable","dev","ino","size","isHeadSettled","seen","readSessionHead","Boolean","bytesRead","matches","matchedPids","Set","match","process","pid","entry","exec","date","hours","minutes","seconds","millis","ms","parse","Number","isNaN","dir","files","fullPath","normalized","resolve","replace"],"mappings":"AACA,YAAYA,UAAU,OAAO;AAE7B,SAASC,wBAAwB,QAA0B,0BAA0B;AACrF,SAASC,kBAAkB,QAAQ,mCAAmC;AACtE,SACEC,WAAW,EACXC,iBAAiB,EACjBC,SAAS,EACTC,WAAW,EACXC,QAAQ,QAEH,yBAAyB;AAChC,SACEC,yBAAyB,EACzBC,eAAe,QAEV,uBAAuB;AAC9B,SAASC,OAAO,QAAQ,eAAe;AAWvC,iGAAiG,GACjG,MAAMC,sBAAsB;AAyB5B;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC;;IACMC,YAAoB;IACpBC,QAAQ,IAAIC,MAA0B;IACtCC,cAAc,IAAID,MAA4B;IACvDE,aAAa,EAAE;IAEvB,YACEC,UAAmC,CAAC,CAAC,EACrC,AAAiBC,SAA0B,IAAIV,iBAAiB,CAChE;aADiBU,S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