cognitive-core 0.2.1 → 0.2.2
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/atlas.d.ts +10 -0
- package/dist/atlas.d.ts.map +1 -1
- package/dist/atlas.js +65 -0
- package/dist/atlas.js.map +1 -1
- package/dist/learning/pipeline.d.ts +4 -31
- package/dist/learning/pipeline.d.ts.map +1 -1
- package/dist/learning/pipeline.js +12 -64
- package/dist/learning/pipeline.js.map +1 -1
- package/dist/memory/curated-loader.d.ts +21 -4
- package/dist/memory/curated-loader.d.ts.map +1 -1
- package/dist/memory/curated-loader.js +53 -16
- package/dist/memory/curated-loader.js.map +1 -1
- package/dist/memory/index.d.ts +2 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +3 -1
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/playbook.d.ts +6 -0
- package/dist/memory/playbook.d.ts.map +1 -1
- package/dist/memory/playbook.js +15 -0
- package/dist/memory/playbook.js.map +1 -1
- package/dist/memory/source-resolver.d.ts +120 -0
- package/dist/memory/source-resolver.d.ts.map +1 -0
- package/dist/memory/source-resolver.js +300 -0
- package/dist/memory/source-resolver.js.map +1 -0
- package/dist/types/config.d.ts +141 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +40 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/workspace/types.d.ts +12 -54
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/types.js.map +1 -1
- package/package.json +2 -2
- package/playbooks/compound-engineering/adversarial-review.json +51 -0
- package/playbooks/compound-engineering/agent-native-architecture.json +59 -0
- package/playbooks/compound-engineering/agent-native-review.json +54 -0
- package/playbooks/compound-engineering/api-contract-review.json +52 -0
- package/playbooks/compound-engineering/brainstorm-requirements.json +55 -0
- package/playbooks/compound-engineering/bug-reproduction.json +62 -0
- package/playbooks/compound-engineering/confidence-calibration.json +49 -0
- package/playbooks/compound-engineering/correctness-review.json +49 -0
- package/playbooks/compound-engineering/data-migration-safety.json +59 -0
- package/playbooks/compound-engineering/deployment-verification.json +63 -0
- package/playbooks/compound-engineering/error-recovery-patterns.json +53 -0
- package/playbooks/compound-engineering/implementation-planning.json +64 -0
- package/playbooks/compound-engineering/issue-pattern-analysis.json +53 -0
- package/playbooks/compound-engineering/knowledge-compounding.json +63 -0
- package/playbooks/compound-engineering/learnings-research.json +54 -0
- package/playbooks/compound-engineering/maintainability-review.json +49 -0
- package/playbooks/compound-engineering/performance-review.json +54 -0
- package/playbooks/compound-engineering/plan-adversarial-review.json +56 -0
- package/playbooks/compound-engineering/plan-feasibility-review.json +56 -0
- package/playbooks/compound-engineering/project-standards-review.json +52 -0
- package/playbooks/compound-engineering/reliability-review.json +53 -0
- package/playbooks/compound-engineering/review-orchestration.json +64 -0
- package/playbooks/compound-engineering/security-review.json +54 -0
- package/playbooks/compound-engineering/systematic-execution.json +64 -0
- package/playbooks/compound-engineering/testing-review.json +50 -0
- package/src/atlas.ts +96 -0
- package/src/memory/curated-loader.ts +69 -16
- package/src/memory/index.ts +16 -0
- package/src/memory/playbook.ts +19 -0
- package/src/memory/source-resolver.ts +422 -0
- package/src/types/config.ts +46 -0
- package/src/types/index.ts +4 -0
- package/src/workspace/types.ts +22 -78
- package/tests/integration/curated-sources-e2e.test.ts +502 -0
- package/tests/memory/compound-engineering-seed.test.ts +338 -0
- package/tests/memory/curated-loader-extended.test.ts +225 -0
- package/tests/memory/playbook-quality-validation.test.ts +430 -0
- package/tests/memory/source-resolver.test.ts +700 -0
- package/.claude/settings.local.json +0 -11
- package/dist/learning/llm-extractor.d.ts +0 -88
- package/dist/learning/llm-extractor.d.ts.map +0 -1
- package/dist/learning/llm-extractor.js +0 -372
- package/dist/learning/llm-extractor.js.map +0 -1
- package/dist/learning/loop-coordinator.d.ts +0 -61
- package/dist/learning/loop-coordinator.d.ts.map +0 -1
- package/dist/learning/loop-coordinator.js +0 -96
- package/dist/learning/loop-coordinator.js.map +0 -1
- package/references/agent-workspace/CLAUDE.md +0 -74
- package/references/agent-workspace/README.md +0 -587
- package/references/agent-workspace/media/banner.png +0 -0
- package/references/agent-workspace/package-lock.json +0 -2061
- package/references/agent-workspace/package.json +0 -54
- package/references/agent-workspace/src/handle.ts +0 -122
- package/references/agent-workspace/src/index.ts +0 -32
- package/references/agent-workspace/src/manager.ts +0 -102
- package/references/agent-workspace/src/readers/json.ts +0 -71
- package/references/agent-workspace/src/readers/markdown.ts +0 -37
- package/references/agent-workspace/src/readers/raw.ts +0 -27
- package/references/agent-workspace/src/types.ts +0 -68
- package/references/agent-workspace/src/validation.ts +0 -93
- package/references/agent-workspace/src/writers/json.ts +0 -17
- package/references/agent-workspace/src/writers/markdown.ts +0 -27
- package/references/agent-workspace/src/writers/raw.ts +0 -22
- package/references/agent-workspace/tests/errors.test.ts +0 -652
- package/references/agent-workspace/tests/handle.test.ts +0 -144
- package/references/agent-workspace/tests/manager.test.ts +0 -124
- package/references/agent-workspace/tests/readers.test.ts +0 -205
- package/references/agent-workspace/tests/validation.test.ts +0 -196
- package/references/agent-workspace/tests/writers.test.ts +0 -108
- package/references/agent-workspace/tsconfig.json +0 -20
- package/references/agent-workspace/tsup.config.ts +0 -9
- package/references/minimem/.claude/settings.json +0 -7
- package/references/minimem/.sudocode/issues.jsonl +0 -18
- package/references/minimem/.sudocode/specs.jsonl +0 -1
- package/references/minimem/CLAUDE.md +0 -310
- package/references/minimem/README.md +0 -556
- package/references/minimem/claude-plugin/.claude-plugin/plugin.json +0 -10
- package/references/minimem/claude-plugin/.mcp.json +0 -7
- package/references/minimem/claude-plugin/README.md +0 -158
- package/references/minimem/claude-plugin/commands/recall.md +0 -47
- package/references/minimem/claude-plugin/commands/remember.md +0 -41
- package/references/minimem/claude-plugin/hooks/__tests__/hooks.test.ts +0 -272
- package/references/minimem/claude-plugin/hooks/hooks.json +0 -27
- package/references/minimem/claude-plugin/hooks/session-end.sh +0 -86
- package/references/minimem/claude-plugin/hooks/session-start.sh +0 -85
- package/references/minimem/claude-plugin/skills/memory/SKILL.md +0 -108
- package/references/minimem/package-lock.json +0 -5373
- package/references/minimem/package.json +0 -60
- package/references/minimem/scripts/postbuild.js +0 -35
- package/references/minimem/src/__tests__/edge-cases.test.ts +0 -371
- package/references/minimem/src/__tests__/errors.test.ts +0 -265
- package/references/minimem/src/__tests__/helpers.ts +0 -199
- package/references/minimem/src/__tests__/internal.test.ts +0 -407
- package/references/minimem/src/__tests__/knowledge.test.ts +0 -287
- package/references/minimem/src/__tests__/minimem.integration.test.ts +0 -1127
- package/references/minimem/src/__tests__/session.test.ts +0 -190
- package/references/minimem/src/cli/__tests__/commands.test.ts +0 -759
- package/references/minimem/src/cli/commands/__tests__/conflicts.test.ts +0 -141
- package/references/minimem/src/cli/commands/append.ts +0 -76
- package/references/minimem/src/cli/commands/config.ts +0 -262
- package/references/minimem/src/cli/commands/conflicts.ts +0 -413
- package/references/minimem/src/cli/commands/daemon.ts +0 -169
- package/references/minimem/src/cli/commands/index.ts +0 -12
- package/references/minimem/src/cli/commands/init.ts +0 -88
- package/references/minimem/src/cli/commands/mcp.ts +0 -177
- package/references/minimem/src/cli/commands/push-pull.ts +0 -213
- package/references/minimem/src/cli/commands/search.ts +0 -158
- package/references/minimem/src/cli/commands/status.ts +0 -84
- package/references/minimem/src/cli/commands/sync-init.ts +0 -290
- package/references/minimem/src/cli/commands/sync.ts +0 -70
- package/references/minimem/src/cli/commands/upsert.ts +0 -197
- package/references/minimem/src/cli/config.ts +0 -584
- package/references/minimem/src/cli/index.ts +0 -264
- package/references/minimem/src/cli/shared.ts +0 -161
- package/references/minimem/src/cli/sync/__tests__/central.test.ts +0 -152
- package/references/minimem/src/cli/sync/__tests__/conflicts.test.ts +0 -209
- package/references/minimem/src/cli/sync/__tests__/daemon.test.ts +0 -118
- package/references/minimem/src/cli/sync/__tests__/detection.test.ts +0 -207
- package/references/minimem/src/cli/sync/__tests__/integration.test.ts +0 -476
- package/references/minimem/src/cli/sync/__tests__/registry.test.ts +0 -363
- package/references/minimem/src/cli/sync/__tests__/state.test.ts +0 -255
- package/references/minimem/src/cli/sync/__tests__/validation.test.ts +0 -193
- package/references/minimem/src/cli/sync/__tests__/watcher.test.ts +0 -178
- package/references/minimem/src/cli/sync/central.ts +0 -292
- package/references/minimem/src/cli/sync/conflicts.ts +0 -204
- package/references/minimem/src/cli/sync/daemon.ts +0 -407
- package/references/minimem/src/cli/sync/detection.ts +0 -138
- package/references/minimem/src/cli/sync/index.ts +0 -107
- package/references/minimem/src/cli/sync/operations.ts +0 -373
- package/references/minimem/src/cli/sync/registry.ts +0 -279
- package/references/minimem/src/cli/sync/state.ts +0 -355
- package/references/minimem/src/cli/sync/validation.ts +0 -206
- package/references/minimem/src/cli/sync/watcher.ts +0 -234
- package/references/minimem/src/cli/version.ts +0 -34
- package/references/minimem/src/core/index.ts +0 -9
- package/references/minimem/src/core/indexer.ts +0 -628
- package/references/minimem/src/core/searcher.ts +0 -221
- package/references/minimem/src/db/schema.ts +0 -183
- package/references/minimem/src/db/sqlite-vec.ts +0 -24
- package/references/minimem/src/embeddings/__tests__/embeddings.test.ts +0 -431
- package/references/minimem/src/embeddings/batch-gemini.ts +0 -392
- package/references/minimem/src/embeddings/batch-openai.ts +0 -409
- package/references/minimem/src/embeddings/embeddings.ts +0 -434
- package/references/minimem/src/index.ts +0 -109
- package/references/minimem/src/internal.ts +0 -299
- package/references/minimem/src/minimem.ts +0 -1276
- package/references/minimem/src/search/__tests__/hybrid.test.ts +0 -247
- package/references/minimem/src/search/graph.ts +0 -234
- package/references/minimem/src/search/hybrid.ts +0 -151
- package/references/minimem/src/search/search.ts +0 -256
- package/references/minimem/src/server/__tests__/mcp.test.ts +0 -341
- package/references/minimem/src/server/__tests__/tools.test.ts +0 -364
- package/references/minimem/src/server/mcp.ts +0 -326
- package/references/minimem/src/server/tools.ts +0 -720
- package/references/minimem/src/session.ts +0 -460
- package/references/minimem/tsconfig.json +0 -19
- package/references/minimem/tsup.config.ts +0 -26
- package/references/minimem/vitest.config.ts +0 -24
- package/references/sessionlog/.husky/pre-commit +0 -1
- package/references/sessionlog/.lintstagedrc.json +0 -4
- package/references/sessionlog/.prettierignore +0 -4
- package/references/sessionlog/.prettierrc.json +0 -11
- package/references/sessionlog/LICENSE +0 -21
- package/references/sessionlog/README.md +0 -453
- package/references/sessionlog/eslint.config.js +0 -58
- package/references/sessionlog/package-lock.json +0 -3672
- package/references/sessionlog/package.json +0 -65
- package/references/sessionlog/src/__tests__/agent-hooks.test.ts +0 -570
- package/references/sessionlog/src/__tests__/agent-registry.test.ts +0 -127
- package/references/sessionlog/src/__tests__/claude-code-hooks.test.ts +0 -225
- package/references/sessionlog/src/__tests__/claude-generator.test.ts +0 -46
- package/references/sessionlog/src/__tests__/commit-msg.test.ts +0 -86
- package/references/sessionlog/src/__tests__/cursor-agent.test.ts +0 -224
- package/references/sessionlog/src/__tests__/e2e-live.test.ts +0 -890
- package/references/sessionlog/src/__tests__/event-log.test.ts +0 -183
- package/references/sessionlog/src/__tests__/flush-sentinel.test.ts +0 -105
- package/references/sessionlog/src/__tests__/gemini-agent.test.ts +0 -375
- package/references/sessionlog/src/__tests__/git-hooks.test.ts +0 -78
- package/references/sessionlog/src/__tests__/hook-managers.test.ts +0 -121
- package/references/sessionlog/src/__tests__/lifecycle-tasks.test.ts +0 -759
- package/references/sessionlog/src/__tests__/opencode-agent.test.ts +0 -338
- package/references/sessionlog/src/__tests__/redaction.test.ts +0 -136
- package/references/sessionlog/src/__tests__/session-repo.test.ts +0 -353
- package/references/sessionlog/src/__tests__/session-store.test.ts +0 -166
- package/references/sessionlog/src/__tests__/setup-ccweb.test.ts +0 -466
- package/references/sessionlog/src/__tests__/skill-live.test.ts +0 -461
- package/references/sessionlog/src/__tests__/summarize.test.ts +0 -348
- package/references/sessionlog/src/__tests__/task-plan-e2e.test.ts +0 -610
- package/references/sessionlog/src/__tests__/task-plan-live.test.ts +0 -632
- package/references/sessionlog/src/__tests__/transcript-timestamp.test.ts +0 -121
- package/references/sessionlog/src/__tests__/types.test.ts +0 -166
- package/references/sessionlog/src/__tests__/utils.test.ts +0 -333
- package/references/sessionlog/src/__tests__/validation.test.ts +0 -103
- package/references/sessionlog/src/__tests__/worktree.test.ts +0 -57
- package/references/sessionlog/src/agent/agents/claude-code.ts +0 -1089
- package/references/sessionlog/src/agent/agents/cursor.ts +0 -361
- package/references/sessionlog/src/agent/agents/gemini-cli.ts +0 -632
- package/references/sessionlog/src/agent/agents/opencode.ts +0 -540
- package/references/sessionlog/src/agent/registry.ts +0 -143
- package/references/sessionlog/src/agent/session-types.ts +0 -113
- package/references/sessionlog/src/agent/types.ts +0 -220
- package/references/sessionlog/src/cli.ts +0 -597
- package/references/sessionlog/src/commands/clean.ts +0 -133
- package/references/sessionlog/src/commands/disable.ts +0 -84
- package/references/sessionlog/src/commands/doctor.ts +0 -145
- package/references/sessionlog/src/commands/enable.ts +0 -202
- package/references/sessionlog/src/commands/explain.ts +0 -261
- package/references/sessionlog/src/commands/reset.ts +0 -105
- package/references/sessionlog/src/commands/resume.ts +0 -180
- package/references/sessionlog/src/commands/rewind.ts +0 -195
- package/references/sessionlog/src/commands/setup-ccweb.ts +0 -275
- package/references/sessionlog/src/commands/status.ts +0 -172
- package/references/sessionlog/src/config.ts +0 -165
- package/references/sessionlog/src/events/event-log.ts +0 -126
- package/references/sessionlog/src/git-operations.ts +0 -558
- package/references/sessionlog/src/hooks/git-hooks.ts +0 -165
- package/references/sessionlog/src/hooks/lifecycle.ts +0 -391
- package/references/sessionlog/src/index.ts +0 -650
- package/references/sessionlog/src/security/redaction.ts +0 -283
- package/references/sessionlog/src/session/state-machine.ts +0 -452
- package/references/sessionlog/src/store/checkpoint-store.ts +0 -509
- package/references/sessionlog/src/store/native-store.ts +0 -173
- package/references/sessionlog/src/store/provider-types.ts +0 -99
- package/references/sessionlog/src/store/session-store.ts +0 -266
- package/references/sessionlog/src/strategy/attribution.ts +0 -296
- package/references/sessionlog/src/strategy/common.ts +0 -207
- package/references/sessionlog/src/strategy/content-overlap.ts +0 -228
- package/references/sessionlog/src/strategy/manual-commit.ts +0 -988
- package/references/sessionlog/src/strategy/types.ts +0 -279
- package/references/sessionlog/src/summarize/claude-generator.ts +0 -115
- package/references/sessionlog/src/summarize/summarize.ts +0 -432
- package/references/sessionlog/src/types.ts +0 -508
- package/references/sessionlog/src/utils/chunk-files.ts +0 -49
- package/references/sessionlog/src/utils/commit-message.ts +0 -65
- package/references/sessionlog/src/utils/detect-agent.ts +0 -36
- package/references/sessionlog/src/utils/hook-managers.ts +0 -125
- package/references/sessionlog/src/utils/ide-tags.ts +0 -32
- package/references/sessionlog/src/utils/paths.ts +0 -79
- package/references/sessionlog/src/utils/preview-rewind.ts +0 -80
- package/references/sessionlog/src/utils/rewind-conflict.ts +0 -121
- package/references/sessionlog/src/utils/shadow-branch.ts +0 -109
- package/references/sessionlog/src/utils/string-utils.ts +0 -46
- package/references/sessionlog/src/utils/todo-extract.ts +0 -188
- package/references/sessionlog/src/utils/trailers.ts +0 -187
- package/references/sessionlog/src/utils/transcript-parse.ts +0 -177
- package/references/sessionlog/src/utils/transcript-timestamp.ts +0 -59
- package/references/sessionlog/src/utils/tree-ops.ts +0 -219
- package/references/sessionlog/src/utils/tty.ts +0 -72
- package/references/sessionlog/src/utils/validation.ts +0 -65
- package/references/sessionlog/src/utils/worktree.ts +0 -58
- package/references/sessionlog/src/wire-types.ts +0 -59
- package/references/sessionlog/templates/setup-env.sh +0 -153
- package/references/sessionlog/tsconfig.json +0 -18
- package/references/sessionlog/vitest.config.ts +0 -12
- package/references/skill-tree/.claude/settings.json +0 -6
- package/references/skill-tree/.sudocode/issues.jsonl +0 -19
- package/references/skill-tree/.sudocode/specs.jsonl +0 -3
- package/references/skill-tree/CLAUDE.md +0 -126
- package/references/skill-tree/README.md +0 -372
- package/references/skill-tree/docs/GAPS_v1.md +0 -221
- package/references/skill-tree/docs/INTEGRATION_PLAN.md +0 -467
- package/references/skill-tree/docs/TODOS.md +0 -91
- package/references/skill-tree/docs/anthropic_skill_guide.md +0 -1364
- package/references/skill-tree/docs/design/federated-skill-trees.md +0 -524
- package/references/skill-tree/docs/design/multi-agent-sync.md +0 -759
- package/references/skill-tree/docs/scraper/BRAINSTORM.md +0 -583
- package/references/skill-tree/docs/scraper/POC_PLAN.md +0 -420
- package/references/skill-tree/docs/scraper/README.md +0 -170
- package/references/skill-tree/examples/basic-usage.ts +0 -164
- package/references/skill-tree/package-lock.json +0 -1852
- package/references/skill-tree/package.json +0 -66
- package/references/skill-tree/scraper/README.md +0 -123
- package/references/skill-tree/scraper/docs/DESIGN.md +0 -683
- package/references/skill-tree/scraper/docs/PLAN.md +0 -336
- package/references/skill-tree/scraper/drizzle.config.ts +0 -10
- package/references/skill-tree/scraper/package-lock.json +0 -6329
- package/references/skill-tree/scraper/package.json +0 -68
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-description.md +0 -7
- package/references/skill-tree/scraper/test/fixtures/invalid-skill/missing-name.md +0 -7
- package/references/skill-tree/scraper/test/fixtures/minimal-skill/SKILL.md +0 -27
- package/references/skill-tree/scraper/test/fixtures/skill-json/SKILL.json +0 -21
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/SKILL.md +0 -54
- package/references/skill-tree/scraper/test/fixtures/skill-with-meta/_meta.json +0 -24
- package/references/skill-tree/scraper/test/fixtures/valid-skill/SKILL.md +0 -93
- package/references/skill-tree/scraper/test/fixtures/valid-skill/_meta.json +0 -22
- package/references/skill-tree/scraper/tsup.config.ts +0 -14
- package/references/skill-tree/scraper/vitest.config.ts +0 -17
- package/references/skill-tree/scripts/convert-to-vitest.ts +0 -166
- package/references/skill-tree/skills/skill-writer/SKILL.md +0 -339
- package/references/skill-tree/skills/skill-writer/references/examples.md +0 -326
- package/references/skill-tree/skills/skill-writer/references/patterns.md +0 -210
- package/references/skill-tree/skills/skill-writer/references/quality-checklist.md +0 -123
- package/references/skill-tree/test/run-all.ts +0 -106
- package/references/skill-tree/test/utils.ts +0 -128
- package/references/skill-tree/vitest.config.ts +0 -16
|
@@ -1,632 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gemini CLI Agent
|
|
3
|
-
*
|
|
4
|
-
* Implementation of the Sessionlog agent interface for Google's Gemini CLI.
|
|
5
|
-
* Handles JSON transcript format with messages array, Gemini-specific
|
|
6
|
-
* hook installation, and session lifecycle management.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import * as fs from 'node:fs';
|
|
10
|
-
import * as path from 'node:path';
|
|
11
|
-
import * as os from 'node:os';
|
|
12
|
-
import * as crypto from 'node:crypto';
|
|
13
|
-
import {
|
|
14
|
-
AGENT_NAMES,
|
|
15
|
-
AGENT_TYPES,
|
|
16
|
-
type HookInput,
|
|
17
|
-
type Event,
|
|
18
|
-
type TokenUsage,
|
|
19
|
-
EventType,
|
|
20
|
-
emptyTokenUsage,
|
|
21
|
-
} from '../../types.js';
|
|
22
|
-
import type {
|
|
23
|
-
Agent,
|
|
24
|
-
HookSupport,
|
|
25
|
-
TranscriptAnalyzer,
|
|
26
|
-
TokenCalculator,
|
|
27
|
-
TranscriptChunker,
|
|
28
|
-
} from '../types.js';
|
|
29
|
-
import { registerAgent } from '../registry.js';
|
|
30
|
-
|
|
31
|
-
// ============================================================================
|
|
32
|
-
// Constants
|
|
33
|
-
// ============================================================================
|
|
34
|
-
|
|
35
|
-
const GEMINI_DIR = '.gemini';
|
|
36
|
-
const SETTINGS_FILE_NAME = 'settings.json';
|
|
37
|
-
|
|
38
|
-
const HOOK_NAMES = [
|
|
39
|
-
'session-start',
|
|
40
|
-
'session-end',
|
|
41
|
-
'before-agent',
|
|
42
|
-
'after-agent',
|
|
43
|
-
'before-model',
|
|
44
|
-
'after-model',
|
|
45
|
-
'before-tool-selection',
|
|
46
|
-
'before-tool',
|
|
47
|
-
'after-tool',
|
|
48
|
-
'pre-compress',
|
|
49
|
-
'notification',
|
|
50
|
-
] as const;
|
|
51
|
-
|
|
52
|
-
const SESSIONLOG_HOOK_PREFIX = 'sessionlog ';
|
|
53
|
-
|
|
54
|
-
/** Tools that modify files in Gemini CLI */
|
|
55
|
-
const FILE_MODIFICATION_TOOLS = new Set(['write_file', 'edit_file', 'save_file', 'replace']);
|
|
56
|
-
|
|
57
|
-
// ============================================================================
|
|
58
|
-
// Gemini Transcript Types (JSON)
|
|
59
|
-
// ============================================================================
|
|
60
|
-
|
|
61
|
-
export interface GeminiTranscript {
|
|
62
|
-
messages: GeminiMessage[];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export interface GeminiMessage {
|
|
66
|
-
id?: string;
|
|
67
|
-
type: string;
|
|
68
|
-
content: string;
|
|
69
|
-
toolCalls?: GeminiToolCall[];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export interface GeminiToolCall {
|
|
73
|
-
id: string;
|
|
74
|
-
name: string;
|
|
75
|
-
args: Record<string, unknown>;
|
|
76
|
-
status?: string;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ============================================================================
|
|
80
|
-
// Gemini Settings Types
|
|
81
|
-
// ============================================================================
|
|
82
|
-
|
|
83
|
-
interface GeminiHookEntry {
|
|
84
|
-
name: string;
|
|
85
|
-
type: string;
|
|
86
|
-
command: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
interface GeminiHookMatcher {
|
|
90
|
-
matcher?: string;
|
|
91
|
-
hooks: GeminiHookEntry[];
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ============================================================================
|
|
95
|
-
// Gemini CLI Agent Implementation
|
|
96
|
-
// ============================================================================
|
|
97
|
-
|
|
98
|
-
class GeminiCLIAgent
|
|
99
|
-
implements Agent, HookSupport, TranscriptAnalyzer, TokenCalculator, TranscriptChunker
|
|
100
|
-
{
|
|
101
|
-
readonly name = AGENT_NAMES.GEMINI;
|
|
102
|
-
readonly type = AGENT_TYPES.GEMINI;
|
|
103
|
-
readonly description = "Gemini CLI - Google's AI coding assistant";
|
|
104
|
-
readonly isPreview = true;
|
|
105
|
-
readonly protectedDirs = [GEMINI_DIR];
|
|
106
|
-
|
|
107
|
-
async detectPresence(cwd?: string): Promise<boolean> {
|
|
108
|
-
const repoRoot = cwd ?? process.cwd();
|
|
109
|
-
const geminiDir = path.join(repoRoot, GEMINI_DIR);
|
|
110
|
-
try {
|
|
111
|
-
const stat = await fs.promises.stat(geminiDir);
|
|
112
|
-
return stat.isDirectory();
|
|
113
|
-
} catch {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async getSessionDir(repoPath: string): Promise<string> {
|
|
119
|
-
if (process.env.SESSIONLOG_TEST_GEMINI_PROJECT_DIR) {
|
|
120
|
-
return process.env.SESSIONLOG_TEST_GEMINI_PROJECT_DIR;
|
|
121
|
-
}
|
|
122
|
-
const projectDir = getProjectHash(repoPath);
|
|
123
|
-
return path.join(os.homedir(), '.gemini', 'tmp', projectDir, 'chats');
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
getSessionID(input: HookInput): string {
|
|
127
|
-
return input.sessionID;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
resolveSessionFile(sessionDir: string, agentSessionID: string): string {
|
|
131
|
-
// Gemini names files as session-<date>-<shortid>.json
|
|
132
|
-
const shortID = agentSessionID.length > 8 ? agentSessionID.slice(0, 8) : agentSessionID;
|
|
133
|
-
|
|
134
|
-
// Try to find existing file
|
|
135
|
-
try {
|
|
136
|
-
const files = fs.readdirSync(sessionDir);
|
|
137
|
-
const pattern = `session-.*-${shortID}\\.json`;
|
|
138
|
-
const regex = new RegExp(pattern);
|
|
139
|
-
const matches = files.filter((f) => regex.test(f)).sort();
|
|
140
|
-
if (matches.length > 0) {
|
|
141
|
-
return path.join(sessionDir, matches[matches.length - 1]);
|
|
142
|
-
}
|
|
143
|
-
} catch {
|
|
144
|
-
// Directory doesn't exist yet
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Fallback: construct filename matching Gemini's convention
|
|
148
|
-
const timestamp = new Date().toISOString().slice(0, 16).replace(/:/g, '-');
|
|
149
|
-
return path.join(sessionDir, `session-${timestamp}-${shortID}.json`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
async readTranscript(sessionRef: string): Promise<Buffer> {
|
|
153
|
-
return fs.promises.readFile(sessionRef);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
formatResumeCommand(sessionID: string): string {
|
|
157
|
-
return `gemini --resume ${sessionID}`;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// ===========================================================================
|
|
161
|
-
// HookSupport
|
|
162
|
-
// ===========================================================================
|
|
163
|
-
|
|
164
|
-
hookNames(): string[] {
|
|
165
|
-
return [...HOOK_NAMES];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
parseHookEvent(hookName: string, stdin: string): Event | null {
|
|
169
|
-
try {
|
|
170
|
-
const data = JSON.parse(stdin) as Record<string, unknown>;
|
|
171
|
-
|
|
172
|
-
const sessionID = String(data.session_id ?? data.sessionID ?? '');
|
|
173
|
-
const sessionRef = String(data.transcript_path ?? data.transcriptPath ?? '');
|
|
174
|
-
|
|
175
|
-
switch (hookName) {
|
|
176
|
-
case 'session-start':
|
|
177
|
-
return {
|
|
178
|
-
type: EventType.SessionStart,
|
|
179
|
-
sessionID,
|
|
180
|
-
sessionRef,
|
|
181
|
-
timestamp: new Date(),
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
case 'before-agent':
|
|
185
|
-
return {
|
|
186
|
-
type: EventType.TurnStart,
|
|
187
|
-
sessionID,
|
|
188
|
-
sessionRef,
|
|
189
|
-
prompt: String(data.prompt ?? ''),
|
|
190
|
-
timestamp: new Date(),
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
case 'after-agent':
|
|
194
|
-
return {
|
|
195
|
-
type: EventType.TurnEnd,
|
|
196
|
-
sessionID,
|
|
197
|
-
sessionRef,
|
|
198
|
-
timestamp: new Date(),
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
case 'session-end':
|
|
202
|
-
return {
|
|
203
|
-
type: EventType.SessionEnd,
|
|
204
|
-
sessionID,
|
|
205
|
-
sessionRef,
|
|
206
|
-
timestamp: new Date(),
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
case 'pre-compress':
|
|
210
|
-
return {
|
|
211
|
-
type: EventType.Compaction,
|
|
212
|
-
sessionID,
|
|
213
|
-
sessionRef,
|
|
214
|
-
timestamp: new Date(),
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
// Pass-through hooks with no lifecycle action
|
|
218
|
-
case 'before-tool':
|
|
219
|
-
case 'after-tool':
|
|
220
|
-
case 'before-model':
|
|
221
|
-
case 'after-model':
|
|
222
|
-
case 'before-tool-selection':
|
|
223
|
-
case 'notification':
|
|
224
|
-
return null;
|
|
225
|
-
|
|
226
|
-
default:
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
} catch {
|
|
230
|
-
return null;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async installHooks(repoPath: string, force = false): Promise<number> {
|
|
235
|
-
const settingsPath = path.join(repoPath, GEMINI_DIR, SETTINGS_FILE_NAME);
|
|
236
|
-
let rawSettings: Record<string, unknown> = {};
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
const content = await fs.promises.readFile(settingsPath, 'utf-8');
|
|
240
|
-
rawSettings = JSON.parse(content) as Record<string, unknown>;
|
|
241
|
-
} catch {
|
|
242
|
-
// No existing settings
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Ensure hooksConfig.enabled is true
|
|
246
|
-
const hooksConfig = (rawSettings.hooksConfig ?? {}) as Record<string, unknown>;
|
|
247
|
-
hooksConfig.enabled = true;
|
|
248
|
-
rawSettings.hooksConfig = hooksConfig;
|
|
249
|
-
|
|
250
|
-
const hooks = (rawSettings.hooks ?? {}) as Record<string, GeminiHookMatcher[]>;
|
|
251
|
-
|
|
252
|
-
const hookDefs = [
|
|
253
|
-
{
|
|
254
|
-
key: 'SessionStart',
|
|
255
|
-
hookName: 'session-start',
|
|
256
|
-
matcher: '',
|
|
257
|
-
name: 'sessionlog-session-start',
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
key: 'SessionEnd',
|
|
261
|
-
hookName: 'session-end',
|
|
262
|
-
matcher: 'exit',
|
|
263
|
-
name: 'sessionlog-session-end-exit',
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
key: 'SessionEnd',
|
|
267
|
-
hookName: 'session-end',
|
|
268
|
-
matcher: 'logout',
|
|
269
|
-
name: 'sessionlog-session-end-logout',
|
|
270
|
-
},
|
|
271
|
-
{
|
|
272
|
-
key: 'BeforeAgent',
|
|
273
|
-
hookName: 'before-agent',
|
|
274
|
-
matcher: '',
|
|
275
|
-
name: 'sessionlog-before-agent',
|
|
276
|
-
},
|
|
277
|
-
{ key: 'AfterAgent', hookName: 'after-agent', matcher: '', name: 'sessionlog-after-agent' },
|
|
278
|
-
{
|
|
279
|
-
key: 'BeforeModel',
|
|
280
|
-
hookName: 'before-model',
|
|
281
|
-
matcher: '',
|
|
282
|
-
name: 'sessionlog-before-model',
|
|
283
|
-
},
|
|
284
|
-
{ key: 'AfterModel', hookName: 'after-model', matcher: '', name: 'sessionlog-after-model' },
|
|
285
|
-
{
|
|
286
|
-
key: 'BeforeToolSelection',
|
|
287
|
-
hookName: 'before-tool-selection',
|
|
288
|
-
matcher: '',
|
|
289
|
-
name: 'sessionlog-before-tool-selection',
|
|
290
|
-
},
|
|
291
|
-
{ key: 'BeforeTool', hookName: 'before-tool', matcher: '*', name: 'sessionlog-before-tool' },
|
|
292
|
-
{ key: 'AfterTool', hookName: 'after-tool', matcher: '*', name: 'sessionlog-after-tool' },
|
|
293
|
-
{
|
|
294
|
-
key: 'PreCompress',
|
|
295
|
-
hookName: 'pre-compress',
|
|
296
|
-
matcher: '',
|
|
297
|
-
name: 'sessionlog-pre-compress',
|
|
298
|
-
},
|
|
299
|
-
{
|
|
300
|
-
key: 'Notification',
|
|
301
|
-
hookName: 'notification',
|
|
302
|
-
matcher: '',
|
|
303
|
-
name: 'sessionlog-notification',
|
|
304
|
-
},
|
|
305
|
-
];
|
|
306
|
-
|
|
307
|
-
// If not force, check idempotency
|
|
308
|
-
if (!force) {
|
|
309
|
-
const sessionStartMatchers = hooks['SessionStart'] ?? [];
|
|
310
|
-
for (const m of sessionStartMatchers) {
|
|
311
|
-
for (const h of m.hooks) {
|
|
312
|
-
if (h.command === `sessionlog hooks gemini session-start`) {
|
|
313
|
-
return 0; // Already installed
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// Remove existing sessionlog hooks
|
|
320
|
-
for (const key of Object.keys(hooks)) {
|
|
321
|
-
hooks[key] = removeSessionlogGeminiHooks(hooks[key] ?? []);
|
|
322
|
-
if (hooks[key].length === 0) delete hooks[key];
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Install all hooks
|
|
326
|
-
for (const def of hookDefs) {
|
|
327
|
-
const matchers = hooks[def.key] ?? [];
|
|
328
|
-
const cmd = `sessionlog hooks gemini ${def.hookName}`;
|
|
329
|
-
const entry: GeminiHookEntry = { name: def.name, type: 'command', command: cmd };
|
|
330
|
-
|
|
331
|
-
// Find or create matcher
|
|
332
|
-
let found = false;
|
|
333
|
-
for (const m of matchers) {
|
|
334
|
-
if ((m.matcher ?? '') === def.matcher) {
|
|
335
|
-
m.hooks.push(entry);
|
|
336
|
-
found = true;
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
if (!found) {
|
|
341
|
-
const newMatcher: GeminiHookMatcher = { hooks: [entry] };
|
|
342
|
-
if (def.matcher) newMatcher.matcher = def.matcher;
|
|
343
|
-
matchers.push(newMatcher);
|
|
344
|
-
}
|
|
345
|
-
hooks[def.key] = matchers;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
rawSettings.hooks = hooks;
|
|
349
|
-
|
|
350
|
-
const dir = path.dirname(settingsPath);
|
|
351
|
-
await fs.promises.mkdir(dir, { recursive: true });
|
|
352
|
-
await fs.promises.writeFile(settingsPath, JSON.stringify(rawSettings, null, 2));
|
|
353
|
-
|
|
354
|
-
return 12; // Total hooks installed
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
async uninstallHooks(repoPath: string): Promise<void> {
|
|
358
|
-
const settingsPath = path.join(repoPath, GEMINI_DIR, SETTINGS_FILE_NAME);
|
|
359
|
-
|
|
360
|
-
try {
|
|
361
|
-
const content = await fs.promises.readFile(settingsPath, 'utf-8');
|
|
362
|
-
const rawSettings = JSON.parse(content) as Record<string, unknown>;
|
|
363
|
-
const hooks = (rawSettings.hooks ?? {}) as Record<string, GeminiHookMatcher[]>;
|
|
364
|
-
|
|
365
|
-
for (const key of Object.keys(hooks)) {
|
|
366
|
-
hooks[key] = removeSessionlogGeminiHooks(hooks[key] ?? []);
|
|
367
|
-
if (hooks[key].length === 0) delete hooks[key];
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
if (Object.keys(hooks).length === 0) {
|
|
371
|
-
delete rawSettings.hooks;
|
|
372
|
-
} else {
|
|
373
|
-
rawSettings.hooks = hooks;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
await fs.promises.writeFile(settingsPath, JSON.stringify(rawSettings, null, 2));
|
|
377
|
-
} catch {
|
|
378
|
-
// No file to modify
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
async areHooksInstalled(repoPath: string): Promise<boolean> {
|
|
383
|
-
const settingsPath = path.join(repoPath, GEMINI_DIR, SETTINGS_FILE_NAME);
|
|
384
|
-
|
|
385
|
-
try {
|
|
386
|
-
const content = await fs.promises.readFile(settingsPath, 'utf-8');
|
|
387
|
-
const rawSettings = JSON.parse(content) as Record<string, unknown>;
|
|
388
|
-
const hooks = (rawSettings.hooks ?? {}) as Record<string, GeminiHookMatcher[]>;
|
|
389
|
-
|
|
390
|
-
for (const key of Object.keys(hooks)) {
|
|
391
|
-
for (const m of hooks[key] ?? []) {
|
|
392
|
-
for (const h of m.hooks) {
|
|
393
|
-
if (h.command.startsWith(SESSIONLOG_HOOK_PREFIX)) return true;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
} catch {
|
|
398
|
-
// No file
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
return false;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// ===========================================================================
|
|
405
|
-
// TranscriptAnalyzer
|
|
406
|
-
// ===========================================================================
|
|
407
|
-
|
|
408
|
-
async getTranscriptPosition(transcriptPath: string): Promise<number> {
|
|
409
|
-
try {
|
|
410
|
-
const data = await fs.promises.readFile(transcriptPath, 'utf-8');
|
|
411
|
-
const transcript = JSON.parse(data) as GeminiTranscript;
|
|
412
|
-
return transcript.messages?.length ?? 0;
|
|
413
|
-
} catch {
|
|
414
|
-
return 0;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
async extractModifiedFilesFromOffset(
|
|
419
|
-
transcriptPath: string,
|
|
420
|
-
startOffset: number,
|
|
421
|
-
): Promise<{ files: string[]; currentPosition: number }> {
|
|
422
|
-
const data = await fs.promises.readFile(transcriptPath, 'utf-8');
|
|
423
|
-
const transcript = parseGeminiTranscript(data);
|
|
424
|
-
const files = new Set<string>();
|
|
425
|
-
|
|
426
|
-
for (let i = startOffset; i < transcript.messages.length; i++) {
|
|
427
|
-
const msg = transcript.messages[i];
|
|
428
|
-
if (msg.type !== 'gemini') continue;
|
|
429
|
-
|
|
430
|
-
for (const tc of msg.toolCalls ?? []) {
|
|
431
|
-
if (!FILE_MODIFICATION_TOOLS.has(tc.name)) continue;
|
|
432
|
-
const filePath = extractGeminiFilePath(tc.args);
|
|
433
|
-
if (filePath) files.add(filePath);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
return { files: Array.from(files), currentPosition: transcript.messages.length };
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
async extractPrompts(sessionRef: string, fromOffset: number): Promise<string[]> {
|
|
441
|
-
const data = await fs.promises.readFile(sessionRef, 'utf-8');
|
|
442
|
-
const transcript = parseGeminiTranscript(data);
|
|
443
|
-
const prompts: string[] = [];
|
|
444
|
-
|
|
445
|
-
for (let i = fromOffset; i < transcript.messages.length; i++) {
|
|
446
|
-
const msg = transcript.messages[i];
|
|
447
|
-
if (msg.type === 'user' && msg.content) {
|
|
448
|
-
prompts.push(msg.content);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return prompts;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
async extractSummary(sessionRef: string): Promise<string> {
|
|
456
|
-
const data = await fs.promises.readFile(sessionRef, 'utf-8');
|
|
457
|
-
const transcript = parseGeminiTranscript(data);
|
|
458
|
-
|
|
459
|
-
for (let i = transcript.messages.length - 1; i >= 0; i--) {
|
|
460
|
-
if (transcript.messages[i].type === 'gemini' && transcript.messages[i].content) {
|
|
461
|
-
return transcript.messages[i].content;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return '';
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// ===========================================================================
|
|
469
|
-
// TokenCalculator
|
|
470
|
-
// ===========================================================================
|
|
471
|
-
|
|
472
|
-
async calculateTokenUsage(transcriptData: Buffer, fromOffset: number): Promise<TokenUsage> {
|
|
473
|
-
const data = transcriptData.toString('utf-8');
|
|
474
|
-
const usage = emptyTokenUsage();
|
|
475
|
-
|
|
476
|
-
try {
|
|
477
|
-
const parsed = JSON.parse(data) as {
|
|
478
|
-
messages: Array<{
|
|
479
|
-
type: string;
|
|
480
|
-
tokens?: { input: number; output: number; cached: number };
|
|
481
|
-
}>;
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
for (let i = fromOffset; i < parsed.messages.length; i++) {
|
|
485
|
-
const msg = parsed.messages[i];
|
|
486
|
-
if (msg.type !== 'gemini' || !msg.tokens) continue;
|
|
487
|
-
|
|
488
|
-
usage.apiCallCount++;
|
|
489
|
-
usage.inputTokens += msg.tokens.input ?? 0;
|
|
490
|
-
usage.outputTokens += msg.tokens.output ?? 0;
|
|
491
|
-
usage.cacheReadTokens += msg.tokens.cached ?? 0;
|
|
492
|
-
}
|
|
493
|
-
} catch {
|
|
494
|
-
// Invalid transcript data
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
return usage;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// ===========================================================================
|
|
501
|
-
// TranscriptChunker
|
|
502
|
-
// ===========================================================================
|
|
503
|
-
|
|
504
|
-
async chunkTranscript(content: Buffer, maxSize: number): Promise<Buffer[]> {
|
|
505
|
-
try {
|
|
506
|
-
const transcript = JSON.parse(content.toString('utf-8')) as GeminiTranscript;
|
|
507
|
-
if (!transcript.messages?.length) return [content];
|
|
508
|
-
|
|
509
|
-
const chunks: Buffer[] = [];
|
|
510
|
-
let currentMessages: GeminiMessage[] = [];
|
|
511
|
-
const baseSize = Buffer.byteLength('{"messages":[]}');
|
|
512
|
-
let currentSize = baseSize;
|
|
513
|
-
|
|
514
|
-
for (const msg of transcript.messages) {
|
|
515
|
-
const msgBytes = Buffer.byteLength(JSON.stringify(msg));
|
|
516
|
-
const msgSize = msgBytes + 1; // +1 for comma
|
|
517
|
-
|
|
518
|
-
if (currentSize + msgSize > maxSize && currentMessages.length > 0) {
|
|
519
|
-
chunks.push(Buffer.from(JSON.stringify({ messages: currentMessages })));
|
|
520
|
-
currentMessages = [];
|
|
521
|
-
currentSize = baseSize;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
currentMessages.push(msg);
|
|
525
|
-
currentSize += msgSize;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (currentMessages.length > 0) {
|
|
529
|
-
chunks.push(Buffer.from(JSON.stringify({ messages: currentMessages })));
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
return chunks.length > 0 ? chunks : [content];
|
|
533
|
-
} catch {
|
|
534
|
-
// Fall back to raw content
|
|
535
|
-
return [content];
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
async reassembleTranscript(chunks: Buffer[]): Promise<Buffer> {
|
|
540
|
-
const allMessages: GeminiMessage[] = [];
|
|
541
|
-
|
|
542
|
-
for (const chunk of chunks) {
|
|
543
|
-
const transcript = JSON.parse(chunk.toString('utf-8')) as GeminiTranscript;
|
|
544
|
-
allMessages.push(...(transcript.messages ?? []));
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
return Buffer.from(JSON.stringify({ messages: allMessages }));
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
// ============================================================================
|
|
552
|
-
// Helpers
|
|
553
|
-
// ============================================================================
|
|
554
|
-
|
|
555
|
-
function getProjectHash(projectRoot: string): string {
|
|
556
|
-
return crypto.createHash('sha256').update(projectRoot).digest('hex');
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
function removeSessionlogGeminiHooks(matchers: GeminiHookMatcher[]): GeminiHookMatcher[] {
|
|
560
|
-
const result: GeminiHookMatcher[] = [];
|
|
561
|
-
for (const m of matchers) {
|
|
562
|
-
const filteredHooks = m.hooks.filter((h) => !h.command.startsWith(SESSIONLOG_HOOK_PREFIX));
|
|
563
|
-
if (filteredHooks.length > 0) {
|
|
564
|
-
result.push({ ...m, hooks: filteredHooks });
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return result;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function extractGeminiFilePath(args: Record<string, unknown>): string {
|
|
571
|
-
if (typeof args.file_path === 'string' && args.file_path) return args.file_path;
|
|
572
|
-
if (typeof args.path === 'string' && args.path) return args.path;
|
|
573
|
-
if (typeof args.filename === 'string' && args.filename) return args.filename;
|
|
574
|
-
return '';
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
* Parse Gemini JSON transcript, handling both string and array content formats.
|
|
579
|
-
*/
|
|
580
|
-
function parseGeminiTranscript(data: string): GeminiTranscript {
|
|
581
|
-
const raw = JSON.parse(data) as { messages: Array<Record<string, unknown>> };
|
|
582
|
-
const messages: GeminiMessage[] = [];
|
|
583
|
-
|
|
584
|
-
for (const rawMsg of raw.messages ?? []) {
|
|
585
|
-
const msg: GeminiMessage = {
|
|
586
|
-
id: rawMsg.id as string | undefined,
|
|
587
|
-
type: rawMsg.type as string,
|
|
588
|
-
content: '',
|
|
589
|
-
toolCalls: rawMsg.toolCalls as GeminiToolCall[] | undefined,
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
// Handle both string and array content formats
|
|
593
|
-
const content = rawMsg.content;
|
|
594
|
-
if (typeof content === 'string') {
|
|
595
|
-
msg.content = content;
|
|
596
|
-
} else if (Array.isArray(content)) {
|
|
597
|
-
const texts: string[] = [];
|
|
598
|
-
for (const part of content) {
|
|
599
|
-
if (
|
|
600
|
-
part &&
|
|
601
|
-
typeof part === 'object' &&
|
|
602
|
-
typeof (part as Record<string, unknown>).text === 'string'
|
|
603
|
-
) {
|
|
604
|
-
texts.push((part as Record<string, unknown>).text as string);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
msg.content = texts.join('\n');
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
messages.push(msg);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return { messages };
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// ============================================================================
|
|
617
|
-
// Exported Helpers (for summarize module)
|
|
618
|
-
// ============================================================================
|
|
619
|
-
|
|
620
|
-
export { parseGeminiTranscript, FILE_MODIFICATION_TOOLS as GEMINI_FILE_MODIFICATION_TOOLS };
|
|
621
|
-
|
|
622
|
-
export type { GeminiTranscript as ParsedGeminiTranscript };
|
|
623
|
-
|
|
624
|
-
// ============================================================================
|
|
625
|
-
// Registration
|
|
626
|
-
// ============================================================================
|
|
627
|
-
|
|
628
|
-
export function createGeminiCLIAgent(): GeminiCLIAgent {
|
|
629
|
-
return new GeminiCLIAgent();
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
registerAgent(AGENT_NAMES.GEMINI, () => new GeminiCLIAgent());
|