@codemieai/code 0.11.0 → 0.13.0
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/README.md +109 -56
- package/bin/codemie-copilot.js +224 -0
- package/bin/codemie-pi.js +18 -0
- package/dist/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +16 -10
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +43 -19
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/core/agent-aliases.d.ts +17 -0
- package/dist/agents/core/agent-aliases.d.ts.map +1 -0
- package/dist/agents/core/agent-aliases.js +41 -0
- package/dist/agents/core/agent-aliases.js.map +1 -0
- package/dist/agents/core/session/BaseSessionAdapter.d.ts +19 -0
- package/dist/agents/core/session/BaseSessionAdapter.d.ts.map +1 -1
- package/dist/agents/core/session/session-origin-audit.d.ts +13 -0
- package/dist/agents/core/session/session-origin-audit.d.ts.map +1 -1
- package/dist/agents/core/session/session-origin-audit.js +34 -0
- package/dist/agents/core/session/session-origin-audit.js.map +1 -1
- package/dist/agents/core/session/stale-session-reconciliation.d.ts +42 -0
- package/dist/agents/core/session/stale-session-reconciliation.d.ts.map +1 -0
- package/dist/agents/core/session/stale-session-reconciliation.js +141 -0
- package/dist/agents/core/session/stale-session-reconciliation.js.map +1 -0
- package/dist/agents/core/session/types.d.ts +19 -0
- package/dist/agents/core/session/types.d.ts.map +1 -1
- package/dist/agents/core/session/types.js +17 -1
- package/dist/agents/core/session/types.js.map +1 -1
- package/dist/agents/core/types.d.ts +11 -0
- package/dist/agents/core/types.d.ts.map +1 -1
- package/dist/agents/plugins/codex/codex.reconciliation.d.ts +15 -35
- package/dist/agents/plugins/codex/codex.reconciliation.d.ts.map +1 -1
- package/dist/agents/plugins/codex/codex.reconciliation.js +8 -139
- package/dist/agents/plugins/codex/codex.reconciliation.js.map +1 -1
- package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.d.ts +146 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.js +12 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli-event-types.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.constants.d.ts +15 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.constants.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.constants.js +15 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.constants.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.models.d.ts +8 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.models.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.models.js +195 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.models.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.paths.d.ts +11 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.paths.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.paths.js +21 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.paths.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.d.ts +14 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.js +263 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.plugin.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.session.d.ts +43 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.session.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.session.js +343 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.session.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.d.ts +10 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.js +41 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.storage-utils.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.usage.d.ts +37 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.usage.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.usage.js +96 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.usage.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.d.ts +17 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.js +58 -0
- package/dist/agents/plugins/copilot-cli/copilot-cli.workspace.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/index.d.ts +3 -0
- package/dist/agents/plugins/copilot-cli/index.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/index.js +3 -0
- package/dist/agents/plugins/copilot-cli/index.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.d.ts +18 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.js +313 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.conversations-processor.js.map +1 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.d.ts +16 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.d.ts.map +1 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.js +22 -0
- package/dist/agents/plugins/copilot-cli/session/processors/copilot-cli.metrics-processor.js.map +1 -0
- package/dist/agents/plugins/pi/__tests__/home-redirect.d.ts +12 -0
- package/dist/agents/plugins/pi/__tests__/home-redirect.d.ts.map +1 -0
- package/dist/agents/plugins/pi/__tests__/home-redirect.js +27 -0
- package/dist/agents/plugins/pi/__tests__/home-redirect.js.map +1 -0
- package/dist/agents/plugins/pi/extension/README.md +68 -0
- package/dist/agents/plugins/pi/extension/index.js +161 -0
- package/dist/agents/plugins/pi/extension/package.json +8 -0
- package/dist/agents/plugins/pi/index.d.ts +3 -0
- package/dist/agents/plugins/pi/index.d.ts.map +1 -0
- package/dist/agents/plugins/pi/index.js +3 -0
- package/dist/agents/plugins/pi/index.js.map +1 -0
- package/dist/agents/plugins/pi/pi.extension.d.ts +60 -0
- package/dist/agents/plugins/pi/pi.extension.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.extension.js +201 -0
- package/dist/agents/plugins/pi/pi.extension.js.map +1 -0
- package/dist/agents/plugins/pi/pi.incremental-sync.d.ts +63 -0
- package/dist/agents/plugins/pi/pi.incremental-sync.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.incremental-sync.js +266 -0
- package/dist/agents/plugins/pi/pi.incremental-sync.js.map +1 -0
- package/dist/agents/plugins/pi/pi.models.d.ts +20 -0
- package/dist/agents/plugins/pi/pi.models.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.models.js +201 -0
- package/dist/agents/plugins/pi/pi.models.js.map +1 -0
- package/dist/agents/plugins/pi/pi.packages.d.ts +11 -0
- package/dist/agents/plugins/pi/pi.packages.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.packages.js +35 -0
- package/dist/agents/plugins/pi/pi.packages.js.map +1 -0
- package/dist/agents/plugins/pi/pi.paths.d.ts +37 -0
- package/dist/agents/plugins/pi/pi.paths.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.paths.js +146 -0
- package/dist/agents/plugins/pi/pi.paths.js.map +1 -0
- package/dist/agents/plugins/pi/pi.plugin.d.ts +30 -0
- package/dist/agents/plugins/pi/pi.plugin.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.plugin.js +453 -0
- package/dist/agents/plugins/pi/pi.plugin.js.map +1 -0
- package/dist/agents/plugins/pi/pi.session.d.ts +114 -0
- package/dist/agents/plugins/pi/pi.session.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.session.js +388 -0
- package/dist/agents/plugins/pi/pi.session.js.map +1 -0
- package/dist/agents/plugins/pi/pi.setup.d.ts +2 -0
- package/dist/agents/plugins/pi/pi.setup.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.setup.js +33 -0
- package/dist/agents/plugins/pi/pi.setup.js.map +1 -0
- package/dist/agents/plugins/pi/pi.types.d.ts +143 -0
- package/dist/agents/plugins/pi/pi.types.d.ts.map +1 -0
- package/dist/agents/plugins/pi/pi.types.js +74 -0
- package/dist/agents/plugins/pi/pi.types.js.map +1 -0
- package/dist/agents/plugins/pi/session/pi-file-operations.d.ts +17 -0
- package/dist/agents/plugins/pi/session/pi-file-operations.d.ts.map +1 -0
- package/dist/agents/plugins/pi/session/pi-file-operations.js +98 -0
- package/dist/agents/plugins/pi/session/pi-file-operations.js.map +1 -0
- package/dist/agents/plugins/pi/session/pi-named-invocations.d.ts +52 -0
- package/dist/agents/plugins/pi/session/pi-named-invocations.d.ts.map +1 -0
- package/dist/agents/plugins/pi/session/pi-named-invocations.js +189 -0
- package/dist/agents/plugins/pi/session/pi-named-invocations.js.map +1 -0
- package/dist/agents/plugins/pi/session/pi-user-prompt.d.ts +14 -0
- package/dist/agents/plugins/pi/session/pi-user-prompt.d.ts.map +1 -0
- package/dist/agents/plugins/pi/session/pi-user-prompt.js +51 -0
- package/dist/agents/plugins/pi/session/pi-user-prompt.js.map +1 -0
- package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.d.ts +52 -0
- package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.d.ts.map +1 -0
- package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.js +716 -0
- package/dist/agents/plugins/pi/session/processors/pi.conversations-processor.js.map +1 -0
- package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.d.ts +104 -0
- package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.d.ts.map +1 -0
- package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.js +595 -0
- package/dist/agents/plugins/pi/session/processors/pi.metrics-processor.js.map +1 -0
- package/dist/agents/registry.d.ts +20 -0
- package/dist/agents/registry.d.ts.map +1 -1
- package/dist/agents/registry.js +29 -2
- package/dist/agents/registry.js.map +1 -1
- package/dist/cli/commands/analytics/agent-labels.d.ts +3 -0
- package/dist/cli/commands/analytics/agent-labels.d.ts.map +1 -0
- package/dist/cli/commands/analytics/agent-labels.js +20 -0
- package/dist/cli/commands/analytics/agent-labels.js.map +1 -0
- package/dist/cli/commands/analytics/cost/cost-enricher.d.ts.map +1 -1
- package/dist/cli/commands/analytics/cost/cost-enricher.js +12 -0
- package/dist/cli/commands/analytics/cost/cost-enricher.js.map +1 -1
- package/dist/cli/commands/analytics/cost/types.d.ts +10 -0
- package/dist/cli/commands/analytics/cost/types.d.ts.map +1 -1
- package/dist/cli/commands/analytics/cost/usage-readers.d.ts +24 -0
- package/dist/cli/commands/analytics/cost/usage-readers.d.ts.map +1 -1
- package/dist/cli/commands/analytics/cost/usage-readers.js +253 -54
- package/dist/cli/commands/analytics/cost/usage-readers.js.map +1 -1
- package/dist/cli/commands/analytics/formatter.d.ts.map +1 -1
- package/dist/cli/commands/analytics/formatter.js +10 -2
- package/dist/cli/commands/analytics/formatter.js.map +1 -1
- package/dist/cli/commands/analytics/index.d.ts.map +1 -1
- package/dist/cli/commands/analytics/index.js +22 -0
- package/dist/cli/commands/analytics/index.js.map +1 -1
- package/dist/cli/commands/analytics/native-loader.d.ts +21 -4
- package/dist/cli/commands/analytics/native-loader.d.ts.map +1 -1
- package/dist/cli/commands/analytics/native-loader.js +267 -88
- package/dist/cli/commands/analytics/native-loader.js.map +1 -1
- package/dist/cli/commands/analytics/report/client/app.js +77 -15
- package/dist/cli/commands/analytics/report/payload-builder.d.ts.map +1 -1
- package/dist/cli/commands/analytics/report/payload-builder.js +32 -2
- package/dist/cli/commands/analytics/report/payload-builder.js.map +1 -1
- package/dist/cli/commands/analytics/report/types.d.ts +11 -0
- package/dist/cli/commands/analytics/report/types.d.ts.map +1 -1
- package/dist/cli/commands/hook.d.ts.map +1 -1
- package/dist/cli/commands/hook.js +71 -29
- package/dist/cli/commands/hook.js.map +1 -1
- package/dist/cli/commands/install.d.ts.map +1 -1
- package/dist/cli/commands/install.js +9 -7
- package/dist/cli/commands/install.js.map +1 -1
- package/dist/cli/commands/list.d.ts.map +1 -1
- package/dist/cli/commands/list.js +4 -2
- package/dist/cli/commands/list.js.map +1 -1
- package/dist/cli/commands/setup.d.ts +3 -1
- package/dist/cli/commands/setup.d.ts.map +1 -1
- package/dist/cli/commands/setup.js +87 -63
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/commands/uninstall.d.ts.map +1 -1
- package/dist/cli/commands/uninstall.js +6 -4
- package/dist/cli/commands/uninstall.js.map +1 -1
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +7 -5
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/first-time.d.ts.map +1 -1
- package/dist/cli/first-time.js +10 -9
- package/dist/cli/first-time.js.map +1 -1
- package/dist/providers/core/auth-validation.d.ts +7 -2
- package/dist/providers/core/auth-validation.d.ts.map +1 -1
- package/dist/providers/core/auth-validation.js +11 -5
- package/dist/providers/core/auth-validation.js.map +1 -1
- package/dist/providers/core/types.d.ts +16 -0
- package/dist/providers/core/types.d.ts.map +1 -1
- package/dist/providers/core/types.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.d.ts +8 -3
- package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.js +46 -11
- package/dist/providers/plugins/sso/proxy/plugins/claude-request-normalizer.plugin.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.d.ts +23 -13
- package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.js +75 -18
- package/dist/providers/plugins/sso/proxy/plugins/codex-encrypted-content-sanitizer.plugin.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.d.ts +21 -0
- package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.js +133 -0
- package/dist/providers/plugins/sso/proxy/plugins/copilot-encrypted-content-sanitizer.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/header-injection.plugin.js +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/header-injection.plugin.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +2 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js +4 -2
- package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/types.d.ts +11 -0
- package/dist/providers/plugins/sso/proxy/plugins/types.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts +2 -0
- package/dist/providers/plugins/sso/proxy/sso.proxy.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.js +37 -1
- package/dist/providers/plugins/sso/proxy/sso.proxy.js.map +1 -1
- package/dist/providers/plugins/sso/session/SessionSyncer.d.ts.map +1 -1
- package/dist/providers/plugins/sso/session/SessionSyncer.js +13 -0
- package/dist/providers/plugins/sso/session/SessionSyncer.js.map +1 -1
- package/dist/providers/plugins/sso/session/processors/conversations/syncProcessor.js +6 -0
- package/dist/providers/plugins/sso/session/processors/conversations/syncProcessor.js.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.d.ts +0 -6
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.d.ts.map +1 -1
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.js +28 -19
- package/dist/providers/plugins/sso/session/processors/metrics/metrics-post-processor.js.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.setup-steps.js +39 -22
- package/dist/providers/plugins/sso/sso.setup-steps.js.map +1 -1
- package/dist/utils/interactive.d.ts +14 -0
- package/dist/utils/interactive.d.ts.map +1 -0
- package/dist/utils/interactive.js +16 -0
- package/dist/utils/interactive.js.map +1 -0
- package/package.json +6 -5
- package/scripts/copy-plugins.js +6 -0
- package/scripts/release.sh +54 -0
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { BaseAgentAdapter } from '../../core/BaseAgentAdapter.js';
|
|
2
|
+
import { logger } from '../../../utils/logger.js';
|
|
3
|
+
import { preparePiAgentDir } from './pi.setup.js';
|
|
4
|
+
import { fetchAndBuildPiModels, classifyPiModel } from './pi.models.js';
|
|
5
|
+
import { getPiAgentDir, resolvePiSessionDir } from './pi.paths.js';
|
|
6
|
+
import { LEDGER_PATH_ENV, ensurePiCodeMieExtension, getPiRunLedgerPath, readPiRunLedger, } from './pi.extension.js';
|
|
7
|
+
import { resolve } from 'path';
|
|
8
|
+
import { detectGitBranch, detectGitRemoteRepo } from '../../../utils/processes.js';
|
|
9
|
+
import { appendTranscriptMarker } from '../../core/session/session-origin-audit.js';
|
|
10
|
+
import { reconcileStaleSessions } from '../../core/session/stale-session-reconciliation.js';
|
|
11
|
+
import { startPiIncrementalSync, stopPiIncrementalSync } from './pi.incremental-sync.js';
|
|
12
|
+
import { installRequiredPiPackages } from './pi.packages.js';
|
|
13
|
+
import { PiSessionAdapter } from './pi.session.js';
|
|
14
|
+
/**
|
|
15
|
+
* Pi flags that select an existing session. Pi rejects `--session-id` when any of
|
|
16
|
+
* them is present (`validateSessionIdFlags` in Pi's `main.ts` calls `process.exit(1)`),
|
|
17
|
+
* so the injected id must be suppressed for these runs. `--fork` is deliberately
|
|
18
|
+
* absent: Pi allows `--fork` together with `--session-id` and uses the id to name
|
|
19
|
+
* the forked session.
|
|
20
|
+
*/
|
|
21
|
+
const PI_SESSION_SELECTION_FLAGS = ['--session', '--continue', '-c', '--resume', '-r'];
|
|
22
|
+
/**
|
|
23
|
+
* Read the value of a `<flag> <value>` pair. Pi's parser only accepts the
|
|
24
|
+
* space-separated form, so `--flag=value` is deliberately not matched, and it
|
|
25
|
+
* assigns on every occurrence, so the last one wins.
|
|
26
|
+
*/
|
|
27
|
+
function readFlagValue(args, flag) {
|
|
28
|
+
const index = args.lastIndexOf(flag);
|
|
29
|
+
return index !== -1 && index + 1 < args.length ? args[index + 1] : undefined;
|
|
30
|
+
}
|
|
31
|
+
function hasSessionSelectionFlag(args) {
|
|
32
|
+
return PI_SESSION_SELECTION_FLAGS.some((flag) => args.includes(flag));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Reconcile CodeMie's CLI surface with Pi's session flags before the run starts.
|
|
36
|
+
*
|
|
37
|
+
* Two argv-derived facts are needed later by hooks that cannot see argv:
|
|
38
|
+
* `beforeRun` receives only `env`, and `enrichArgs` receives no env at all. Both
|
|
39
|
+
* are published through `envOverrides`, which `BaseAgentAdapter` spreads into the
|
|
40
|
+
* run-scoped `env` object that also reaches `onSessionEnd` and session discovery.
|
|
41
|
+
*/
|
|
42
|
+
export function preparePiInvocation(args, envOverrides) {
|
|
43
|
+
// CodeMie declares `--resume <session-id>`, but Pi's `--resume`/`-r` is a boolean
|
|
44
|
+
// that opens an interactive picker, which would leave the id as a bare positional
|
|
45
|
+
// and send it to the model as a chat message. `--session <id>` is Pi's
|
|
46
|
+
// value-taking "open this session and keep appending" flag. If the user also
|
|
47
|
+
// passed `--session`, theirs wins in Pi and this pair is dropped rather than
|
|
48
|
+
// rewritten, so a second `--session` cannot shadow it and the orphaned id cannot
|
|
49
|
+
// leak into the conversation.
|
|
50
|
+
const resumeIndex = args.indexOf('--resume');
|
|
51
|
+
const hasResumeValue = resumeIndex !== -1 && resumeIndex + 1 < args.length;
|
|
52
|
+
let piArgs = args;
|
|
53
|
+
if (hasResumeValue) {
|
|
54
|
+
piArgs = args.includes('--session')
|
|
55
|
+
? [...args.slice(0, resumeIndex), ...args.slice(resumeIndex + 2)]
|
|
56
|
+
: args.map((arg, index) => (index === resumeIndex ? '--session' : arg));
|
|
57
|
+
}
|
|
58
|
+
const overrides = { ...envOverrides };
|
|
59
|
+
// `--session-dir` is an unknown option to CodeMie's parser and reaches Pi verbatim,
|
|
60
|
+
// so discovery would otherwise scan a directory Pi never writes to. Seed the raw
|
|
61
|
+
// value; resolvePiSessionDir performs the tilde expansion Pi also applies.
|
|
62
|
+
const sessionDir = readFlagValue(piArgs, '--session-dir');
|
|
63
|
+
if (sessionDir) {
|
|
64
|
+
overrides.PI_CODING_AGENT_SESSION_DIR = sessionDir;
|
|
65
|
+
}
|
|
66
|
+
return { args: piArgs, envOverrides: overrides };
|
|
67
|
+
}
|
|
68
|
+
function buildPiHookConfig(env, sessionId) {
|
|
69
|
+
return {
|
|
70
|
+
agentName: env.CODEMIE_AGENT || 'pi',
|
|
71
|
+
sessionId,
|
|
72
|
+
provider: env.CODEMIE_PROVIDER,
|
|
73
|
+
apiBaseUrl: env.CODEMIE_BASE_URL,
|
|
74
|
+
ssoUrl: env.CODEMIE_URL,
|
|
75
|
+
syncApiUrl: env.CODEMIE_SYNC_API_URL,
|
|
76
|
+
version: env.CODEMIE_CLI_VERSION,
|
|
77
|
+
profileName: env.CODEMIE_PROFILE_NAME,
|
|
78
|
+
project: env.CODEMIE_PROJECT,
|
|
79
|
+
model: env.CODEMIE_MODEL,
|
|
80
|
+
clientType: 'codemie-pi',
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Point the CodeMie session record at what the run actually produced.
|
|
85
|
+
*
|
|
86
|
+
* Three things are only knowable once Pi has exited, and each has a consumer that
|
|
87
|
+
* silently degrades without it:
|
|
88
|
+
*
|
|
89
|
+
* - `correlation.agentSessionFile` — the analytics cost path resolves the native
|
|
90
|
+
* transcript through this field. Pi left it empty, so token and cost figures were
|
|
91
|
+
* never readable for a Pi session, and the report blamed a missing token reader.
|
|
92
|
+
* - `correlation.agentSessionId` — the metrics aggregator prefers it when labelling
|
|
93
|
+
* the wire `session_id`, which should be Pi's id rather than CodeMie's.
|
|
94
|
+
* - `workingDirectory` / `gitBranch` / `repository` — `--session <path>` runs the
|
|
95
|
+
* whole session under the transcript's cwd, which may be a different repository
|
|
96
|
+
* than the one CodeMie was launched from.
|
|
97
|
+
*/
|
|
98
|
+
async function correlateRunToSession(sessionId, ledger) {
|
|
99
|
+
if (!ledger.primaryTranscript)
|
|
100
|
+
return;
|
|
101
|
+
try {
|
|
102
|
+
const { SessionStore } = await import('../../core/session/SessionStore.js');
|
|
103
|
+
const store = new SessionStore();
|
|
104
|
+
const session = await store.loadSession(sessionId);
|
|
105
|
+
if (!session) {
|
|
106
|
+
logger.debug(`[pi] No session record for ${sessionId}; skipping correlation`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
session.correlation = {
|
|
110
|
+
...session.correlation,
|
|
111
|
+
status: 'matched',
|
|
112
|
+
agentSessionFile: ledger.primaryTranscript,
|
|
113
|
+
...(ledger.piSessionId && { agentSessionId: ledger.piSessionId }),
|
|
114
|
+
detectedAt: Date.now(),
|
|
115
|
+
};
|
|
116
|
+
if (ledger.cwd && resolve(ledger.cwd) !== resolve(session.workingDirectory)) {
|
|
117
|
+
logger.debug(`[pi] Session ran under ${ledger.cwd}, not ${session.workingDirectory}`);
|
|
118
|
+
session.workingDirectory = ledger.cwd;
|
|
119
|
+
const [branch, repository] = await Promise.all([
|
|
120
|
+
detectGitBranch(ledger.cwd),
|
|
121
|
+
detectGitRemoteRepo(ledger.cwd),
|
|
122
|
+
]);
|
|
123
|
+
if (branch)
|
|
124
|
+
session.gitBranch = branch;
|
|
125
|
+
if (repository)
|
|
126
|
+
session.repository = repository;
|
|
127
|
+
}
|
|
128
|
+
await store.saveSession(session);
|
|
129
|
+
// Ownership sidecars, so analytics can tell a CodeMie-managed transcript from a
|
|
130
|
+
// bare `pi` one.
|
|
131
|
+
for (const transcript of ledger.transcripts) {
|
|
132
|
+
appendTranscriptMarker(transcript, sessionId, 'pi');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
137
|
+
logger.debug(`[pi] Correlating the run to its session record failed (non-blocking): ${msg}`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
export const PiPluginMetadata = {
|
|
141
|
+
name: 'pi',
|
|
142
|
+
displayName: 'Pi',
|
|
143
|
+
description: 'Pi - open-source coding agent harness',
|
|
144
|
+
npmPackage: '@earendil-works/pi-coding-agent',
|
|
145
|
+
cliCommand: process.env.CODEMIE_PI_BIN || 'pi',
|
|
146
|
+
sessionAnalyticsReport: true,
|
|
147
|
+
metricsConfig: {
|
|
148
|
+
excludeErrorsFromTools: ['bash'],
|
|
149
|
+
},
|
|
150
|
+
dataPaths: {
|
|
151
|
+
home: '.pi',
|
|
152
|
+
},
|
|
153
|
+
/**
|
|
154
|
+
* Pi names its resource directories differently from the scanner's defaults, so the
|
|
155
|
+
* lifecycle metric counted zero of everything until this mapping existed:
|
|
156
|
+
*
|
|
157
|
+
* - `prompts/` holds Pi's prompt templates, its slash-command equivalent. Flat `.md`
|
|
158
|
+
* files, which is what the `commands` counter looks for.
|
|
159
|
+
* - `extensions/` holds Pi's in-process hooks as `.ts`/`.js` files, which is what the
|
|
160
|
+
* `hooks` counter looks for.
|
|
161
|
+
* - `skills/` is a directory per skill with a `SKILL.md` entry, matching the default.
|
|
162
|
+
* - Pi has no agents or rules concept. The empty arrays are deliberate: they hold
|
|
163
|
+
* those categories at zero rather than scanning a directory Pi never reads.
|
|
164
|
+
*
|
|
165
|
+
* `global` is the user's own Pi home rather than the agent dir CodeMie redirects Pi
|
|
166
|
+
* to (`<cwd>/.pi/codemie/agent`). That dir is a copy of this one plus CodeMie's own
|
|
167
|
+
* metrics extension, so counting it would report our plumbing as a user-authored hook.
|
|
168
|
+
*/
|
|
169
|
+
extensionsConfig: {
|
|
170
|
+
project: '.pi',
|
|
171
|
+
global: '~/.pi/agent',
|
|
172
|
+
skillsEntryFile: 'SKILL.md',
|
|
173
|
+
dirNames: {
|
|
174
|
+
agents: [],
|
|
175
|
+
commands: ['prompts'],
|
|
176
|
+
skills: ['skills'],
|
|
177
|
+
hooks: ['extensions'],
|
|
178
|
+
rules: [],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
/**
|
|
182
|
+
* MCP is not part of Pi core — Pi ships without it deliberately ("It intentionally
|
|
183
|
+
* does not include built-in MCP", Pi's `docs/usage.md`). It arrives through the
|
|
184
|
+
* `pi-mcp-adapter` package, which CodeMie installs for every managed Pi
|
|
185
|
+
* (`REQUIRED_PI_PACKAGES` in `pi.packages.ts`), so under CodeMie the adapter is
|
|
186
|
+
* effectively core and its servers are worth counting.
|
|
187
|
+
*
|
|
188
|
+
* The adapter merges six files, lowest precedence first: `~/.config/mcp/mcp.json`,
|
|
189
|
+
* `~/.agents/mcp.json`, `~/.agents/mcp/mcp.json`, `<agentDir>/mcp.json`,
|
|
190
|
+
* `<cwd>/.mcp.json`, `<cwd>/.pi/mcp.json`. Three scopes cannot hold six files, so the
|
|
191
|
+
* two project files map directly and the four global ones become ordered candidates —
|
|
192
|
+
* and note `readMCPFromSource` takes the first candidate that *parses*, it never
|
|
193
|
+
* merges.
|
|
194
|
+
*
|
|
195
|
+
* `user` names the redirected agent dir, and deliberately **not** the user's own
|
|
196
|
+
* `~/.pi/agent/mcp.json`. `beforeRun` always sets `PI_CODING_AGENT_DIR` to
|
|
197
|
+
* `<cwd>/.pi/codemie/agent` and the adapter resolves `<agentDir>/mcp.json` through that
|
|
198
|
+
* variable, so under CodeMie the home file is never one of the adapter's six sources.
|
|
199
|
+
* Listing it would report servers this Pi does not load: `preparePiAgentDir` copies once
|
|
200
|
+
* and returns early forever after, so a project whose copy predates the user's MCP setup
|
|
201
|
+
* never acquires an `mcp.json` — a permanent state, not a first-run one — while the home
|
|
202
|
+
* file keeps growing, because a bare `pi` writes precisely there. Worse, because
|
|
203
|
+
* `readMCPFromSource` returns on the first candidate that *parses*, that phantom would
|
|
204
|
+
* also hide `~/.agents/*` and `~/.config/mcp`, which the adapter genuinely does merge.
|
|
205
|
+
* (This is the opposite call from `extensionsConfig.global` above, which avoids the copy
|
|
206
|
+
* because CodeMie injects its own extension into it. Nothing injects MCP servers, so
|
|
207
|
+
* here the copy is simply the truth.)
|
|
208
|
+
*
|
|
209
|
+
* The invariant that buys: every server reported is one this run actually loads.
|
|
210
|
+
*
|
|
211
|
+
* Knowingly an approximation otherwise:
|
|
212
|
+
* - Under-counts the first run in a project, which reports zero user servers because the
|
|
213
|
+
* copy is made in `beforeRun`, after `onSessionStart` has already sent the metric.
|
|
214
|
+
* Self-healing from the second run on.
|
|
215
|
+
* - Over-counts a server named in two scopes. The adapter merges those into one live
|
|
216
|
+
* server; `totalServers` sums the scopes, while `serverNames` stays deduplicated.
|
|
217
|
+
* - Under-counts every global file after the first that parses, the legacy
|
|
218
|
+
* `mcp-servers` alias key, and any config written as true JSONC — the adapter strips
|
|
219
|
+
* comments before parsing, `readJsonFile` does not.
|
|
220
|
+
* - Under-counts host-config imports (`hostConfigDiscovery: "on"`, or a per-file
|
|
221
|
+
* `"imports"` array), which pull servers from Claude/Codex/Cursor/VS Code files.
|
|
222
|
+
* Following a key into other files with other key names is beyond `navigateJsonPath`.
|
|
223
|
+
* Both mechanisms are opt-in and default off.
|
|
224
|
+
*
|
|
225
|
+
* Every one of those failures is silent: a wrong path and a genuinely MCP-less machine
|
|
226
|
+
* are indistinguishable in the summary.
|
|
227
|
+
*/
|
|
228
|
+
mcpConfig: {
|
|
229
|
+
local: {
|
|
230
|
+
path: '.pi/mcp.json',
|
|
231
|
+
jsonPath: 'mcpServers',
|
|
232
|
+
},
|
|
233
|
+
project: {
|
|
234
|
+
path: '.mcp.json',
|
|
235
|
+
jsonPath: 'mcpServers',
|
|
236
|
+
},
|
|
237
|
+
user: {
|
|
238
|
+
path: [
|
|
239
|
+
'.pi/codemie/agent/mcp.json',
|
|
240
|
+
'~/.agents/mcp/mcp.json',
|
|
241
|
+
'~/.agents/mcp.json',
|
|
242
|
+
'~/.config/mcp/mcp.json',
|
|
243
|
+
],
|
|
244
|
+
jsonPath: 'mcpServers',
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
envMapping: {
|
|
248
|
+
baseUrl: [],
|
|
249
|
+
apiKey: [],
|
|
250
|
+
model: [],
|
|
251
|
+
},
|
|
252
|
+
supportedProviders: ['ai-run-sso', 'bearer-auth', 'litellm'],
|
|
253
|
+
ssoConfig: {
|
|
254
|
+
enabled: true,
|
|
255
|
+
clientType: 'codemie-pi',
|
|
256
|
+
},
|
|
257
|
+
/**
|
|
258
|
+
* `--task` must become `-p`, not a bare positional. Pi treats a positional as an
|
|
259
|
+
* opening prompt for an *interactive* session, so the TUI takes over the terminal
|
|
260
|
+
* and the run never exits — while `-p` is Pi's "process the prompt and exit" mode
|
|
261
|
+
* and consumes the argument that follows it as the prompt.
|
|
262
|
+
*/
|
|
263
|
+
flagMappings: {
|
|
264
|
+
'--task': {
|
|
265
|
+
type: 'flag',
|
|
266
|
+
target: '-p',
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
lifecycle: {
|
|
270
|
+
async beforeRun(env, _config) {
|
|
271
|
+
const cwd = process.cwd();
|
|
272
|
+
await preparePiAgentDir(cwd);
|
|
273
|
+
await fetchAndBuildPiModels(env, cwd);
|
|
274
|
+
env.PI_CODING_AGENT_DIR = getPiAgentDir(cwd);
|
|
275
|
+
// Have Pi report which transcripts this run writes, instead of inferring them
|
|
276
|
+
// from the session directory after the fact. `preparePiAgentDir` skips the copy
|
|
277
|
+
// when the agent dir already exists, so this runs unconditionally to pick up
|
|
278
|
+
// asset changes after an upgrade.
|
|
279
|
+
const extension = await ensurePiCodeMieExtension(cwd, env);
|
|
280
|
+
if (extension.installed && env.CODEMIE_SESSION_ID) {
|
|
281
|
+
const ledgerPath = getPiRunLedgerPath(env.CODEMIE_SESSION_ID);
|
|
282
|
+
env[LEDGER_PATH_ENV] = ledgerPath;
|
|
283
|
+
process.env[LEDGER_PATH_ENV] = ledgerPath;
|
|
284
|
+
}
|
|
285
|
+
// Honor session-directory overrides early so both Pi and discovery agree.
|
|
286
|
+
const { sessionDir, isCustom } = resolvePiSessionDir(cwd, env);
|
|
287
|
+
if (isCustom) {
|
|
288
|
+
env.PI_CODING_AGENT_SESSION_DIR = sessionDir;
|
|
289
|
+
process.env.PI_CODING_AGENT_SESSION_DIR = sessionDir;
|
|
290
|
+
}
|
|
291
|
+
logger.debug('[pi] Configured PI_CODING_AGENT_DIR', { path: env.PI_CODING_AGENT_DIR });
|
|
292
|
+
return env;
|
|
293
|
+
},
|
|
294
|
+
enrichArgs(args, _config) {
|
|
295
|
+
const model = process.env.CODEMIE_MODEL;
|
|
296
|
+
if (!model) {
|
|
297
|
+
throw new Error('No model configured for codemie-pi. Run codemie setup to select a model.');
|
|
298
|
+
}
|
|
299
|
+
const classification = classifyPiModel(model);
|
|
300
|
+
const providerId = classification.provider;
|
|
301
|
+
// `--task` is not handled here: `flagMappings` rewrites it to Pi's `-p`, which
|
|
302
|
+
// BaseAgentAdapter applies after this hook. Consuming it here would leave a bare
|
|
303
|
+
// positional, and Pi treats a bare positional as an interactive opening prompt.
|
|
304
|
+
const result = ['--provider', providerId, '--model', model, ...args];
|
|
305
|
+
// Share CodeMie's session id with Pi so discovery can exact-match the
|
|
306
|
+
// transcript. Pi exits with code 1 if this is combined with a flag that
|
|
307
|
+
// already selects a session, so those runs correlate by run window instead.
|
|
308
|
+
const sessionId = process.env.CODEMIE_SESSION_ID;
|
|
309
|
+
if (sessionId && !result.includes('--session-id') && !hasSessionSelectionFlag(result)) {
|
|
310
|
+
result.push('--session-id', sessionId);
|
|
311
|
+
}
|
|
312
|
+
else if (sessionId) {
|
|
313
|
+
logger.debug('[pi] Skipping --session-id injection: argv already selects a session');
|
|
314
|
+
}
|
|
315
|
+
// Forward the effective session directory. beforeRun resolved it onto the run
|
|
316
|
+
// env, which BaseAgentAdapter has already merged into process.env. A
|
|
317
|
+
// user-supplied --session-dir is in argv already and takes precedence.
|
|
318
|
+
if (!result.includes('--session-dir') && process.env.PI_CODING_AGENT_SESSION_DIR) {
|
|
319
|
+
result.push('--session-dir', process.env.PI_CODING_AGENT_SESSION_DIR);
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
},
|
|
323
|
+
async onSessionStart(sessionId, env) {
|
|
324
|
+
try {
|
|
325
|
+
const { processEvent } = await import('../../../cli/commands/hook.js');
|
|
326
|
+
await processEvent({
|
|
327
|
+
hook_event_name: 'SessionStart',
|
|
328
|
+
session_id: sessionId,
|
|
329
|
+
transcript_path: '',
|
|
330
|
+
permission_mode: 'default',
|
|
331
|
+
cwd: process.cwd(),
|
|
332
|
+
source: 'startup',
|
|
333
|
+
}, buildPiHookConfig(env, sessionId));
|
|
334
|
+
logger.info(`[pi] SessionStart hook completed for session ${sessionId}`);
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
338
|
+
logger.error(`[pi] SessionStart hook failed (non-blocking): ${msg}`);
|
|
339
|
+
}
|
|
340
|
+
// A run killed with SIGKILL, or whose terminal was closed, never reaches onSessionEnd and
|
|
341
|
+
// leaves its record `active` forever with no terminal metric. Recover those on the next
|
|
342
|
+
// start. Fire-and-forget: a stranded earlier session must not delay this one.
|
|
343
|
+
void reconcileStaleSessions('pi', env, buildPiHookConfig).catch((error) => {
|
|
344
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
345
|
+
logger.debug(`[pi] Stale-session reconciliation failed (non-blocking): ${msg}`);
|
|
346
|
+
});
|
|
347
|
+
// Flush metrics during the run, so a hard kill loses at most one interval instead of the
|
|
348
|
+
// whole session. Ledger-driven: it processes exactly the transcripts the extension
|
|
349
|
+
// recorded, never a directory scan.
|
|
350
|
+
startPiIncrementalSync({
|
|
351
|
+
sessionId,
|
|
352
|
+
metadata: PiPluginMetadata,
|
|
353
|
+
buildContext: () => ({
|
|
354
|
+
sessionId,
|
|
355
|
+
apiBaseUrl: env.CODEMIE_SYNC_API_URL || env.CODEMIE_BASE_URL || '',
|
|
356
|
+
cookies: '',
|
|
357
|
+
clientType: 'codemie-pi',
|
|
358
|
+
version: env.CODEMIE_CLI_VERSION ?? '',
|
|
359
|
+
dryRun: false,
|
|
360
|
+
}),
|
|
361
|
+
ssoUrl: env.CODEMIE_URL,
|
|
362
|
+
syncApiUrl: env.CODEMIE_SYNC_API_URL ?? env.CODEMIE_BASE_URL,
|
|
363
|
+
cliVersion: env.CODEMIE_CLI_VERSION,
|
|
364
|
+
});
|
|
365
|
+
},
|
|
366
|
+
async onSessionEnd(exitCode, env) {
|
|
367
|
+
const sessionId = env.CODEMIE_SESSION_ID;
|
|
368
|
+
if (!sessionId) {
|
|
369
|
+
logger.debug('[pi] No CODEMIE_SESSION_ID in environment, skipping session end');
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
// Stop the mid-run flush FIRST, and wait for any tick already running: it appends to the
|
|
373
|
+
// same metrics JSONL this final flush is about to, and two writers that both read the
|
|
374
|
+
// existing record ids before either appends would upload every delta twice.
|
|
375
|
+
await stopPiIncrementalSync(sessionId);
|
|
376
|
+
// The extension recorded which transcripts this run wrote, from inside Pi.
|
|
377
|
+
// Nothing else is claimed: a transcript absent from the ledger belongs to
|
|
378
|
+
// another process, and uploading it would leak that session's prompts.
|
|
379
|
+
const ledger = await readPiRunLedger(sessionId);
|
|
380
|
+
// Slash commands never reach the transcript — Pi expands prompt templates into plain user
|
|
381
|
+
// text before persisting — so the ledger is their only record. Hand them to the adapter the
|
|
382
|
+
// hook pipeline will reach through the registry.
|
|
383
|
+
try {
|
|
384
|
+
const { AgentRegistry } = await import('../../registry.js');
|
|
385
|
+
const adapter = AgentRegistry.getAgent('pi')?.getSessionAdapter?.();
|
|
386
|
+
if (adapter instanceof PiSessionAdapter) {
|
|
387
|
+
adapter.setLedgerInvocations({
|
|
388
|
+
commandInvocations: ledger.commandInvocations,
|
|
389
|
+
skillCommandInvocations: ledger.skillCommandInvocations,
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
catch (error) {
|
|
394
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
395
|
+
logger.debug(`[pi] Could not attach ledger invocations (non-blocking): ${msg}`);
|
|
396
|
+
}
|
|
397
|
+
if (!ledger.loaded) {
|
|
398
|
+
logger.warn('[pi] The CodeMie run ledger is missing, so this run\'s transcripts cannot be '
|
|
399
|
+
+ 'identified. Reporting session lifecycle only — no tool metrics for this session.');
|
|
400
|
+
}
|
|
401
|
+
else if (ledger.transcripts.length === 0) {
|
|
402
|
+
logger.debug('[pi] Run produced no transcript (session ended before its first reply)');
|
|
403
|
+
}
|
|
404
|
+
await correlateRunToSession(sessionId, ledger);
|
|
405
|
+
const reason = env.CODEMIE_EXIT_SIGNAL
|
|
406
|
+
? `signal(${env.CODEMIE_EXIT_SIGNAL})`
|
|
407
|
+
: exitCode === 0
|
|
408
|
+
? 'exit'
|
|
409
|
+
: `exit(${exitCode})`;
|
|
410
|
+
try {
|
|
411
|
+
const { processEvent } = await import('../../../cli/commands/hook.js');
|
|
412
|
+
await processEvent({
|
|
413
|
+
hook_event_name: 'SessionEnd',
|
|
414
|
+
// Pi's own session id, so the backend joins on the agent's identity.
|
|
415
|
+
session_id: ledger.piSessionId ?? sessionId,
|
|
416
|
+
transcript_path: ledger.transcripts[0] ?? '',
|
|
417
|
+
transcript_paths: ledger.transcripts.length > 0 ? ledger.transcripts : undefined,
|
|
418
|
+
permission_mode: 'default',
|
|
419
|
+
// `--session <path>` runs the whole session under the transcript's cwd.
|
|
420
|
+
cwd: ledger.cwd ?? process.cwd(),
|
|
421
|
+
reason,
|
|
422
|
+
}, buildPiHookConfig(env, sessionId));
|
|
423
|
+
logger.info(`[pi] SessionEnd hook completed for session ${sessionId}`);
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
427
|
+
logger.error(`[pi] SessionEnd hook failed (non-blocking): ${msg}`);
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
export class PiPlugin extends BaseAgentAdapter {
|
|
433
|
+
sessionAdapter;
|
|
434
|
+
constructor() {
|
|
435
|
+
super(PiPluginMetadata);
|
|
436
|
+
this.sessionAdapter = new PiSessionAdapter(PiPluginMetadata);
|
|
437
|
+
}
|
|
438
|
+
getSessionAdapter() {
|
|
439
|
+
return this.sessionAdapter;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Translate CodeMie's session flags to Pi's and publish the argv-derived facts
|
|
443
|
+
* that `beforeRun` and `enrichArgs` need but cannot read from argv themselves.
|
|
444
|
+
*/
|
|
445
|
+
async run(args, envOverrides, runOptions) {
|
|
446
|
+
const prepared = preparePiInvocation(args, envOverrides);
|
|
447
|
+
return super.run(prepared.args, prepared.envOverrides, runOptions);
|
|
448
|
+
}
|
|
449
|
+
async additionalInstallation(_options) {
|
|
450
|
+
await installRequiredPiPackages({ cliCommand: this.metadata.cliCommand });
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
//# sourceMappingURL=pi.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.plugin.js","sourceRoot":"","sources":["../../../../src/agents/plugins/pi/pi.plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAElE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AC,KAAK,CAAC,+CAA+C,GAAG,EAAE,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;KACF;CACF,CAAC;AAEF,MAAM,OAAO,QAAS,SAAQ,gBAAgB;IACpC,cAAc,CAAiB;IAEvC;QACE,KAAK,CAAC,gBAAgB,CAAC,CAAC;QACxB,IAAI,CAAC,cAAc,GAAG,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;IAC/D,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CACP,IAAc,EACd,YAAqC,EACrC,UAAiC;QAEjC,MAAM,QAAQ,GAAG,mBAAmB,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QACzD,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,sBAAsB,CAC1B,QAAiE;QAEjE,MAAM,yBAAyB,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi Session Adapter
|
|
3
|
+
*
|
|
4
|
+
* Discovers and parses Pi JSONL session files, then runs the metrics processor.
|
|
5
|
+
*/
|
|
6
|
+
import type { SessionAdapter, ParsedSession, AggregatedResult, SessionDiscoveryOptions, SessionDescriptor } from '../../core/session/BaseSessionAdapter.js';
|
|
7
|
+
import type { SessionProcessor, ProcessingContext } from '../../core/session/BaseProcessor.js';
|
|
8
|
+
import type { AgentMetadata } from '../../core/types.js';
|
|
9
|
+
export interface PiDiscoveryOptions extends SessionDiscoveryOptions {
|
|
10
|
+
/** Environment variables used to resolve Pi session-directory overrides. */
|
|
11
|
+
env?: NodeJS.ProcessEnv;
|
|
12
|
+
}
|
|
13
|
+
/** One transcript linked to a parsed session, as {@link ParsedSession.subagents} carries it. */
|
|
14
|
+
type LinkedTranscript = NonNullable<ParsedSession['subagents']>[number];
|
|
15
|
+
/**
|
|
16
|
+
* `subagents[].agentType` for a nested sub-agent run: a delegated agent Pi ran under this
|
|
17
|
+
* transcript, stored at `<transcript-without-.jsonl>/<agentId>/run-N/session.jsonl`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const PI_SUBAGENT_RUN = "pi-subagent-run";
|
|
20
|
+
/**
|
|
21
|
+
* `subagents[].agentType` for a transcript that CONTINUED this one (`/fork`, `/branch`).
|
|
22
|
+
* Its inherited entries are byte-identical copies of this transcript's, ids included, so
|
|
23
|
+
* consumers must fold it in by entry identity rather than concatenating blindly.
|
|
24
|
+
*
|
|
25
|
+
* Never attached by this adapter — see {@link PiSessionAdapter.loadSubagentRuns} for why folding
|
|
26
|
+
* a fork family is the analytics layer's job. `native-loader.ts` attaches it.
|
|
27
|
+
*/
|
|
28
|
+
export declare const PI_FORKED_CONTINUATION = "pi-forked-continuation";
|
|
29
|
+
/** The transcripts that continued `parsed` via `/fork` or `/branch`, in discovery order. */
|
|
30
|
+
export declare function piForkedContinuations(parsed: ParsedSession): LinkedTranscript[];
|
|
31
|
+
import { type PiLedgerInvocations } from './session/processors/pi.metrics-processor.js';
|
|
32
|
+
export declare class PiSessionAdapter implements SessionAdapter {
|
|
33
|
+
private readonly metadata;
|
|
34
|
+
readonly agentName = "pi";
|
|
35
|
+
private processors;
|
|
36
|
+
constructor(metadata: AgentMetadata);
|
|
37
|
+
private initializeProcessors;
|
|
38
|
+
/**
|
|
39
|
+
* Supply the run-ledger counts the metrics processor cannot derive from a transcript.
|
|
40
|
+
*
|
|
41
|
+
* Pi expands a prompt template into plain user text before persisting it, so `/review` never
|
|
42
|
+
* appears in the JSONL — the only record of it is the ledger the CodeMie extension wrote
|
|
43
|
+
* (`pi.extension.ts`). The processing pipeline reaches this adapter through the registry
|
|
44
|
+
* singleton, and `ProcessingContext` is shared by every agent, so the counts are handed over
|
|
45
|
+
* here rather than threaded through a field only Pi would ever read.
|
|
46
|
+
*/
|
|
47
|
+
setLedgerInvocations(ledgerInvocations: PiLedgerInvocations | undefined): void;
|
|
48
|
+
registerProcessor(processor: SessionProcessor): void;
|
|
49
|
+
parseSessionFile(filePath: string, sessionId: string): Promise<ParsedSession>;
|
|
50
|
+
/**
|
|
51
|
+
* Nested sub-agent transcripts, stored under `<transcript-without-.jsonl>/<agentId>/run-N/`.
|
|
52
|
+
*
|
|
53
|
+
* A delegated agent gets its own session file there. The parent records tool results for those
|
|
54
|
+
* dispatches but NO usage on them (measured on a real corpus: 1707 `toolResult` entries, zero
|
|
55
|
+
* carrying `usage`), so every token a sub-agent burned lives only in the nested file and a
|
|
56
|
+
* reader that walks `messages` alone misses all of it.
|
|
57
|
+
*
|
|
58
|
+
* Attached WITHOUT a `toolUseId`: this is session-level spend, not the allocation of one
|
|
59
|
+
* dispatch, and `cost-enricher.enrichDispatchCosts` keys on `toolUseId` precisely so it skips
|
|
60
|
+
* these.
|
|
61
|
+
*
|
|
62
|
+
* **Forked continuations are deliberately NOT linked here.** `/fork` writes a new file that
|
|
63
|
+
* replays the prior conversation verbatim, so folding it into its source looks tempting — but
|
|
64
|
+
* `codemie pi --fork` is a second MANAGED run with a CodeMie session of its own, and the cost
|
|
65
|
+
* enricher walks sessions in `startTime` order against a shared `seen` set. Anything attached
|
|
66
|
+
* to the earlier session's transcript is consumed by the earlier session, so the forked run
|
|
67
|
+
* reports as free and its spend lands on the wrong session, date and branch. Collapsing a fork
|
|
68
|
+
* family is the analytics layer's job, where the set of sessions being reported is known;
|
|
69
|
+
* `native-loader.ts` does it for untracked runs.
|
|
70
|
+
*
|
|
71
|
+
* This is identity, not attribution: a directory Pi named after this transcript. Nothing here
|
|
72
|
+
* guesses ownership from mtime, id shape, or timing — see {@link discoverSessions}.
|
|
73
|
+
*/
|
|
74
|
+
private loadSubagentRuns;
|
|
75
|
+
private static readonly HEADER_READ_BYTES;
|
|
76
|
+
private readSessionHeader;
|
|
77
|
+
private readJsonlFile;
|
|
78
|
+
processSession(filePath: string, sessionId: string, context: ProcessingContext): Promise<AggregatedResult>;
|
|
79
|
+
/**
|
|
80
|
+
* Enumerate the Pi transcripts visible from this project.
|
|
81
|
+
*
|
|
82
|
+
* This is a plain listing, and deliberately so: it answers "which Pi transcripts
|
|
83
|
+
* exist here", never "which of them belong to the run that just finished".
|
|
84
|
+
*
|
|
85
|
+
* That second question cannot be answered from a directory. A concurrent `pi` — or
|
|
86
|
+
* a second CodeMie run in the same cwd — writes files indistinguishable from this
|
|
87
|
+
* run's by id, mtime, or `parentSession` lineage, and claiming one of them uploads
|
|
88
|
+
* a stranger's prompts and tool output under this user's session. Successive
|
|
89
|
+
* rounds of increasingly careful heuristics here were each shown to be reachable-
|
|
90
|
+
* wrong, so ownership is no longer inferred at all: the CodeMie extension records
|
|
91
|
+
* each transcript path from inside Pi, and `readPiRunLedger` reads it back.
|
|
92
|
+
*
|
|
93
|
+
* Scope follows the caller. With a `cwd`, the listing is that project's: the transcripts in
|
|
94
|
+
* that project's session directory whose own header declares that cwd — what a managed run
|
|
95
|
+
* needs. Without one, the listing is every project's, because that is what analytics needs:
|
|
96
|
+
* Claude and Codex discovery is global, so a cwd-scoped Pi would report zero usage whenever
|
|
97
|
+
* `codemie analytics` is run from anywhere but the project directory.
|
|
98
|
+
*
|
|
99
|
+
* @see pi.extension.ts
|
|
100
|
+
*/
|
|
101
|
+
discoverSessions(options?: SessionDiscoveryOptions): Promise<SessionDescriptor[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Every transcript in `sessionDir` recent enough to matter, optionally narrowed to one project.
|
|
104
|
+
*
|
|
105
|
+
* A session directory can be shared between projects (`--session-dir`, or a
|
|
106
|
+
* `sessionDir` in the project's `.pi/settings.json`), so when a `projectPath` is
|
|
107
|
+
* given each file's own header must declare that cwd. Filtering is on mtime rather
|
|
108
|
+
* than header timestamp so a long-running session is not dropped while it is still
|
|
109
|
+
* being written to.
|
|
110
|
+
*/
|
|
111
|
+
private listTranscripts;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=pi.session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.session.d.ts","sourceRoot":"","sources":["../../../../src/agents/plugins/pi/pi.session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC5J,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC/F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IACjE,4EAA4E;IAC5E,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AAED,gGAAgG;AAChG,KAAK,gBAAgB,GAAG,WAAW,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,2BAA2B,CAAC;AAE/D,4FAA4F;AAC5F,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,GAAG,gBAAgB,EAAE,CAE/E;AAiDD,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,8CAA8C,CAAC;AAItD,qBAAa,gBAAiB,YAAW,cAAc;IAIzC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAHrC,QAAQ,CAAC,SAAS,QAAQ;IAC1B,OAAO,CAAC,UAAU,CAA0B;gBAEf,QAAQ,EAAE,aAAa;IAIpD,OAAO,CAAC,oBAAoB;IAM5B;;;;;;;;OAQG;IACH,oBAAoB,CAAC,iBAAiB,EA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