@memorax/memorax-code 0.1.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/LICENSE +21 -0
- package/README.md +53 -0
- package/bin/memorax-cli.mjs +28 -0
- package/bin/memorax-code-backend.mjs +4 -0
- package/bin/memorax-code-claude.mjs +4 -0
- package/bin/memorax-code-codex.mjs +4 -0
- package/bin/memorax-code-npm-preinstall.mjs +55 -0
- package/bin/memorax-code-plugin-postinstall.mjs +1236 -0
- package/bin/memorax-code.mjs +204 -0
- package/docs/configuration.md +232 -0
- package/docs/troubleshooting.md +179 -0
- package/lib/client-hook-runtime.mjs +32 -0
- package/lib/memorax-code-adapter-common/src/backend-connection.d.mts +111 -0
- package/lib/memorax-code-adapter-common/src/backend-connection.mjs +304 -0
- package/lib/memorax-code-adapter-common/src/clients/claude-command.mjs +38 -0
- package/lib/memorax-code-adapter-common/src/clients/codex-command.mjs +41 -0
- package/lib/memorax-code-adapter-common/src/clients/codex-plugin-artifact.d.mts +3 -0
- package/lib/memorax-code-adapter-common/src/clients/codex-plugin-artifact.mjs +38 -0
- package/lib/memorax-code-adapter-common/src/config-utils.d.mts +27 -0
- package/lib/memorax-code-adapter-common/src/config-utils.mjs +391 -0
- package/lib/memorax-code-adapter-common/src/hooks/capture-cwd-hook.mjs +137 -0
- package/lib/memorax-code-adapter-common/src/hooks/client-hook-launcher.mjs +324 -0
- package/lib/memorax-code-adapter-common/src/hooks/ensure-backend-runner.mjs +142 -0
- package/lib/memorax-code-adapter-common/src/hooks/hook-runtime-generation.d.mts +38 -0
- package/lib/memorax-code-adapter-common/src/hooks/hook-runtime-generation.mjs +501 -0
- package/lib/memorax-code-adapter-common/src/hooks/memory-skill-reminder-hook.mjs +277 -0
- package/lib/memorax-code-adapter-common/src/memorax-code-config-file.d.mts +28 -0
- package/lib/memorax-code-adapter-common/src/memorax-code-config-file.mjs +296 -0
- package/lib/memorax-code-adapter-common/src/memorax-defaults.d.mts +10 -0
- package/lib/memorax-code-adapter-common/src/memorax-defaults.mjs +12 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-memory-job-context.mjs +28 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-memory-job-marker.mjs +252 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-memory-job-supervisor.mjs +559 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-memory-job-worker.mjs +411 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-memory-update-policy-evaluator.mjs +185 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-memory-update-policy.mjs +165 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-procedure-memory-context.mjs +181 -0
- package/lib/memorax-code-adapter-common/src/repo-memory/repo-user-profile-context.mjs +251 -0
- package/lib/memorax-code-adapter-common/src/runtime-record.d.mts +55 -0
- package/lib/memorax-code-adapter-common/src/runtime-record.mjs +152 -0
- package/lib/memorax-code-adapter-common/src/windows-cli-invocation.mjs +100 -0
- package/lib/memorax-code-backend/dist/active-client-selection.js +35 -0
- package/lib/memorax-code-backend/dist/adapter-lifecycle-participant.js +1 -0
- package/lib/memorax-code-backend/dist/automatic-memory-retrieval.js +113 -0
- package/lib/memorax-code-backend/dist/automatic-memory-writeback.js +297 -0
- package/lib/memorax-code-backend/dist/backend-env.js +13 -0
- package/lib/memorax-code-backend/dist/backend-lifecycle-lock.js +42 -0
- package/lib/memorax-code-backend/dist/backend-process.js +147 -0
- package/lib/memorax-code-backend/dist/backend-service-cleanup.js +18 -0
- package/lib/memorax-code-backend/dist/backend-service-record.js +206 -0
- package/lib/memorax-code-backend/dist/backend-service-result.js +37 -0
- package/lib/memorax-code-backend/dist/backend-service-token.js +11 -0
- package/lib/memorax-code-backend/dist/backend-shutdown-request.js +133 -0
- package/lib/memorax-code-backend/dist/backend-state.js +58 -0
- package/lib/memorax-code-backend/dist/backend-status.js +53 -0
- package/lib/memorax-code-backend/dist/backend-token-record.js +79 -0
- package/lib/memorax-code-backend/dist/claude-adapter-lifecycle.js +134 -0
- package/lib/memorax-code-backend/dist/claude-local-transcript.js +648 -0
- package/lib/memorax-code-backend/dist/claude-memory-hook-runtime.js +472 -0
- package/lib/memorax-code-backend/dist/claude-transcript-turn.js +876 -0
- package/lib/memorax-code-backend/dist/client-plugin-removal.js +67 -0
- package/lib/memorax-code-backend/dist/client-selection.js +36 -0
- package/lib/memorax-code-backend/dist/codex-adapter-lifecycle.js +131 -0
- package/lib/memorax-code-backend/dist/codex-effective-prompt.js +54 -0
- package/lib/memorax-code-backend/dist/codex-memory-hook-runtime.js +541 -0
- package/lib/memorax-code-backend/dist/codex-plugin-hooks.js +421 -0
- package/lib/memorax-code-backend/dist/codex-plugin-install.js +523 -0
- package/lib/memorax-code-backend/dist/codex-rollout-turn.js +402 -0
- package/lib/memorax-code-backend/dist/codex-session-turn-index.js +88 -0
- package/lib/memorax-code-backend/dist/codex-workspace-links.js +55 -0
- package/lib/memorax-code-backend/dist/debug-log.js +21 -0
- package/lib/memorax-code-backend/dist/entrypoint.js +14 -0
- package/lib/memorax-code-backend/dist/incremental-jsonl-projection.js +271 -0
- package/lib/memorax-code-backend/dist/install-watchdog.js +71 -0
- package/lib/memorax-code-backend/dist/jsonl-append.js +75 -0
- package/lib/memorax-code-backend/dist/memorax-adapter.js +451 -0
- package/lib/memorax-code-backend/dist/memorax-cli.js +14 -0
- package/lib/memorax-code-backend/dist/memorax-code-config.js +279 -0
- package/lib/memorax-code-backend/dist/memorax-code-lifecycle.js +523 -0
- package/lib/memorax-code-backend/dist/memorax-code.js +3 -0
- package/lib/memorax-code-backend/dist/memorax-config.js +283 -0
- package/lib/memorax-code-backend/dist/memorax-http.js +142 -0
- package/lib/memorax-code-backend/dist/memory-cli.js +345 -0
- package/lib/memorax-code-backend/dist/memory-hook-command.js +200 -0
- package/lib/memorax-code-backend/dist/memory-observability.js +1 -0
- package/lib/memorax-code-backend/dist/memory-project.js +89 -0
- package/lib/memorax-code-backend/dist/memory-reminder-trace-recorder.js +58 -0
- package/lib/memorax-code-backend/dist/memory-service.js +66 -0
- package/lib/memorax-code-backend/dist/memory-turn-coordinator.js +139 -0
- package/lib/memorax-code-backend/dist/memory-viewer-activity.js +113 -0
- package/lib/memorax-code-backend/dist/memory-viewer-data-projection-cache.js +69 -0
- package/lib/memorax-code-backend/dist/memory-viewer-event-identity.js +3 -0
- package/lib/memorax-code-backend/dist/memory-viewer-history-projection.js +79 -0
- package/lib/memorax-code-backend/dist/memory-viewer-logo.js +1 -0
- package/lib/memorax-code-backend/dist/memory-viewer-observability.js +8 -0
- package/lib/memorax-code-backend/dist/memory-viewer-redaction.js +52 -0
- package/lib/memorax-code-backend/dist/memory-viewer-session-title.js +93 -0
- package/lib/memorax-code-backend/dist/memory-viewer-store.js +964 -0
- package/lib/memorax-code-backend/dist/memory-viewer-turn-reference.js +12 -0
- package/lib/memorax-code-backend/dist/memory-viewer-user-html.js +115 -0
- package/lib/memorax-code-backend/dist/memory-viewer-user-projection.js +168 -0
- package/lib/memorax-code-backend/dist/memory-viewer-writeback-status.js +97 -0
- package/lib/memorax-code-backend/dist/memory-writeback-buffer.js +217 -0
- package/lib/memorax-code-backend/dist/memory-writeback-chunk.js +120 -0
- package/lib/memorax-code-backend/dist/memory-writeback-reconciler.js +244 -0
- package/lib/memorax-code-backend/dist/memory-writeback-task-projection.js +377 -0
- package/lib/memorax-code-backend/dist/proxy-env.js +54 -0
- package/lib/memorax-code-backend/dist/repo-memory-readiness.js +188 -0
- package/lib/memorax-code-backend/dist/repository-memory-context.js +134 -0
- package/lib/memorax-code-backend/dist/repository-memory-scope.js +490 -0
- package/lib/memorax-code-backend/dist/server-cli.js +787 -0
- package/lib/memorax-code-backend/dist/server-health.js +16 -0
- package/lib/memorax-code-backend/dist/server-http.js +110 -0
- package/lib/memorax-code-backend/dist/server-json.js +4 -0
- package/lib/memorax-code-backend/dist/server-memory-hook.js +32 -0
- package/lib/memorax-code-backend/dist/server-memory-viewer.js +135 -0
- package/lib/memorax-code-backend/dist/server-observability.js +102 -0
- package/lib/memorax-code-backend/dist/server.js +220 -0
- package/lib/memorax-code-backend/dist/service-entrypoint.js +10 -0
- package/lib/memorax-code-backend/dist/service.js +567 -0
- package/lib/memorax-code-backend/dist/trace-config.js +112 -0
- package/lib/memorax-code-backend/dist/trace-context.js +111 -0
- package/lib/memorax-code-backend/dist/trace-store.js +571 -0
- package/lib/memorax-code-backend/dist/utils.js +3 -0
- package/lib/memorax-code-backend/dist/windows-cli-invocation.js +148 -0
- package/lib/memorax-code-backend/package.json +26 -0
- package/lib/memorax-code-claude-adapter/.claude-plugin/plugin.json +15 -0
- package/lib/memorax-code-claude-adapter/hooks/hook-launcher.mjs +27 -0
- package/lib/memorax-code-claude-adapter/hooks/hooks.json +66 -0
- package/lib/memorax-code-claude-adapter/hooks/repo-memory-job.mjs +37 -0
- package/lib/memorax-code-claude-adapter/hooks/runtime-hook.mjs +4 -0
- package/lib/memorax-code-claude-adapter/hooks/runtime-shell.json +5 -0
- package/lib/memorax-code-claude-adapter/package.json +13 -0
- package/lib/memorax-code-claude-adapter/runtime-hooks/capture-cwd.mjs +17 -0
- package/lib/memorax-code-claude-adapter/runtime-hooks/ensure-backend.mjs +59 -0
- package/lib/memorax-code-claude-adapter/runtime-hooks/memory-cli-session.mjs +33 -0
- package/lib/memorax-code-claude-adapter/runtime-hooks/memory-skill-reminder.mjs +73 -0
- package/lib/memorax-code-claude-adapter/runtime-hooks/memory-turn.mjs +91 -0
- package/lib/memorax-code-claude-adapter/scripts/build-marketplace.mjs +99 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/SKILL.md +83 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/agents/claude.yaml +10 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/agents/openai.yaml +7 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/defaults.json +9 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/memorax-add.md +82 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/memorax-search.md +61 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/personal-read.md +46 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/personal-write.md +100 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/repo-build.md +270 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/repo-read.md +96 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/repo-templates.md +270 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/references/repo-update.md +116 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/collect_all.py +496 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/detect_updates.py +856 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/git_commit_facets.py +222 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/github_resource_facets.py +504 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/gitlab_resource_facets.py +509 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/prepare_repo_memory.py +411 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/user_profile_memory.py +528 -0
- package/lib/memorax-code-claude-adapter/skills/memorax-code/scripts/validate_memory.py +226 -0
- package/lib/memorax-code-claude-adapter/src/adapter-paths.mjs +46 -0
- package/lib/memorax-code-claude-adapter/src/cli.mjs +363 -0
- package/lib/memorax-code-claude-adapter/src/config-utils.mjs +1 -0
- package/lib/memorax-code-claude-adapter/src/config.mjs +544 -0
- package/lib/memorax-code-claude-adapter/src/plugin-artifact-contract.mjs +148 -0
- package/lib/memorax-code-claude-adapter/src/plugin-install.mjs +566 -0
- package/lib/memorax-code-claude-marketplace/.claude-plugin/marketplace.json +15 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/.claude-plugin/plugin.json +15 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/hooks/hook-launcher.mjs +27 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/hooks/hooks.json +66 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/hooks/repo-memory-job.mjs +37 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/hooks/runtime-hook.mjs +4 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/hooks/runtime-shell.json +5 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/backend-connection.d.mts +111 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/backend-connection.mjs +304 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/clients/claude-command.mjs +38 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/clients/codex-command.mjs +41 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/clients/codex-plugin-artifact.d.mts +3 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/clients/codex-plugin-artifact.mjs +38 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/config-utils.d.mts +27 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/config-utils.mjs +391 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/hooks/capture-cwd-hook.mjs +137 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/hooks/client-hook-launcher.mjs +324 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/hooks/ensure-backend-runner.mjs +142 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/hooks/hook-runtime-generation.d.mts +38 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/hooks/hook-runtime-generation.mjs +501 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/hooks/memory-skill-reminder-hook.mjs +277 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/memorax-code-config-file.d.mts +28 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/memorax-code-config-file.mjs +296 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/memorax-defaults.d.mts +10 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/memorax-defaults.mjs +12 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-memory-job-context.mjs +28 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-memory-job-marker.mjs +252 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-memory-job-supervisor.mjs +559 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-memory-job-worker.mjs +411 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-memory-update-policy-evaluator.mjs +185 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-memory-update-policy.mjs +165 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-procedure-memory-context.mjs +181 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/repo-memory/repo-user-profile-context.mjs +251 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/runtime-record.d.mts +55 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/runtime-record.mjs +152 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/memorax-code-adapter-common/src/windows-cli-invocation.mjs +100 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/package.json +13 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/runtime-hooks/capture-cwd.mjs +17 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/runtime-hooks/ensure-backend.mjs +59 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/runtime-hooks/memory-cli-session.mjs +33 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/runtime-hooks/memory-skill-reminder.mjs +73 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/runtime-hooks/memory-turn.mjs +91 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/scripts/build-marketplace.mjs +99 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/SKILL.md +83 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/agents/claude.yaml +10 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/agents/openai.yaml +7 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/defaults.json +9 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/memorax-add.md +82 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/memorax-search.md +61 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/personal-read.md +46 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/personal-write.md +100 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/repo-build.md +270 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/repo-read.md +96 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/repo-templates.md +270 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/references/repo-update.md +116 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/collect_all.py +496 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/detect_updates.py +856 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/git_commit_facets.py +222 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/github_resource_facets.py +504 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/gitlab_resource_facets.py +509 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/prepare_repo_memory.py +411 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/user_profile_memory.py +528 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/skills/memorax-code/scripts/validate_memory.py +226 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/src/adapter-paths.mjs +46 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/src/cli.mjs +363 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/src/config-utils.mjs +1 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/src/config.mjs +544 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/src/plugin-artifact-contract.mjs +148 -0
- package/lib/memorax-code-claude-marketplace/plugins/memorax-code-claude-adapter/src/plugin-install.mjs +566 -0
- package/lib/memorax-code-codex-adapter/.codex-plugin/plugin.json +33 -0
- package/lib/memorax-code-codex-adapter/assets/composer-icon.png +0 -0
- package/lib/memorax-code-codex-adapter/assets/logo.png +0 -0
- package/lib/memorax-code-codex-adapter/hooks/hook-launcher.mjs +26 -0
- package/lib/memorax-code-codex-adapter/hooks/hooks.json +61 -0
- package/lib/memorax-code-codex-adapter/hooks/repo-memory-job.mjs +38 -0
- package/lib/memorax-code-codex-adapter/hooks/repo-memory-update-policy.mjs +10 -0
- package/lib/memorax-code-codex-adapter/hooks/runtime-hook.mjs +4 -0
- package/lib/memorax-code-codex-adapter/hooks/runtime-shell.json +5 -0
- package/lib/memorax-code-codex-adapter/package.json +13 -0
- package/lib/memorax-code-codex-adapter/runtime-hooks/capture-cwd.mjs +18 -0
- package/lib/memorax-code-codex-adapter/runtime-hooks/ensure-backend.mjs +82 -0
- package/lib/memorax-code-codex-adapter/runtime-hooks/memory-skill-reminder.mjs +125 -0
- package/lib/memorax-code-codex-adapter/runtime-hooks/memory-writeback.mjs +52 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/SKILL.md +83 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/agents/claude.yaml +10 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/agents/openai.yaml +7 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/defaults.json +9 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/memorax-add.md +82 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/memorax-search.md +61 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/personal-read.md +46 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/personal-write.md +100 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/repo-build.md +270 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/repo-read.md +96 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/repo-templates.md +270 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/references/repo-update.md +116 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/collect_all.py +496 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/detect_updates.py +856 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/git_commit_facets.py +222 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/github_resource_facets.py +504 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/gitlab_resource_facets.py +509 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/prepare_repo_memory.py +411 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/user_profile_memory.py +528 -0
- package/lib/memorax-code-codex-adapter/skills/memorax-code/scripts/validate_memory.py +226 -0
- package/lib/memorax-code-codex-adapter/src/adapter-paths.mjs +29 -0
- package/lib/memorax-code-codex-adapter/src/cli.mjs +368 -0
- package/lib/memorax-code-codex-adapter/src/config-utils.mjs +1 -0
- package/lib/memorax-code-codex-adapter/src/config.mjs +226 -0
- package/lib/memorax-code-codex-adapter/src/session-registry.mjs +331 -0
- package/lib/memorax-code-codex-adapter/src/workspace-kind.mjs +68 -0
- package/lib/node-version.mjs +11 -0
- package/lib/npm-invocation.mjs +31 -0
- package/lib/resolve-claude-command.mjs +47 -0
- package/lib/resolve-codex-command.mjs +94 -0
- package/lib/run-entrypoint.mjs +83 -0
- package/lib/vscode-extension-command.mjs +119 -0
- package/lib/windows-cli-invocation.mjs +100 -0
- package/package.json +45 -0
|
@@ -0,0 +1,876 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
export async function readClaudeTranscriptTurn(input) {
|
|
3
|
+
let transcript;
|
|
4
|
+
try {
|
|
5
|
+
transcript = await readFile(input.transcriptPath, "utf8");
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
return {
|
|
9
|
+
ok: false,
|
|
10
|
+
reason: "transcript_unavailable",
|
|
11
|
+
error: error instanceof Error ? error.message : String(error),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return claudeTranscriptTurnFromJsonLines(transcript, input);
|
|
15
|
+
}
|
|
16
|
+
export async function readClaudeInterruptedTranscriptTurn(input) {
|
|
17
|
+
let transcript;
|
|
18
|
+
try {
|
|
19
|
+
transcript = await readFile(input.transcriptPath, "utf8");
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return {
|
|
23
|
+
ok: false,
|
|
24
|
+
reason: "transcript_unavailable",
|
|
25
|
+
error: error instanceof Error ? error.message : String(error),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return claudeInterruptedTranscriptTurnFromJsonLines(transcript, input);
|
|
29
|
+
}
|
|
30
|
+
export function claudeTranscriptTurnFromJsonLines(transcript, input) {
|
|
31
|
+
const requested = requestedTranscriptRecords(transcript, input.sessionId);
|
|
32
|
+
if (!requested.ok)
|
|
33
|
+
return requested;
|
|
34
|
+
const records = requested.records;
|
|
35
|
+
const promptRecords = records.filter((record) => (promptIdFromRecord(record) === input.promptId && isInteractiveUserRecord(record)));
|
|
36
|
+
if (promptRecords.length === 0)
|
|
37
|
+
return { ok: false, reason: "turn_not_found" };
|
|
38
|
+
const sessionTurnIndex = interactivePromptIndex(records, input.promptId);
|
|
39
|
+
const recordsByUuid = indexRecordsByUuid(records);
|
|
40
|
+
const candidates = [];
|
|
41
|
+
let ambiguousBranch = false;
|
|
42
|
+
for (const record of records) {
|
|
43
|
+
if (!isCompletedAssistantRecord(record))
|
|
44
|
+
continue;
|
|
45
|
+
const assistantReply = completedAssistantReply(record);
|
|
46
|
+
const branch = promptBranch(record, recordsByUuid);
|
|
47
|
+
if (branch.ambiguous) {
|
|
48
|
+
ambiguousBranch = true;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (branch.promptId === input.promptId && branch.userPrompt) {
|
|
52
|
+
const usage = aggregateClaudeUsage(branch.assistantMessages);
|
|
53
|
+
candidates.push({
|
|
54
|
+
branch,
|
|
55
|
+
userPrompt: branch.userPrompt,
|
|
56
|
+
...(assistantReply ? { assistantReply } : {}),
|
|
57
|
+
activities: claudeMemoryActivities(branch.assistantMessages),
|
|
58
|
+
...(usage ? { usage } : {}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const terminalCandidates = maximalTerminalLineages(candidates);
|
|
63
|
+
if (ambiguousBranch || terminalCandidates.length > 1) {
|
|
64
|
+
return { ok: false, reason: "turn_ambiguous" };
|
|
65
|
+
}
|
|
66
|
+
const candidate = terminalCandidates[0];
|
|
67
|
+
if (candidate?.assistantReply && sessionTurnIndex !== undefined) {
|
|
68
|
+
return {
|
|
69
|
+
ok: true,
|
|
70
|
+
turn: {
|
|
71
|
+
sessionId: input.sessionId,
|
|
72
|
+
promptId: input.promptId,
|
|
73
|
+
sessionTurnIndex,
|
|
74
|
+
userPrompt: candidate.userPrompt,
|
|
75
|
+
assistantReply: candidate.assistantReply,
|
|
76
|
+
activities: candidate.activities,
|
|
77
|
+
...(candidate.usage ? { usage: candidate.usage } : {}),
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (!promptRecords.some((record) => visibleUserPrompt(record))) {
|
|
82
|
+
return { ok: false, reason: "user_prompt_missing" };
|
|
83
|
+
}
|
|
84
|
+
return { ok: false, reason: "assistant_message_missing" };
|
|
85
|
+
}
|
|
86
|
+
export function claudeInterruptedTranscriptTurnFromJsonLines(transcript, input) {
|
|
87
|
+
const requested = requestedTranscriptRecords(transcript, input.sessionId);
|
|
88
|
+
if (!requested.ok)
|
|
89
|
+
return requested;
|
|
90
|
+
const records = requested.records;
|
|
91
|
+
const promptRecords = records.filter((record) => (promptIdFromRecord(record) === input.promptId && isInteractiveUserRecord(record)));
|
|
92
|
+
if (promptRecords.length === 0)
|
|
93
|
+
return { ok: false, reason: "turn_not_found" };
|
|
94
|
+
const sessionTurnIndex = interactivePromptIndex(records, input.promptId);
|
|
95
|
+
const recordsByUuid = indexRecordsByUuid(records);
|
|
96
|
+
const candidates = [];
|
|
97
|
+
let ambiguousBranch = false;
|
|
98
|
+
for (const record of records) {
|
|
99
|
+
if (!interruptionMarker(record))
|
|
100
|
+
continue;
|
|
101
|
+
const prompt = promptOnBranch(record, recordsByUuid, input.promptId);
|
|
102
|
+
if (prompt.ambiguous) {
|
|
103
|
+
ambiguousBranch = true;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (!prompt.userPrompt || !prompt.assistantMessages)
|
|
107
|
+
continue;
|
|
108
|
+
if (prompt.assistantMessages.some((message) => message.stop_reason === "end_turn"))
|
|
109
|
+
continue;
|
|
110
|
+
const usage = aggregateClaudeUsage(prompt.assistantMessages);
|
|
111
|
+
const interruptedAt = transcriptRecordTimestamp(record);
|
|
112
|
+
candidates.push({
|
|
113
|
+
userPrompt: prompt.userPrompt,
|
|
114
|
+
assistantReply: interruptedAssistantReply(prompt.assistantMessages),
|
|
115
|
+
activities: claudeMemoryActivities(prompt.assistantMessages),
|
|
116
|
+
...(usage ? { usage } : {}),
|
|
117
|
+
...(interruptedAt ? { interruptedAt } : {}),
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (ambiguousBranch || candidates.length > 1) {
|
|
121
|
+
return { ok: false, reason: "turn_ambiguous" };
|
|
122
|
+
}
|
|
123
|
+
const candidate = candidates[0];
|
|
124
|
+
if (candidate && sessionTurnIndex !== undefined) {
|
|
125
|
+
return {
|
|
126
|
+
ok: true,
|
|
127
|
+
turn: {
|
|
128
|
+
sessionId: input.sessionId,
|
|
129
|
+
promptId: input.promptId,
|
|
130
|
+
sessionTurnIndex,
|
|
131
|
+
...candidate,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
if (!promptRecords.some((record) => visibleUserPrompt(record))) {
|
|
136
|
+
return { ok: false, reason: "user_prompt_missing" };
|
|
137
|
+
}
|
|
138
|
+
return { ok: false, reason: "turn_not_interrupted" };
|
|
139
|
+
}
|
|
140
|
+
export function claudeTranscriptMemoryActivitiesFromJsonLines(transcript, input) {
|
|
141
|
+
const requested = requestedTranscriptRecords(transcript, input.sessionId);
|
|
142
|
+
if (!requested.ok)
|
|
143
|
+
return [];
|
|
144
|
+
const records = requested.records;
|
|
145
|
+
const recordsByUuid = indexRecordsByUuid(records);
|
|
146
|
+
const terminals = new Map();
|
|
147
|
+
const interrupted = new Map();
|
|
148
|
+
for (const record of records) {
|
|
149
|
+
if (isMemoryActivityTerminalAssistantRecord(record)) {
|
|
150
|
+
const branch = promptBranch(record, recordsByUuid);
|
|
151
|
+
if (!branch.ambiguous && branch.promptId && branch.userPrompt) {
|
|
152
|
+
const candidates = terminals.get(branch.promptId) ?? [];
|
|
153
|
+
candidates.push(branch);
|
|
154
|
+
terminals.set(branch.promptId, candidates);
|
|
155
|
+
}
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (!interruptionMarker(record))
|
|
159
|
+
continue;
|
|
160
|
+
const branch = promptBranch(record, recordsByUuid);
|
|
161
|
+
if (branch.ambiguous
|
|
162
|
+
|| !branch.promptId
|
|
163
|
+
|| !branch.userPrompt
|
|
164
|
+
|| branch.assistantMessages.some((message) => message.stop_reason === "end_turn")) {
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const candidates = interrupted.get(branch.promptId) ?? [];
|
|
168
|
+
candidates.push(branch);
|
|
169
|
+
interrupted.set(branch.promptId, candidates);
|
|
170
|
+
}
|
|
171
|
+
const activities = [];
|
|
172
|
+
const promptIds = new Set([...terminals.keys(), ...interrupted.keys()]);
|
|
173
|
+
for (const promptId of promptIds) {
|
|
174
|
+
const terminalBranches = maximalTerminalLineages((terminals.get(promptId) ?? []).map((branch) => ({ branch }))).map((candidate) => candidate.branch);
|
|
175
|
+
const interruptedBranches = interrupted.get(promptId) ?? [];
|
|
176
|
+
const branch = terminalBranches.length === 1
|
|
177
|
+
? terminalBranches[0]
|
|
178
|
+
: terminalBranches.length === 0 && interruptedBranches.length === 1
|
|
179
|
+
? interruptedBranches[0]
|
|
180
|
+
: undefined;
|
|
181
|
+
if (!branch)
|
|
182
|
+
continue;
|
|
183
|
+
activities.push(...claudeMemoryActivityDetails(promptId, branch, input.includeAuthority === true));
|
|
184
|
+
}
|
|
185
|
+
return activities;
|
|
186
|
+
}
|
|
187
|
+
function requestedTranscriptRecords(transcript, sessionId) {
|
|
188
|
+
const parsed = transcriptRecords(transcript);
|
|
189
|
+
if (!parsed.ok) {
|
|
190
|
+
return {
|
|
191
|
+
ok: false,
|
|
192
|
+
reason: "transcript_unavailable",
|
|
193
|
+
error: "Claude transcript contains an invalid completed JSONL record.",
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const records = requestedSessionRecords(parsed.records, sessionId);
|
|
197
|
+
return records
|
|
198
|
+
? { ok: true, records }
|
|
199
|
+
: { ok: false, reason: "transcript_session_mismatch" };
|
|
200
|
+
}
|
|
201
|
+
function indexRecordsByUuid(records) {
|
|
202
|
+
const indexed = new Map();
|
|
203
|
+
for (const record of records) {
|
|
204
|
+
const uuid = stringValue(record.uuid);
|
|
205
|
+
if (uuid)
|
|
206
|
+
indexed.set(uuid, record);
|
|
207
|
+
}
|
|
208
|
+
return indexed;
|
|
209
|
+
}
|
|
210
|
+
function requestedSessionRecords(records, requestedSessionId) {
|
|
211
|
+
let requestedSessionStart;
|
|
212
|
+
for (const [index, record] of records.entries()) {
|
|
213
|
+
const sessionId = sessionIdFromRecord(record);
|
|
214
|
+
if (!sessionId)
|
|
215
|
+
continue;
|
|
216
|
+
if (requestedSessionStart === undefined) {
|
|
217
|
+
if (sessionId === requestedSessionId)
|
|
218
|
+
requestedSessionStart = index;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (sessionId !== requestedSessionId)
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
return requestedSessionStart === undefined
|
|
225
|
+
? undefined
|
|
226
|
+
: records.slice(requestedSessionStart);
|
|
227
|
+
}
|
|
228
|
+
function transcriptRecords(transcript) {
|
|
229
|
+
const records = [];
|
|
230
|
+
const lines = transcript.split(/\r?\n/);
|
|
231
|
+
for (const [index, line] of lines.entries()) {
|
|
232
|
+
if (!line.trim())
|
|
233
|
+
continue;
|
|
234
|
+
try {
|
|
235
|
+
const parsed = JSON.parse(line);
|
|
236
|
+
if (!isRecord(parsed))
|
|
237
|
+
return { ok: false };
|
|
238
|
+
records.push(parsed);
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
// Claude may append while the file is being read; only an unterminated tail can be incomplete.
|
|
242
|
+
if (records.length > 0 && index === lines.length - 1 && !transcript.endsWith("\n"))
|
|
243
|
+
continue;
|
|
244
|
+
return { ok: false };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return { ok: true, records };
|
|
248
|
+
}
|
|
249
|
+
function maximalTerminalLineages(candidates) {
|
|
250
|
+
const indexesByRecord = new Map();
|
|
251
|
+
const indexesByUuid = new Map();
|
|
252
|
+
for (const [index, candidate] of candidates.entries()) {
|
|
253
|
+
const terminal = candidate.branch.records[0];
|
|
254
|
+
if (!terminal)
|
|
255
|
+
continue;
|
|
256
|
+
indexesByRecord.set(terminal, [...(indexesByRecord.get(terminal) ?? []), index]);
|
|
257
|
+
const uuid = stringValue(terminal.uuid);
|
|
258
|
+
if (uuid)
|
|
259
|
+
indexesByUuid.set(uuid, [...(indexesByUuid.get(uuid) ?? []), index]);
|
|
260
|
+
}
|
|
261
|
+
const superseded = new Set();
|
|
262
|
+
for (const [descendantIndex, candidate] of candidates.entries()) {
|
|
263
|
+
for (const ancestor of candidate.branch.records.slice(1)) {
|
|
264
|
+
const ancestorUuid = stringValue(ancestor.uuid);
|
|
265
|
+
const indexes = new Set([
|
|
266
|
+
...(indexesByRecord.get(ancestor) ?? []),
|
|
267
|
+
...(ancestorUuid ? indexesByUuid.get(ancestorUuid) ?? [] : []),
|
|
268
|
+
]);
|
|
269
|
+
for (const ancestorIndex of indexes) {
|
|
270
|
+
if (ancestorIndex !== descendantIndex)
|
|
271
|
+
superseded.add(ancestorIndex);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return candidates.filter((candidate, index) => (Boolean(candidate.branch.records[0]) && !superseded.has(index)));
|
|
276
|
+
}
|
|
277
|
+
function promptBranch(terminal, recordsByUuid) {
|
|
278
|
+
const visited = new Set();
|
|
279
|
+
const assistantMessages = [];
|
|
280
|
+
const branchRecords = [];
|
|
281
|
+
let current = terminal;
|
|
282
|
+
while (current) {
|
|
283
|
+
branchRecords.push(current);
|
|
284
|
+
const uuid = stringValue(current.uuid);
|
|
285
|
+
if (uuid) {
|
|
286
|
+
if (visited.has(uuid))
|
|
287
|
+
return { assistantMessages, records: branchRecords, ambiguous: true };
|
|
288
|
+
visited.add(uuid);
|
|
289
|
+
}
|
|
290
|
+
const assistantMessage = assistantMessageFromRecord(current);
|
|
291
|
+
if (assistantMessage)
|
|
292
|
+
assistantMessages.push(assistantMessage);
|
|
293
|
+
const prompt = visibleUserPrompt(current);
|
|
294
|
+
if (prompt) {
|
|
295
|
+
return {
|
|
296
|
+
promptId: promptIdFromRecord(current),
|
|
297
|
+
userPrompt: prompt,
|
|
298
|
+
assistantMessages,
|
|
299
|
+
records: branchRecords,
|
|
300
|
+
ambiguous: false,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
const parentUuid = stringValue(current.parentUuid) ?? stringValue(current.parent_uuid);
|
|
304
|
+
current = parentUuid ? recordsByUuid.get(parentUuid) : undefined;
|
|
305
|
+
}
|
|
306
|
+
return { assistantMessages, records: branchRecords, ambiguous: false };
|
|
307
|
+
}
|
|
308
|
+
function promptOnBranch(assistant, recordsByUuid, promptId) {
|
|
309
|
+
const branch = promptBranch(assistant, recordsByUuid);
|
|
310
|
+
if (branch.ambiguous)
|
|
311
|
+
return { ambiguous: true };
|
|
312
|
+
return branch.promptId === promptId && branch.userPrompt
|
|
313
|
+
? {
|
|
314
|
+
userPrompt: branch.userPrompt,
|
|
315
|
+
assistantMessages: branch.assistantMessages,
|
|
316
|
+
ambiguous: false,
|
|
317
|
+
}
|
|
318
|
+
: { ambiguous: false };
|
|
319
|
+
}
|
|
320
|
+
function visibleUserPrompt(record) {
|
|
321
|
+
if (!isInteractiveUserRecord(record))
|
|
322
|
+
return undefined;
|
|
323
|
+
const message = record.message;
|
|
324
|
+
return visibleMessageText(message.content);
|
|
325
|
+
}
|
|
326
|
+
function isInteractiveUserRecord(record) {
|
|
327
|
+
if (record.type !== "user"
|
|
328
|
+
|| record.userType !== "external"
|
|
329
|
+
|| record.isSidechain === true
|
|
330
|
+
|| record.isMeta === true
|
|
331
|
+
|| record.isCompactSummary === true
|
|
332
|
+
|| record.isVisibleInTranscriptOnly === true) {
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
const origin = isRecord(record.origin) ? record.origin : undefined;
|
|
336
|
+
if (stringValue(origin?.kind)?.toLowerCase() === "task-notification"
|
|
337
|
+
|| stringValue(record.promptSource ?? record.prompt_source)?.toLowerCase() === "system"
|
|
338
|
+
|| stringValue(record.interruptedMessageId ?? record.interrupted_message_id)) {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
const message = isRecord(record.message) ? record.message : undefined;
|
|
342
|
+
return Boolean(message && message.role === "user");
|
|
343
|
+
}
|
|
344
|
+
function interactivePromptIndex(records, targetPromptId) {
|
|
345
|
+
const seenPromptIds = new Set();
|
|
346
|
+
let index = 0;
|
|
347
|
+
for (const record of records) {
|
|
348
|
+
if (!visibleUserPrompt(record))
|
|
349
|
+
continue;
|
|
350
|
+
const promptId = promptIdFromRecord(record);
|
|
351
|
+
if (!promptId || seenPromptIds.has(promptId))
|
|
352
|
+
continue;
|
|
353
|
+
seenPromptIds.add(promptId);
|
|
354
|
+
index += 1;
|
|
355
|
+
if (promptId === targetPromptId)
|
|
356
|
+
return index;
|
|
357
|
+
}
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
function interruptionMarker(record) {
|
|
361
|
+
return record.type === "user"
|
|
362
|
+
&& record.isSidechain !== true
|
|
363
|
+
&& Boolean(stringValue(record.interruptedMessageId ?? record.interrupted_message_id));
|
|
364
|
+
}
|
|
365
|
+
function interruptedAssistantReply(assistantMessages) {
|
|
366
|
+
const textSegments = [];
|
|
367
|
+
const seenByMessageId = new Set();
|
|
368
|
+
for (const message of assistantMessages.slice().reverse()) {
|
|
369
|
+
const text = visibleMessageText(message.content);
|
|
370
|
+
if (!text)
|
|
371
|
+
continue;
|
|
372
|
+
const messageId = stringValue(message.id);
|
|
373
|
+
const dedupeKey = messageId ? `${messageId}\u0000${text}` : undefined;
|
|
374
|
+
if (dedupeKey && seenByMessageId.has(dedupeKey))
|
|
375
|
+
continue;
|
|
376
|
+
if (dedupeKey)
|
|
377
|
+
seenByMessageId.add(dedupeKey);
|
|
378
|
+
textSegments.push(text);
|
|
379
|
+
}
|
|
380
|
+
return textSegments.join("\n\n");
|
|
381
|
+
}
|
|
382
|
+
function transcriptRecordTimestamp(record) {
|
|
383
|
+
const timestamp = stringValue(record.timestamp);
|
|
384
|
+
return timestamp && Number.isFinite(Date.parse(timestamp)) ? timestamp : undefined;
|
|
385
|
+
}
|
|
386
|
+
function claudeMemoryActivityDetails(promptId, branch, includeAuthority) {
|
|
387
|
+
const activities = [];
|
|
388
|
+
const terminalRecordId = includeAuthority
|
|
389
|
+
? stringValue(branch.records[0]?.uuid)
|
|
390
|
+
: undefined;
|
|
391
|
+
const seenToolUseIds = new Set();
|
|
392
|
+
let index = 1;
|
|
393
|
+
for (const record of branch.records.slice().reverse()) {
|
|
394
|
+
const message = assistantMessageFromRecord(record);
|
|
395
|
+
if (!message || !Array.isArray(message.content))
|
|
396
|
+
continue;
|
|
397
|
+
for (const block of message.content) {
|
|
398
|
+
if (!isRecord(block) || block.type !== "tool_use")
|
|
399
|
+
continue;
|
|
400
|
+
const toolUseId = stringValue(block.id);
|
|
401
|
+
if (!toolUseId || seenToolUseIds.has(toolUseId))
|
|
402
|
+
continue;
|
|
403
|
+
seenToolUseIds.add(toolUseId);
|
|
404
|
+
if (block.name !== "Bash")
|
|
405
|
+
continue;
|
|
406
|
+
const toolInput = isRecord(block.input) ? block.input : undefined;
|
|
407
|
+
const command = toolInput ? stringValue(toolInput.command) : undefined;
|
|
408
|
+
if (!command)
|
|
409
|
+
continue;
|
|
410
|
+
const types = memoryCliCommandTypes(command);
|
|
411
|
+
if (types.length === 0)
|
|
412
|
+
continue;
|
|
413
|
+
const timestamp = canonicalTranscriptActivityTimestamp(record);
|
|
414
|
+
const result = claudeToolResultDetails(branch.records, toolUseId, types.length === 1 && types[0] === "memory_cli_search");
|
|
415
|
+
for (const [occurrence, type] of types.entries()) {
|
|
416
|
+
activities.push({
|
|
417
|
+
promptId,
|
|
418
|
+
index,
|
|
419
|
+
occurrence: occurrence + 1,
|
|
420
|
+
type,
|
|
421
|
+
toolUseId,
|
|
422
|
+
...(terminalRecordId ? { terminalRecordId } : {}),
|
|
423
|
+
...(timestamp ? { timestamp } : {}),
|
|
424
|
+
...(result.ok === undefined ? {} : { ok: result.ok }),
|
|
425
|
+
...(type === "memory_cli_search" && result.itemCount !== undefined
|
|
426
|
+
? { itemCount: result.itemCount }
|
|
427
|
+
: {}),
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
index += 1;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return activities;
|
|
434
|
+
}
|
|
435
|
+
function canonicalTranscriptActivityTimestamp(record) {
|
|
436
|
+
const timestamp = transcriptRecordTimestamp(record);
|
|
437
|
+
return timestamp ? new Date(Date.parse(timestamp)).toISOString() : undefined;
|
|
438
|
+
}
|
|
439
|
+
function claudeToolResultDetails(branchRecords, toolUseId, deriveSearchItemCount) {
|
|
440
|
+
const matches = [];
|
|
441
|
+
let failed = false;
|
|
442
|
+
for (const record of branchRecords) {
|
|
443
|
+
const message = isRecord(record.message) ? record.message : undefined;
|
|
444
|
+
if (message?.role !== "user" || !Array.isArray(message.content))
|
|
445
|
+
continue;
|
|
446
|
+
for (const block of message.content) {
|
|
447
|
+
if (!isRecord(block)
|
|
448
|
+
|| block.type !== "tool_result"
|
|
449
|
+
|| stringValue(block.tool_use_id ?? block.toolUseId) !== toolUseId) {
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
matches.push(block);
|
|
453
|
+
if (block.is_error === true)
|
|
454
|
+
failed = true;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (matches.length === 0)
|
|
458
|
+
return {};
|
|
459
|
+
if (failed)
|
|
460
|
+
return { ok: false };
|
|
461
|
+
if (!deriveSearchItemCount || matches.length !== 1)
|
|
462
|
+
return { ok: true };
|
|
463
|
+
const itemCount = safeMemorySearchItemCount(matches[0]?.content);
|
|
464
|
+
return itemCount === undefined ? { ok: true } : { ok: true, itemCount };
|
|
465
|
+
}
|
|
466
|
+
function memoryCliCommandTypes(command) {
|
|
467
|
+
const activities = [];
|
|
468
|
+
for (const segment of shellCommandSegments(command)) {
|
|
469
|
+
const words = shellWords(segment);
|
|
470
|
+
if (!words)
|
|
471
|
+
continue;
|
|
472
|
+
let executableIndex = 0;
|
|
473
|
+
while (isShellAssignmentWord(words[executableIndex]))
|
|
474
|
+
executableIndex += 1;
|
|
475
|
+
const executable = words[executableIndex];
|
|
476
|
+
if (!isMemoraxCliExecutable(executable))
|
|
477
|
+
continue;
|
|
478
|
+
const operation = words[executableIndex + 1]?.toLowerCase();
|
|
479
|
+
if (operation === "search")
|
|
480
|
+
activities.push("memory_cli_search");
|
|
481
|
+
if (operation === "add")
|
|
482
|
+
activities.push("memory_cli_add");
|
|
483
|
+
}
|
|
484
|
+
return activities;
|
|
485
|
+
}
|
|
486
|
+
function shellCommandSegments(command) {
|
|
487
|
+
const segments = [];
|
|
488
|
+
let segment = "";
|
|
489
|
+
let quote;
|
|
490
|
+
let escaped = false;
|
|
491
|
+
let substitutionDepth = 0;
|
|
492
|
+
const pushSegment = () => {
|
|
493
|
+
if (segment.trim())
|
|
494
|
+
segments.push(segment);
|
|
495
|
+
segment = "";
|
|
496
|
+
};
|
|
497
|
+
for (let index = 0; index < command.length; index += 1) {
|
|
498
|
+
const character = command[index] ?? "";
|
|
499
|
+
if (escaped) {
|
|
500
|
+
segment += character;
|
|
501
|
+
escaped = false;
|
|
502
|
+
continue;
|
|
503
|
+
}
|
|
504
|
+
if (character === "\\" && quote !== "'") {
|
|
505
|
+
segment += character;
|
|
506
|
+
escaped = true;
|
|
507
|
+
continue;
|
|
508
|
+
}
|
|
509
|
+
if (quote) {
|
|
510
|
+
segment += character;
|
|
511
|
+
if (character === quote)
|
|
512
|
+
quote = undefined;
|
|
513
|
+
continue;
|
|
514
|
+
}
|
|
515
|
+
if (character === "'" || character === "\"" || character === "`") {
|
|
516
|
+
quote = character;
|
|
517
|
+
segment += character;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (character === "$" && command[index + 1] === "(") {
|
|
521
|
+
substitutionDepth += 1;
|
|
522
|
+
segment += "$(";
|
|
523
|
+
index += 1;
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
if (character === ")" && substitutionDepth > 0) {
|
|
527
|
+
substitutionDepth -= 1;
|
|
528
|
+
segment += character;
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (substitutionDepth === 0 && (character === ";" || character === "\n" || character === "\r")) {
|
|
532
|
+
pushSegment();
|
|
533
|
+
if (character === "\r" && command[index + 1] === "\n")
|
|
534
|
+
index += 1;
|
|
535
|
+
continue;
|
|
536
|
+
}
|
|
537
|
+
if (substitutionDepth === 0
|
|
538
|
+
&& ((character === "&" && command[index + 1] === "&")
|
|
539
|
+
|| (character === "|" && command[index + 1] === "|"))) {
|
|
540
|
+
pushSegment();
|
|
541
|
+
index += 1;
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
segment += character;
|
|
545
|
+
}
|
|
546
|
+
pushSegment();
|
|
547
|
+
return segments;
|
|
548
|
+
}
|
|
549
|
+
function shellWords(segment) {
|
|
550
|
+
const words = [];
|
|
551
|
+
let word = "";
|
|
552
|
+
let hasWord = false;
|
|
553
|
+
let quote;
|
|
554
|
+
for (let index = 0; index < segment.length; index += 1) {
|
|
555
|
+
const character = segment[index] ?? "";
|
|
556
|
+
if (quote === "'") {
|
|
557
|
+
if (character === "'")
|
|
558
|
+
quote = undefined;
|
|
559
|
+
else
|
|
560
|
+
word += character;
|
|
561
|
+
hasWord = true;
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
if (quote === "\"") {
|
|
565
|
+
if (character === "\"") {
|
|
566
|
+
quote = undefined;
|
|
567
|
+
}
|
|
568
|
+
else if (character === "\\"
|
|
569
|
+
&& ["\\", "\"", "$", "`", "\n"].includes(segment[index + 1] ?? "")) {
|
|
570
|
+
index += 1;
|
|
571
|
+
word += segment[index] ?? "";
|
|
572
|
+
}
|
|
573
|
+
else {
|
|
574
|
+
word += character;
|
|
575
|
+
}
|
|
576
|
+
hasWord = true;
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (character === "'" || character === "\"") {
|
|
580
|
+
quote = character;
|
|
581
|
+
hasWord = true;
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
if (character === "\\") {
|
|
585
|
+
index += 1;
|
|
586
|
+
if (index >= segment.length)
|
|
587
|
+
return undefined;
|
|
588
|
+
word += segment[index] ?? "";
|
|
589
|
+
hasWord = true;
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (/\s/u.test(character)) {
|
|
593
|
+
if (hasWord)
|
|
594
|
+
words.push(word);
|
|
595
|
+
word = "";
|
|
596
|
+
hasWord = false;
|
|
597
|
+
continue;
|
|
598
|
+
}
|
|
599
|
+
word += character;
|
|
600
|
+
hasWord = true;
|
|
601
|
+
}
|
|
602
|
+
if (quote)
|
|
603
|
+
return undefined;
|
|
604
|
+
if (hasWord)
|
|
605
|
+
words.push(word);
|
|
606
|
+
return words;
|
|
607
|
+
}
|
|
608
|
+
function isShellAssignmentWord(word) {
|
|
609
|
+
return Boolean(word && /^[A-Za-z_][A-Za-z0-9_]*=/u.test(word));
|
|
610
|
+
}
|
|
611
|
+
function isMemoraxCliExecutable(word) {
|
|
612
|
+
return isNamedExecutable(word, "memorax-cli");
|
|
613
|
+
}
|
|
614
|
+
function isNamedExecutable(word, name) {
|
|
615
|
+
if (!word)
|
|
616
|
+
return false;
|
|
617
|
+
const normalized = word.replaceAll("\\", "/");
|
|
618
|
+
if (normalized === name || normalized === `${name}.mjs`)
|
|
619
|
+
return true;
|
|
620
|
+
const absolute = normalized.startsWith("/") || /^[A-Za-z]:\//u.test(normalized);
|
|
621
|
+
if (!absolute)
|
|
622
|
+
return false;
|
|
623
|
+
const basename = normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
624
|
+
return basename === name || basename === `${name}.mjs`;
|
|
625
|
+
}
|
|
626
|
+
function safeMemorySearchItemCount(content) {
|
|
627
|
+
if (typeof content !== "string" || content.length > 2 * 1024 * 1024)
|
|
628
|
+
return undefined;
|
|
629
|
+
const output = content.trim();
|
|
630
|
+
if (!output)
|
|
631
|
+
return undefined;
|
|
632
|
+
if (output.startsWith("{")) {
|
|
633
|
+
try {
|
|
634
|
+
const parsed = JSON.parse(output);
|
|
635
|
+
if (!isRecord(parsed)
|
|
636
|
+
|| parsed.ok !== true
|
|
637
|
+
|| parsed.action !== "memory.search"
|
|
638
|
+
|| !Array.isArray(parsed.items)
|
|
639
|
+
|| parsed.items.length > 100) {
|
|
640
|
+
return undefined;
|
|
641
|
+
}
|
|
642
|
+
return parsed.items.length;
|
|
643
|
+
}
|
|
644
|
+
catch {
|
|
645
|
+
return undefined;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
const lines = output.split(/\r?\n/u);
|
|
649
|
+
if (lines[0] !== "<memories>" || lines.at(-1) !== "</memories>")
|
|
650
|
+
return undefined;
|
|
651
|
+
let insideFacts = false;
|
|
652
|
+
let factsGroups = 0;
|
|
653
|
+
let itemCount = 0;
|
|
654
|
+
for (const line of lines.slice(1, -1)) {
|
|
655
|
+
if (!insideFacts && /^ {2}<facts(?: memory_type="[^"\r\n]*")?>$/u.test(line)) {
|
|
656
|
+
insideFacts = true;
|
|
657
|
+
factsGroups += 1;
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (insideFacts && line === " </facts>") {
|
|
661
|
+
insideFacts = false;
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
if (insideFacts && /^ {3}-(?:\[[^\]\r\n]+\] | )\S.*$/u.test(line)) {
|
|
665
|
+
itemCount += 1;
|
|
666
|
+
if (itemCount > 100)
|
|
667
|
+
return undefined;
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
return !insideFacts && factsGroups > 0 && itemCount > 0 ? itemCount : undefined;
|
|
673
|
+
}
|
|
674
|
+
function claudeMemoryActivities(assistantMessages) {
|
|
675
|
+
const activities = [];
|
|
676
|
+
const seenToolUseIds = new Set();
|
|
677
|
+
let index = 1;
|
|
678
|
+
for (const message of assistantMessages.slice().reverse()) {
|
|
679
|
+
if (!Array.isArray(message.content))
|
|
680
|
+
continue;
|
|
681
|
+
for (const block of message.content) {
|
|
682
|
+
if (!isRecord(block) || block.type !== "tool_use")
|
|
683
|
+
continue;
|
|
684
|
+
const toolUseId = stringValue(block.id);
|
|
685
|
+
if (!toolUseId || seenToolUseIds.has(toolUseId))
|
|
686
|
+
continue;
|
|
687
|
+
seenToolUseIds.add(toolUseId);
|
|
688
|
+
if (block.name !== "Bash")
|
|
689
|
+
continue;
|
|
690
|
+
const toolInput = isRecord(block.input) ? block.input : undefined;
|
|
691
|
+
const command = toolInput ? stringValue(toolInput.command) : undefined;
|
|
692
|
+
if (!command)
|
|
693
|
+
continue;
|
|
694
|
+
const types = memoryCliCommandTypes(command);
|
|
695
|
+
if (types.length === 0)
|
|
696
|
+
continue;
|
|
697
|
+
for (const type of types) {
|
|
698
|
+
activities.push({
|
|
699
|
+
index,
|
|
700
|
+
type,
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
index += 1;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return activities;
|
|
707
|
+
}
|
|
708
|
+
const CLAUDE_USAGE_COUNT_FIELDS = [
|
|
709
|
+
"input_tokens",
|
|
710
|
+
"cache_creation_input_tokens",
|
|
711
|
+
"cache_read_input_tokens",
|
|
712
|
+
"output_tokens",
|
|
713
|
+
"ephemeral_1h_input_tokens",
|
|
714
|
+
"ephemeral_5m_input_tokens",
|
|
715
|
+
"web_search_requests",
|
|
716
|
+
"web_fetch_requests",
|
|
717
|
+
];
|
|
718
|
+
function aggregateClaudeUsage(assistantMessages) {
|
|
719
|
+
const usageByMessageId = new Map();
|
|
720
|
+
const totals = emptyClaudeUsageCounts();
|
|
721
|
+
for (const message of assistantMessages) {
|
|
722
|
+
const messageId = stringValue(message.id);
|
|
723
|
+
const usage = claudeUsageCounts(message.usage);
|
|
724
|
+
if (!messageId || !usage)
|
|
725
|
+
return undefined;
|
|
726
|
+
const existing = usageByMessageId.get(messageId);
|
|
727
|
+
if (existing) {
|
|
728
|
+
if (!sameClaudeUsageCounts(existing, usage))
|
|
729
|
+
return undefined;
|
|
730
|
+
continue;
|
|
731
|
+
}
|
|
732
|
+
usageByMessageId.set(messageId, usage);
|
|
733
|
+
if (!addClaudeUsageCounts(totals, usage))
|
|
734
|
+
return undefined;
|
|
735
|
+
}
|
|
736
|
+
return usageByMessageId.size > 0 ? claudeTokenUsage(totals) : undefined;
|
|
737
|
+
}
|
|
738
|
+
function claudeUsageCounts(value) {
|
|
739
|
+
if (!isRecord(value))
|
|
740
|
+
return undefined;
|
|
741
|
+
const inputTokens = nonNegativeInteger(value.input_tokens);
|
|
742
|
+
const cacheCreationInputTokens = nullableNonNegativeInteger(value.cache_creation_input_tokens);
|
|
743
|
+
const cacheReadInputTokens = nullableNonNegativeInteger(value.cache_read_input_tokens);
|
|
744
|
+
const outputTokens = nonNegativeInteger(value.output_tokens);
|
|
745
|
+
const cacheCreation = nullableUsageGroup(value.cache_creation, [
|
|
746
|
+
"ephemeral_1h_input_tokens",
|
|
747
|
+
"ephemeral_5m_input_tokens",
|
|
748
|
+
]);
|
|
749
|
+
const serverToolUse = nullableUsageGroup(value.server_tool_use, [
|
|
750
|
+
"web_search_requests",
|
|
751
|
+
"web_fetch_requests",
|
|
752
|
+
]);
|
|
753
|
+
if (inputTokens === undefined
|
|
754
|
+
|| cacheCreationInputTokens === undefined
|
|
755
|
+
|| cacheReadInputTokens === undefined
|
|
756
|
+
|| outputTokens === undefined
|
|
757
|
+
|| !cacheCreation
|
|
758
|
+
|| !serverToolUse) {
|
|
759
|
+
return undefined;
|
|
760
|
+
}
|
|
761
|
+
return {
|
|
762
|
+
input_tokens: inputTokens,
|
|
763
|
+
cache_creation_input_tokens: cacheCreationInputTokens,
|
|
764
|
+
cache_read_input_tokens: cacheReadInputTokens,
|
|
765
|
+
output_tokens: outputTokens,
|
|
766
|
+
ephemeral_1h_input_tokens: cacheCreation.ephemeral_1h_input_tokens,
|
|
767
|
+
ephemeral_5m_input_tokens: cacheCreation.ephemeral_5m_input_tokens,
|
|
768
|
+
web_search_requests: serverToolUse.web_search_requests,
|
|
769
|
+
web_fetch_requests: serverToolUse.web_fetch_requests,
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
function nullableUsageGroup(value, fields) {
|
|
773
|
+
if (value === null) {
|
|
774
|
+
return Object.fromEntries(fields.map((field) => [field, 0]));
|
|
775
|
+
}
|
|
776
|
+
if (!isRecord(value))
|
|
777
|
+
return undefined;
|
|
778
|
+
const entries = fields.map((field) => [field, nonNegativeInteger(value[field])]);
|
|
779
|
+
if (entries.some(([, count]) => count === undefined))
|
|
780
|
+
return undefined;
|
|
781
|
+
return Object.fromEntries(entries);
|
|
782
|
+
}
|
|
783
|
+
function sameClaudeUsageCounts(left, right) {
|
|
784
|
+
return CLAUDE_USAGE_COUNT_FIELDS.every((field) => left[field] === right[field]);
|
|
785
|
+
}
|
|
786
|
+
function addClaudeUsageCounts(total, next) {
|
|
787
|
+
for (const field of CLAUDE_USAGE_COUNT_FIELDS) {
|
|
788
|
+
const sum = total[field] + next[field];
|
|
789
|
+
if (!Number.isSafeInteger(sum))
|
|
790
|
+
return false;
|
|
791
|
+
total[field] = sum;
|
|
792
|
+
}
|
|
793
|
+
return true;
|
|
794
|
+
}
|
|
795
|
+
function emptyClaudeUsageCounts() {
|
|
796
|
+
return Object.fromEntries(CLAUDE_USAGE_COUNT_FIELDS.map((field) => [field, 0]));
|
|
797
|
+
}
|
|
798
|
+
function claudeTokenUsage(counts) {
|
|
799
|
+
return {
|
|
800
|
+
input_tokens: counts.input_tokens,
|
|
801
|
+
cache_creation_input_tokens: counts.cache_creation_input_tokens,
|
|
802
|
+
cache_read_input_tokens: counts.cache_read_input_tokens,
|
|
803
|
+
output_tokens: counts.output_tokens,
|
|
804
|
+
cache_creation: {
|
|
805
|
+
ephemeral_1h_input_tokens: counts.ephemeral_1h_input_tokens,
|
|
806
|
+
ephemeral_5m_input_tokens: counts.ephemeral_5m_input_tokens,
|
|
807
|
+
},
|
|
808
|
+
server_tool_use: {
|
|
809
|
+
web_search_requests: counts.web_search_requests,
|
|
810
|
+
web_fetch_requests: counts.web_fetch_requests,
|
|
811
|
+
},
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
function completedAssistantReply(record) {
|
|
815
|
+
const message = assistantMessageFromRecord(record);
|
|
816
|
+
if (!message || message.stop_reason !== "end_turn")
|
|
817
|
+
return undefined;
|
|
818
|
+
return visibleMessageText(message.content);
|
|
819
|
+
}
|
|
820
|
+
function isCompletedAssistantRecord(record) {
|
|
821
|
+
return assistantMessageFromRecord(record)?.stop_reason === "end_turn";
|
|
822
|
+
}
|
|
823
|
+
function isMemoryActivityTerminalAssistantRecord(record) {
|
|
824
|
+
const message = assistantMessageFromRecord(record);
|
|
825
|
+
const stopReason = message ? stringValue(message.stop_reason) : undefined;
|
|
826
|
+
return Boolean(message && ((stopReason && stopReason !== "tool_use")
|
|
827
|
+
|| record.isApiErrorMessage === true
|
|
828
|
+
|| record.error));
|
|
829
|
+
}
|
|
830
|
+
function assistantMessageFromRecord(record) {
|
|
831
|
+
if (record.type !== "assistant"
|
|
832
|
+
|| record.isSidechain === true
|
|
833
|
+
|| record.isMeta === true
|
|
834
|
+
|| record.isCompactSummary === true
|
|
835
|
+
|| record.isVisibleInTranscriptOnly === true) {
|
|
836
|
+
return undefined;
|
|
837
|
+
}
|
|
838
|
+
const message = isRecord(record.message) ? record.message : undefined;
|
|
839
|
+
return message?.role === "assistant" ? message : undefined;
|
|
840
|
+
}
|
|
841
|
+
function visibleMessageText(content) {
|
|
842
|
+
if (typeof content === "string")
|
|
843
|
+
return nonBlankString(content);
|
|
844
|
+
if (!Array.isArray(content))
|
|
845
|
+
return undefined;
|
|
846
|
+
const text = content
|
|
847
|
+
.map((part) => isRecord(part) && part.type === "text" ? nonBlankString(part.text) : undefined)
|
|
848
|
+
.filter(isString)
|
|
849
|
+
.join("\n\n")
|
|
850
|
+
.trim();
|
|
851
|
+
return text || undefined;
|
|
852
|
+
}
|
|
853
|
+
function sessionIdFromRecord(record) {
|
|
854
|
+
return stringValue(record.sessionId) ?? stringValue(record.session_id);
|
|
855
|
+
}
|
|
856
|
+
function promptIdFromRecord(record) {
|
|
857
|
+
return stringValue(record.promptId) ?? stringValue(record.prompt_id);
|
|
858
|
+
}
|
|
859
|
+
function nonBlankString(value) {
|
|
860
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
861
|
+
}
|
|
862
|
+
function stringValue(value) {
|
|
863
|
+
return typeof value === "string" && value ? value : undefined;
|
|
864
|
+
}
|
|
865
|
+
function nonNegativeInteger(value) {
|
|
866
|
+
return Number.isSafeInteger(value) && Number(value) >= 0 ? Number(value) : undefined;
|
|
867
|
+
}
|
|
868
|
+
function nullableNonNegativeInteger(value) {
|
|
869
|
+
return value === null ? 0 : nonNegativeInteger(value);
|
|
870
|
+
}
|
|
871
|
+
function isString(value) {
|
|
872
|
+
return value !== undefined;
|
|
873
|
+
}
|
|
874
|
+
function isRecord(value) {
|
|
875
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
876
|
+
}
|