@team-agent/installer 0.2.11 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +744 -0
- package/Cargo.toml +34 -0
- package/crates/team-agent/Cargo.toml +33 -0
- package/crates/team-agent/src/cli/adapters.rs +1343 -0
- package/crates/team-agent/src/cli/diagnose.rs +554 -0
- package/crates/team-agent/src/cli/emit.rs +1204 -0
- package/crates/team-agent/src/cli/helpers.rs +88 -0
- package/crates/team-agent/src/cli/leader.rs +216 -0
- package/crates/team-agent/src/cli/mod.rs +1207 -0
- package/crates/team-agent/src/cli/profile.rs +306 -0
- package/crates/team-agent/src/cli/send.rs +215 -0
- package/crates/team-agent/src/cli/status.rs +179 -0
- package/crates/team-agent/src/cli/status_port.rs +502 -0
- package/crates/team-agent/src/cli/tests/base.rs +616 -0
- package/crates/team-agent/src/cli/tests/compile.rs +96 -0
- package/crates/team-agent/src/cli/tests/divergence.rs +509 -0
- package/crates/team-agent/src/cli/tests/lane_c.rs +333 -0
- package/crates/team-agent/src/cli/tests/leader_watch.rs +395 -0
- package/crates/team-agent/src/cli/tests/main_preserved.rs +675 -0
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +390 -0
- package/crates/team-agent/src/cli/tests/mod.rs +97 -0
- package/crates/team-agent/src/cli/tests/peer_allow.rs +137 -0
- package/crates/team-agent/src/cli/tests/repair_state_byte_lock.rs +302 -0
- package/crates/team-agent/src/cli/tests/run_delegation.rs +305 -0
- package/crates/team-agent/src/cli/tests/status_send.rs +385 -0
- package/crates/team-agent/src/cli/tests/verb_profile.rs +182 -0
- package/crates/team-agent/src/cli/tests/verb_settle.rs +236 -0
- package/crates/team-agent/src/cli/tests/verb_validate.rs +184 -0
- package/crates/team-agent/src/cli/types.rs +605 -0
- package/crates/team-agent/src/compiler/tests.rs +701 -0
- package/crates/team-agent/src/compiler.rs +489 -0
- package/crates/team-agent/src/coordinator/backoff.rs +153 -0
- package/crates/team-agent/src/coordinator/health.rs +557 -0
- package/crates/team-agent/src/coordinator/mod.rs +80 -0
- package/crates/team-agent/src/coordinator/orphan.rs +179 -0
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +255 -0
- package/crates/team-agent/src/coordinator/tests/basics.rs +262 -0
- package/crates/team-agent/src/coordinator/tests/daemon.rs +323 -0
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +263 -0
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +136 -0
- package/crates/team-agent/src/coordinator/tests/mod.rs +310 -0
- package/crates/team-agent/src/coordinator/tests/spine.rs +261 -0
- package/crates/team-agent/src/coordinator/tests/takeover.rs +227 -0
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +256 -0
- package/crates/team-agent/src/coordinator/tests/watch.rs +167 -0
- package/crates/team-agent/src/coordinator/tick.rs +2032 -0
- package/crates/team-agent/src/coordinator/types.rs +584 -0
- package/crates/team-agent/src/db/migration.rs +716 -0
- package/crates/team-agent/src/db/mod.rs +23 -0
- package/crates/team-agent/src/db/schema.rs +378 -0
- package/crates/team-agent/src/event_log.rs +375 -0
- package/crates/team-agent/src/fake_worker.rs +253 -0
- package/crates/team-agent/src/leader/helpers.rs +190 -0
- package/crates/team-agent/src/leader/inject.rs +33 -0
- package/crates/team-agent/src/leader/lease.rs +1084 -0
- package/crates/team-agent/src/leader/mod.rs +99 -0
- package/crates/team-agent/src/leader/owner_bind.rs +292 -0
- package/crates/team-agent/src/leader/rediscover/tests.rs +526 -0
- package/crates/team-agent/src/leader/rediscover.rs +1101 -0
- package/crates/team-agent/src/leader/start.rs +273 -0
- package/crates/team-agent/src/leader/takeover.rs +235 -0
- package/crates/team-agent/src/leader/tests/basics.rs +183 -0
- package/crates/team-agent/src/leader/tests/byte_findings.rs +237 -0
- package/crates/team-agent/src/leader/tests/identity.rs +206 -0
- package/crates/team-agent/src/leader/tests/idle.rs +272 -0
- package/crates/team-agent/src/leader/tests/lease_api.rs +225 -0
- package/crates/team-agent/src/leader/tests/lease_claim.rs +410 -0
- package/crates/team-agent/src/leader/tests/mod.rs +125 -0
- package/crates/team-agent/src/leader/tests/rediscover.rs +351 -0
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +204 -0
- package/crates/team-agent/src/leader/types.rs +489 -0
- package/crates/team-agent/src/lib.rs +85 -0
- package/crates/team-agent/src/lifecycle/display.rs +228 -0
- package/crates/team-agent/src/lifecycle/helpers.rs +112 -0
- package/crates/team-agent/src/lifecycle/launch/plan.rs +227 -0
- package/crates/team-agent/src/lifecycle/launch.rs +2109 -0
- package/crates/team-agent/src/lifecycle/mod.rs +62 -0
- package/crates/team-agent/src/lifecycle/restart/agent.rs +533 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +517 -0
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +41 -0
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +268 -0
- package/crates/team-agent/src/lifecycle/restart/remove.rs +780 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +208 -0
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +242 -0
- package/crates/team-agent/src/lifecycle/restart.rs +76 -0
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +455 -0
- package/crates/team-agent/src/lifecycle/tests/core.rs +989 -0
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +583 -0
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +985 -0
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +265 -0
- package/crates/team-agent/src/lifecycle/tests.rs +27 -0
- package/crates/team-agent/src/lifecycle/types.rs +710 -0
- package/crates/team-agent/src/main.rs +41 -0
- package/crates/team-agent/src/mcp_server/helpers.rs +228 -0
- package/crates/team-agent/src/mcp_server/mod.rs +183 -0
- package/crates/team-agent/src/mcp_server/normalize.rs +312 -0
- package/crates/team-agent/src/mcp_server/tests/golden.rs +283 -0
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +244 -0
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +189 -0
- package/crates/team-agent/src/mcp_server/tests/send.rs +222 -0
- package/crates/team-agent/src/mcp_server/tests/tools.rs +158 -0
- package/crates/team-agent/src/mcp_server/tests/wire.rs +187 -0
- package/crates/team-agent/src/mcp_server/tests.rs +38 -0
- package/crates/team-agent/src/mcp_server/tools.rs +603 -0
- package/crates/team-agent/src/mcp_server/types.rs +421 -0
- package/crates/team-agent/src/mcp_server/wire.rs +468 -0
- package/crates/team-agent/src/message_store.rs +767 -0
- package/crates/team-agent/src/messaging/activity.rs +433 -0
- package/crates/team-agent/src/messaging/delivery.rs +743 -0
- package/crates/team-agent/src/messaging/helpers.rs +209 -0
- package/crates/team-agent/src/messaging/leader_receiver.rs +329 -0
- package/crates/team-agent/src/messaging/mod.rs +147 -0
- package/crates/team-agent/src/messaging/peers.rs +32 -0
- package/crates/team-agent/src/messaging/results.rs +553 -0
- package/crates/team-agent/src/messaging/scheduler.rs +344 -0
- package/crates/team-agent/src/messaging/selftest.rs +100 -0
- package/crates/team-agent/src/messaging/send.rs +578 -0
- package/crates/team-agent/src/messaging/tests/basic.rs +357 -0
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +122 -0
- package/crates/team-agent/src/messaging/tests/mod.rs +293 -0
- package/crates/team-agent/src/messaging/tests/runtime.rs +1422 -0
- package/crates/team-agent/src/messaging/tests/spine.rs +437 -0
- package/crates/team-agent/src/messaging/trust.rs +192 -0
- package/crates/team-agent/src/messaging/types.rs +355 -0
- package/crates/team-agent/src/messaging/watchers.rs +591 -0
- package/crates/team-agent/src/model/enums.rs +311 -0
- package/crates/team-agent/src/model/errors.rs +17 -0
- package/crates/team-agent/src/model/ids.rs +155 -0
- package/crates/team-agent/src/model/mod.rs +22 -0
- package/crates/team-agent/src/model/paths.rs +228 -0
- package/crates/team-agent/src/model/permissions.rs +567 -0
- package/crates/team-agent/src/model/routing.rs +340 -0
- package/crates/team-agent/src/model/spec.rs +680 -0
- package/crates/team-agent/src/model/task_graph.rs +380 -0
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +43 -0
- package/crates/team-agent/src/model/testdata/fuzz.yaml +43 -0
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +207 -0
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +206 -0
- package/crates/team-agent/src/model/testdata/team.spec.yaml +206 -0
- package/crates/team-agent/src/model/yaml/tests.rs +288 -0
- package/crates/team-agent/src/model/yaml.rs +800 -0
- package/crates/team-agent/src/packaging/install.rs +305 -0
- package/crates/team-agent/src/packaging/migrate.rs +30 -0
- package/crates/team-agent/src/packaging/mod.rs +82 -0
- package/crates/team-agent/src/packaging/repair.rs +24 -0
- package/crates/team-agent/src/packaging/tests.rs +829 -0
- package/crates/team-agent/src/packaging/types.rs +369 -0
- package/crates/team-agent/src/provider/adapter.rs +801 -0
- package/crates/team-agent/src/provider/approvals/mod.rs +2 -0
- package/crates/team-agent/src/provider/approvals/parsing.rs +452 -0
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +163 -0
- package/crates/team-agent/src/provider/classify.rs +456 -0
- package/crates/team-agent/src/provider/faults.rs +136 -0
- package/crates/team-agent/src/provider/helpers.rs +41 -0
- package/crates/team-agent/src/provider/mod.rs +53 -0
- package/crates/team-agent/src/provider/startup_prompt.rs +423 -0
- package/crates/team-agent/src/provider/tests/adapter.rs +239 -0
- package/crates/team-agent/src/provider/tests/classify.rs +240 -0
- package/crates/team-agent/src/provider/tests/faults.rs +120 -0
- package/crates/team-agent/src/provider/tests/idle.rs +208 -0
- package/crates/team-agent/src/provider/tests/wire.rs +213 -0
- package/crates/team-agent/src/provider/tests.rs +31 -0
- package/crates/team-agent/src/provider/types.rs +424 -0
- package/crates/team-agent/src/state/identity.rs +659 -0
- package/crates/team-agent/src/state/mod.rs +58 -0
- package/crates/team-agent/src/state/owner_gate.rs +423 -0
- package/crates/team-agent/src/state/persist.rs +712 -0
- package/crates/team-agent/src/state/projection.rs +657 -0
- package/crates/team-agent/src/state/selector.rs +105 -0
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +133 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +765 -0
- package/crates/team-agent/src/tmux_backend.rs +810 -0
- package/crates/team-agent/src/transport/test_support.rs +252 -0
- package/crates/team-agent/src/transport/tests/behavior.rs +327 -0
- package/crates/team-agent/src/transport/tests/mod.rs +199 -0
- package/crates/team-agent/src/transport/tests/wire.rs +527 -0
- package/crates/team-agent/src/transport.rs +774 -0
- package/npm/install.mjs +118 -112
- package/package.json +15 -13
- package/crates/team-agent-core/Cargo.toml +0 -12
- package/crates/team-agent-core/src/lib.rs +0 -332
- package/crates/team-agent-core/src/main.rs +0 -152
- package/pyproject.toml +0 -18
- package/scripts/install.py +0 -88
- package/scripts/run_regression_tests.py +0 -83
- package/src/team_agent/__init__.py +0 -3
- package/src/team_agent/__main__.py +0 -5
- package/src/team_agent/_legacy_pane_discovery.py +0 -186
- package/src/team_agent/abnormal_track.py +0 -253
- package/src/team_agent/approvals/__init__.py +0 -65
- package/src/team_agent/approvals/constants.py +0 -6
- package/src/team_agent/approvals/parsing.py +0 -176
- package/src/team_agent/approvals/runtime_prompts.py +0 -171
- package/src/team_agent/approvals/status.py +0 -176
- package/src/team_agent/cli/__init__.py +0 -137
- package/src/team_agent/cli/commands.py +0 -481
- package/src/team_agent/cli/e2e.py +0 -202
- package/src/team_agent/cli/helpers.py +0 -226
- package/src/team_agent/cli/parser.py +0 -540
- package/src/team_agent/compiler.py +0 -334
- package/src/team_agent/coordinator/__init__.py +0 -53
- package/src/team_agent/coordinator/__main__.py +0 -119
- package/src/team_agent/coordinator/lifecycle.py +0 -411
- package/src/team_agent/coordinator/metadata.py +0 -61
- package/src/team_agent/coordinator/paths.py +0 -17
- package/src/team_agent/diagnose/__init__.py +0 -48
- package/src/team_agent/diagnose/checks.py +0 -101
- package/src/team_agent/diagnose/comms.py +0 -213
- package/src/team_agent/diagnose/health.py +0 -241
- package/src/team_agent/diagnose/orphan_cleanup.py +0 -364
- package/src/team_agent/diagnose/preflight.py +0 -194
- package/src/team_agent/diagnose/quick_start.py +0 -324
- package/src/team_agent/display/__init__.py +0 -92
- package/src/team_agent/display/adaptive.py +0 -511
- package/src/team_agent/display/backend.py +0 -46
- package/src/team_agent/display/close.py +0 -154
- package/src/team_agent/display/ghostty.py +0 -77
- package/src/team_agent/display/rebuild.py +0 -102
- package/src/team_agent/display/tiling.py +0 -156
- package/src/team_agent/display/worker_window.py +0 -114
- package/src/team_agent/display/workspace.py +0 -382
- package/src/team_agent/errors.py +0 -10
- package/src/team_agent/events.py +0 -84
- package/src/team_agent/fake_worker.py +0 -80
- package/src/team_agent/idle_predicate.py +0 -218
- package/src/team_agent/idle_takeover.py +0 -59
- package/src/team_agent/idle_takeover_wiring.py +0 -114
- package/src/team_agent/launch/__init__.py +0 -41
- package/src/team_agent/launch/bootstrap.py +0 -85
- package/src/team_agent/launch/config.py +0 -106
- package/src/team_agent/launch/core.py +0 -301
- package/src/team_agent/launch/requirements.py +0 -57
- package/src/team_agent/leader/__init__.py +0 -926
- package/src/team_agent/leader_binding.py +0 -183
- package/src/team_agent/lifecycle/__init__.py +0 -5
- package/src/team_agent/lifecycle/agents.py +0 -278
- package/src/team_agent/lifecycle/operations.py +0 -411
- package/src/team_agent/lifecycle/paste_buffer_hygiene.py +0 -39
- package/src/team_agent/lifecycle/start.py +0 -363
- package/src/team_agent/mcp_server/__init__.py +0 -42
- package/src/team_agent/mcp_server/__main__.py +0 -7
- package/src/team_agent/mcp_server/contracts.py +0 -148
- package/src/team_agent/mcp_server/normalize.py +0 -257
- package/src/team_agent/mcp_server/server.py +0 -150
- package/src/team_agent/mcp_server/tools.py +0 -352
- package/src/team_agent/message_store/__init__.py +0 -23
- package/src/team_agent/message_store/agent_health.py +0 -113
- package/src/team_agent/message_store/core.py +0 -497
- package/src/team_agent/message_store/leader_notification_log.py +0 -198
- package/src/team_agent/message_store/result_watchers.py +0 -251
- package/src/team_agent/message_store/schema.py +0 -308
- package/src/team_agent/message_store/schema_migration.py +0 -448
- package/src/team_agent/messaging/__init__.py +0 -1
- package/src/team_agent/messaging/activity_detector.py +0 -262
- package/src/team_agent/messaging/delivery.py +0 -504
- package/src/team_agent/messaging/deps.py +0 -247
- package/src/team_agent/messaging/idle_alerts.py +0 -423
- package/src/team_agent/messaging/internal_delivery.py +0 -46
- package/src/team_agent/messaging/leader.py +0 -497
- package/src/team_agent/messaging/leader_api_errors.py +0 -216
- package/src/team_agent/messaging/leader_panes.py +0 -673
- package/src/team_agent/messaging/owner_bypass.py +0 -29
- package/src/team_agent/messaging/result_delivery.py +0 -539
- package/src/team_agent/messaging/results.py +0 -447
- package/src/team_agent/messaging/scheduler.py +0 -450
- package/src/team_agent/messaging/send.py +0 -532
- package/src/team_agent/messaging/session_drift.py +0 -94
- package/src/team_agent/messaging/tmux_io.py +0 -506
- package/src/team_agent/messaging/tmux_prompt.py +0 -338
- package/src/team_agent/messaging/trust_auto_answer.py +0 -52
- package/src/team_agent/orchestrator/__init__.py +0 -376
- package/src/team_agent/orchestrator/plan.py +0 -122
- package/src/team_agent/orchestrator/state.py +0 -128
- package/src/team_agent/paths.py +0 -45
- package/src/team_agent/permissions.py +0 -123
- package/src/team_agent/profiles/__init__.py +0 -82
- package/src/team_agent/profiles/constants.py +0 -19
- package/src/team_agent/profiles/core.py +0 -407
- package/src/team_agent/profiles/helpers.py +0 -69
- package/src/team_agent/profiles/provider_env.py +0 -188
- package/src/team_agent/profiles/smoke.py +0 -201
- package/src/team_agent/provider_cli/__init__.py +0 -43
- package/src/team_agent/provider_cli/adapter.py +0 -172
- package/src/team_agent/provider_cli/base.py +0 -48
- package/src/team_agent/provider_cli/claude.py +0 -503
- package/src/team_agent/provider_cli/codex.py +0 -336
- package/src/team_agent/provider_cli/copilot.py +0 -8
- package/src/team_agent/provider_cli/fake.py +0 -39
- package/src/team_agent/provider_cli/gemini.py +0 -95
- package/src/team_agent/provider_cli/opencode.py +0 -8
- package/src/team_agent/provider_cli/prompt.py +0 -62
- package/src/team_agent/provider_cli/registry.py +0 -18
- package/src/team_agent/provider_cli/unsupported.py +0 -32
- package/src/team_agent/provider_state/README.md +0 -78
- package/src/team_agent/provider_state/__init__.py +0 -91
- package/src/team_agent/provider_state/claude.py +0 -86
- package/src/team_agent/provider_state/codex.py +0 -84
- package/src/team_agent/provider_state/common.py +0 -207
- package/src/team_agent/provider_state/registry.py +0 -118
- package/src/team_agent/providers.py +0 -163
- package/src/team_agent/quality_gates.py +0 -104
- package/src/team_agent/restart/__init__.py +0 -34
- package/src/team_agent/restart/orchestration.py +0 -554
- package/src/team_agent/restart/selection.py +0 -89
- package/src/team_agent/restart/snapshot.py +0 -70
- package/src/team_agent/routing.py +0 -84
- package/src/team_agent/runtime.py +0 -1243
- package/src/team_agent/rust_core.py +0 -327
- package/src/team_agent/sessions/__init__.py +0 -25
- package/src/team_agent/sessions/capture.py +0 -144
- package/src/team_agent/sessions/inventory.py +0 -44
- package/src/team_agent/sessions/resume.py +0 -135
- package/src/team_agent/simple_yaml.py +0 -236
- package/src/team_agent/spec.py +0 -370
- package/src/team_agent/state.py +0 -693
- package/src/team_agent/status/__init__.py +0 -63
- package/src/team_agent/status/approvals.py +0 -52
- package/src/team_agent/status/compact.py +0 -158
- package/src/team_agent/status/constants.py +0 -18
- package/src/team_agent/status/inbox.py +0 -58
- package/src/team_agent/status/peek.py +0 -117
- package/src/team_agent/status/queries.py +0 -199
- package/src/team_agent/task_graph.py +0 -80
- package/src/team_agent/terminal.py +0 -57
- package/src/team_agent/wake.py +0 -58
- package/src/team_agent/watch/__init__.py +0 -145
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
from dataclasses import dataclass, field
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
from typing import Any, Protocol, runtime_checkable
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
@dataclass(frozen=True)
|
|
9
|
-
class ProviderStartupInput:
|
|
10
|
-
agent_id: str
|
|
11
|
-
provider: str
|
|
12
|
-
model: str | None
|
|
13
|
-
workspace: Path
|
|
14
|
-
system_prompt: str
|
|
15
|
-
mcp_config: dict[str, Any] = field(default_factory=dict)
|
|
16
|
-
profile: dict[str, Any] = field(default_factory=dict)
|
|
17
|
-
permission_mode: str | None = None
|
|
18
|
-
runtime_flags: dict[str, Any] = field(default_factory=dict)
|
|
19
|
-
previous_session: dict[str, Any] = field(default_factory=dict)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class ProviderCapabilityError(RuntimeError):
|
|
23
|
-
def __init__(self, provider: str, capability: str, reason: str) -> None:
|
|
24
|
-
self.provider = provider
|
|
25
|
-
self.capability = capability
|
|
26
|
-
self.reason = reason
|
|
27
|
-
super().__init__(f"{provider} provider does not support {capability}: {reason}")
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@runtime_checkable
|
|
31
|
-
class ProviderCliSocket(Protocol):
|
|
32
|
-
provider: str
|
|
33
|
-
command_name: str
|
|
34
|
-
|
|
35
|
-
def build_command(self, startup: ProviderStartupInput) -> list[str]:
|
|
36
|
-
...
|
|
37
|
-
|
|
38
|
-
def build_resume_command(self, startup: ProviderStartupInput) -> list[str]:
|
|
39
|
-
...
|
|
40
|
-
|
|
41
|
-
def build_fork_command(self, startup: ProviderStartupInput, source_session_id: str) -> list[str]:
|
|
42
|
-
...
|
|
43
|
-
|
|
44
|
-
def capture_session_id(self, startup: ProviderStartupInput, timeout_s: float = 3.0) -> dict[str, Any] | None:
|
|
45
|
-
...
|
|
46
|
-
|
|
47
|
-
def cleanup(self, startup: ProviderStartupInput) -> None:
|
|
48
|
-
...
|
|
@@ -1,503 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
import re
|
|
5
|
-
import subprocess
|
|
6
|
-
import time
|
|
7
|
-
import uuid
|
|
8
|
-
from datetime import datetime, timedelta, timezone
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
from typing import Any
|
|
11
|
-
|
|
12
|
-
from team_agent.permissions import resolve_permissions
|
|
13
|
-
from team_agent.provider_cli.adapter import (
|
|
14
|
-
ProviderAdapter,
|
|
15
|
-
ResumeUnavailable,
|
|
16
|
-
agent_model,
|
|
17
|
-
parse_time,
|
|
18
|
-
)
|
|
19
|
-
from team_agent.provider_cli.prompt import compile_system_prompt
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class ClaudeCodeAdapter(ProviderAdapter):
|
|
23
|
-
provider = "claude_code"
|
|
24
|
-
command_name = "claude"
|
|
25
|
-
|
|
26
|
-
def build_command(self, agent: dict[str, Any], workspace: Path, mcp_config: dict[str, Any]) -> list[str]:
|
|
27
|
-
session_id = agent.get("_session_id") or str(uuid.uuid4())
|
|
28
|
-
agent["_session_id"] = session_id
|
|
29
|
-
cmd = self._base_command(agent, mcp_config)
|
|
30
|
-
cmd.extend(["--session-id", session_id])
|
|
31
|
-
return cmd
|
|
32
|
-
|
|
33
|
-
def build_resume_command(
|
|
34
|
-
self,
|
|
35
|
-
agent_state: dict[str, Any],
|
|
36
|
-
workspace: Path,
|
|
37
|
-
mcp_config: dict[str, Any] | None = None,
|
|
38
|
-
) -> list[str]:
|
|
39
|
-
_ = workspace
|
|
40
|
-
session_id = agent_state.get("session_id")
|
|
41
|
-
if not session_id:
|
|
42
|
-
raise ResumeUnavailable("claude resume requires session_id")
|
|
43
|
-
if not self.session_is_resumable(agent_state, workspace):
|
|
44
|
-
diagnostics = self.session_lookup_diagnostics(agent_state, workspace)
|
|
45
|
-
raise ResumeUnavailable(
|
|
46
|
-
"claude resume transcript not found "
|
|
47
|
-
f"for session_id {session_id}; diagnostics={json.dumps(diagnostics, sort_keys=True)}"
|
|
48
|
-
)
|
|
49
|
-
agent = dict(agent_state.get("_agent_spec") or agent_state)
|
|
50
|
-
cmd = self._base_command(agent, mcp_config or {})
|
|
51
|
-
cmd.extend(["--resume", str(session_id)])
|
|
52
|
-
return cmd
|
|
53
|
-
|
|
54
|
-
def supports_session_fork(self, agent: dict[str, Any] | None = None) -> bool:
|
|
55
|
-
return not agent or agent.get("auth_mode") != "compatible_api"
|
|
56
|
-
|
|
57
|
-
def build_fork_command(
|
|
58
|
-
self,
|
|
59
|
-
agent: dict[str, Any],
|
|
60
|
-
source_session_id: str,
|
|
61
|
-
workspace: Path,
|
|
62
|
-
mcp_config: dict[str, Any],
|
|
63
|
-
) -> list[str]:
|
|
64
|
-
_ = workspace
|
|
65
|
-
if not source_session_id:
|
|
66
|
-
raise ResumeUnavailable("claude fork requires source session_id")
|
|
67
|
-
session_id = agent.get("_session_id") or str(uuid.uuid4())
|
|
68
|
-
agent["_session_id"] = session_id
|
|
69
|
-
cmd = self._base_command(agent, mcp_config)
|
|
70
|
-
cmd.extend(["--session-id", session_id, "--resume", str(source_session_id), "--fork-session"])
|
|
71
|
-
return cmd
|
|
72
|
-
|
|
73
|
-
def capture_session_id(
|
|
74
|
-
self,
|
|
75
|
-
agent_id: str,
|
|
76
|
-
spawn_context: dict[str, Any],
|
|
77
|
-
timeout_s: float = 3.0,
|
|
78
|
-
) -> dict[str, Any] | None:
|
|
79
|
-
cwd = spawn_context.get("cwd")
|
|
80
|
-
if not cwd:
|
|
81
|
-
return None
|
|
82
|
-
start = parse_time(spawn_context.get("spawn_time")) or datetime.now(timezone.utc)
|
|
83
|
-
root = Path(spawn_context.get("claude_projects_root") or Path.home() / ".claude" / "projects")
|
|
84
|
-
deadline = time.monotonic() + max(timeout_s, 0.0)
|
|
85
|
-
exclude = {str(item) for item in spawn_context.get("exclude_session_ids", []) if item}
|
|
86
|
-
predetermined = spawn_context.get("predetermined_session_id")
|
|
87
|
-
allow_older = bool(spawn_context.get("allow_older"))
|
|
88
|
-
while True:
|
|
89
|
-
match = find_claude_transcript(
|
|
90
|
-
root,
|
|
91
|
-
Path(str(cwd)),
|
|
92
|
-
start,
|
|
93
|
-
agent_id=agent_id,
|
|
94
|
-
predetermined_session_id=str(predetermined) if predetermined else None,
|
|
95
|
-
exclude_session_ids=exclude,
|
|
96
|
-
allow_older=allow_older,
|
|
97
|
-
)
|
|
98
|
-
if match:
|
|
99
|
-
return {
|
|
100
|
-
"session_id": match["session_id"],
|
|
101
|
-
"rollout_path": match["rollout_path"],
|
|
102
|
-
"captured_at": datetime.now(timezone.utc).isoformat(),
|
|
103
|
-
"captured_via": match["captured_via"],
|
|
104
|
-
"attribution_confidence": match["confidence"],
|
|
105
|
-
"spawn_cwd": str(cwd),
|
|
106
|
-
}
|
|
107
|
-
if spawn_context.get("auth_mode") == "compatible_api":
|
|
108
|
-
fallback = find_compatible_api_claude_transcript_fallback(root, Path(str(cwd)), start, agent_id)
|
|
109
|
-
if fallback:
|
|
110
|
-
return fallback
|
|
111
|
-
if time.monotonic() >= deadline:
|
|
112
|
-
return None
|
|
113
|
-
time.sleep(0.2)
|
|
114
|
-
|
|
115
|
-
def session_is_resumable(self, agent_state: dict[str, Any], workspace: Path) -> bool:
|
|
116
|
-
session_id = agent_state.get("session_id")
|
|
117
|
-
if not session_id:
|
|
118
|
-
return False
|
|
119
|
-
cwd = Path(str(agent_state.get("spawn_cwd") or workspace))
|
|
120
|
-
root = Path(agent_state.get("claude_projects_root") or Path.home() / ".claude" / "projects")
|
|
121
|
-
for path in claude_transcript_paths(root, cwd, str(session_id)):
|
|
122
|
-
meta = read_claude_transcript_meta(path, cwd)
|
|
123
|
-
if meta and meta.get("same_cwd") and meta.get("has_user_message"):
|
|
124
|
-
return True
|
|
125
|
-
return False
|
|
126
|
-
|
|
127
|
-
def session_lookup_diagnostics(self, agent_state: dict[str, Any], workspace: Path) -> dict[str, Any]:
|
|
128
|
-
session_id = str(agent_state.get("session_id") or "")
|
|
129
|
-
cwd = Path(str(agent_state.get("spawn_cwd") or workspace))
|
|
130
|
-
root = Path(agent_state.get("claude_projects_root") or Path.home() / ".claude" / "projects")
|
|
131
|
-
paths = claude_transcript_paths(root, cwd, session_id) if session_id else []
|
|
132
|
-
return {
|
|
133
|
-
"provider": self.provider,
|
|
134
|
-
"expected_session_id": session_id,
|
|
135
|
-
"spawn_cwd": str(cwd),
|
|
136
|
-
"claude_projects_root": str(root),
|
|
137
|
-
"encoded_dir_claude_actual": claude_project_dir(root, cwd).name,
|
|
138
|
-
"encoded_dir_team_agent_legacy": claude_legacy_project_dir(root, cwd).name,
|
|
139
|
-
"transcript_paths_checked": [str(path) for path in paths],
|
|
140
|
-
"path_exists": {str(path): path.exists() for path in paths},
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
def recover_session_id(
|
|
144
|
-
self,
|
|
145
|
-
agent_id: str,
|
|
146
|
-
agent_state: dict[str, Any],
|
|
147
|
-
workspace: Path,
|
|
148
|
-
exclude_session_ids: set[str] | None = None,
|
|
149
|
-
) -> dict[str, Any] | None:
|
|
150
|
-
cwd = Path(str(agent_state.get("spawn_cwd") or workspace))
|
|
151
|
-
root = Path(agent_state.get("claude_projects_root") or Path.home() / ".claude" / "projects")
|
|
152
|
-
pending_session_id = agent_state.get("_pending_session_id")
|
|
153
|
-
match = find_claude_transcript(
|
|
154
|
-
root,
|
|
155
|
-
cwd,
|
|
156
|
-
parse_time(agent_state.get("spawned_at")) or datetime.fromtimestamp(0, timezone.utc),
|
|
157
|
-
agent_id=agent_id,
|
|
158
|
-
predetermined_session_id=str(pending_session_id) if pending_session_id else None,
|
|
159
|
-
exclude_session_ids=exclude_session_ids or set(),
|
|
160
|
-
allow_older=True,
|
|
161
|
-
require_agent_match=True,
|
|
162
|
-
require_cwd=True,
|
|
163
|
-
)
|
|
164
|
-
if not match:
|
|
165
|
-
return None
|
|
166
|
-
return {
|
|
167
|
-
"session_id": match["session_id"],
|
|
168
|
-
"rollout_path": match["rollout_path"],
|
|
169
|
-
"captured_at": datetime.now(timezone.utc).isoformat(),
|
|
170
|
-
"captured_via": "fs_repair",
|
|
171
|
-
"attribution_confidence": match["confidence"],
|
|
172
|
-
"spawn_cwd": str(cwd),
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
def _base_command(self, agent: dict[str, Any], mcp_config: dict[str, Any]) -> list[str]:
|
|
176
|
-
prompt = compile_system_prompt(agent)
|
|
177
|
-
cmd = ["claude"]
|
|
178
|
-
if agent.get("_runtime", {}).get("dangerous_auto_approve"):
|
|
179
|
-
cmd.append("--dangerously-skip-permissions")
|
|
180
|
-
else:
|
|
181
|
-
cmd.extend(["--permission-mode", "default"])
|
|
182
|
-
model = agent_model(agent)
|
|
183
|
-
if model:
|
|
184
|
-
cmd.extend(["--model", model])
|
|
185
|
-
if prompt:
|
|
186
|
-
cmd.extend(["--append-system-prompt", prompt])
|
|
187
|
-
if mcp_config:
|
|
188
|
-
managed_compatible_config = (
|
|
189
|
-
agent.get("auth_mode") == "compatible_api"
|
|
190
|
-
and bool(agent.get("_provider_profile", {}).get("claude_projects_root"))
|
|
191
|
-
)
|
|
192
|
-
if not managed_compatible_config:
|
|
193
|
-
cmd.extend(["--mcp-config", json.dumps({"mcpServers": mcp_config})])
|
|
194
|
-
cmd.append("--strict-mcp-config")
|
|
195
|
-
allowed = set(resolve_permissions(agent)["tools"])
|
|
196
|
-
disallowed = claude_disallowed_tools(allowed)
|
|
197
|
-
for tool in disallowed:
|
|
198
|
-
cmd.extend(["--disallowedTools", tool])
|
|
199
|
-
return cmd
|
|
200
|
-
|
|
201
|
-
def auth_hint(self) -> dict[str, Any]:
|
|
202
|
-
if not self.is_installed():
|
|
203
|
-
return {"status": "missing", "detail": "claude command not found"}
|
|
204
|
-
try:
|
|
205
|
-
proc = subprocess.run(
|
|
206
|
-
["claude", "auth", "status"],
|
|
207
|
-
text=True,
|
|
208
|
-
capture_output=True,
|
|
209
|
-
timeout=8,
|
|
210
|
-
check=False,
|
|
211
|
-
)
|
|
212
|
-
except (OSError, subprocess.TimeoutExpired) as exc:
|
|
213
|
-
return {"status": "missing_or_unknown", "detail": f"claude auth status failed: {exc}"}
|
|
214
|
-
text = (proc.stdout or proc.stderr).strip()
|
|
215
|
-
try:
|
|
216
|
-
status = json.loads(text) if text else {}
|
|
217
|
-
except json.JSONDecodeError:
|
|
218
|
-
status = {}
|
|
219
|
-
if status.get("loggedIn") is True or proc.returncode == 0:
|
|
220
|
-
method = status.get("authMethod") or "configured"
|
|
221
|
-
return {"status": "present", "detail": f"claude auth status ok: {method}"}
|
|
222
|
-
return {"status": "missing", "detail": text or "run claude auth login or claude setup-token"}
|
|
223
|
-
|
|
224
|
-
def status_patterns(self) -> dict[str, str]:
|
|
225
|
-
return {"idle": r"[>❯]\s", "processing": r"[✶✢✽✻✳·].*…", "error": "Error|Traceback"}
|
|
226
|
-
|
|
227
|
-
def handle_startup_prompts(
|
|
228
|
-
self,
|
|
229
|
-
session_name: str,
|
|
230
|
-
window_name: str,
|
|
231
|
-
checks: int = 30,
|
|
232
|
-
sleep_s: float = 0.5,
|
|
233
|
-
) -> list[dict[str, Any]]:
|
|
234
|
-
handled: list[dict[str, Any]] = []
|
|
235
|
-
target = f"{session_name}:{window_name}"
|
|
236
|
-
for _ in range(max(checks, 0)):
|
|
237
|
-
proc = subprocess.run(
|
|
238
|
-
["tmux", "capture-pane", "-p", "-S", "-", "-t", target],
|
|
239
|
-
text=True,
|
|
240
|
-
capture_output=True,
|
|
241
|
-
timeout=5,
|
|
242
|
-
check=False,
|
|
243
|
-
)
|
|
244
|
-
output = proc.stdout if proc.returncode == 0 else ""
|
|
245
|
-
if "Quick safety check" in output or "Yes, I trust this folder" in output:
|
|
246
|
-
subprocess.run(["tmux", "send-keys", "-t", target, "Enter"], check=False)
|
|
247
|
-
handled.append({"prompt": "claude_workspace_trust", "action": "sent_enter"})
|
|
248
|
-
break
|
|
249
|
-
if "Claude Code" in output and ("❯" in output or ">" in output):
|
|
250
|
-
break
|
|
251
|
-
if sleep_s > 0:
|
|
252
|
-
time.sleep(sleep_s)
|
|
253
|
-
return handled
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
def claude_disallowed_tools(allowed: set[str]) -> list[str]:
|
|
257
|
-
mapping = {
|
|
258
|
-
"execute_bash": ["Bash"],
|
|
259
|
-
"fs_read": ["Read"],
|
|
260
|
-
"fs_write": ["Edit", "Write", "MultiEdit", "NotebookEdit"],
|
|
261
|
-
"fs_list": ["Glob", "Grep"],
|
|
262
|
-
}
|
|
263
|
-
disallowed: list[str] = []
|
|
264
|
-
for canonical, native in mapping.items():
|
|
265
|
-
if canonical not in allowed:
|
|
266
|
-
disallowed.extend(native)
|
|
267
|
-
return disallowed
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
def find_claude_transcript(
|
|
271
|
-
root: Path,
|
|
272
|
-
cwd: Path,
|
|
273
|
-
spawn_time: datetime,
|
|
274
|
-
*,
|
|
275
|
-
agent_id: str,
|
|
276
|
-
predetermined_session_id: str | None,
|
|
277
|
-
exclude_session_ids: set[str] | None = None,
|
|
278
|
-
allow_older: bool = False,
|
|
279
|
-
require_agent_match: bool = False,
|
|
280
|
-
require_cwd: bool = True,
|
|
281
|
-
) -> dict[str, Any] | None:
|
|
282
|
-
if not root.exists():
|
|
283
|
-
return None
|
|
284
|
-
exclude_session_ids = exclude_session_ids or set()
|
|
285
|
-
if predetermined_session_id and predetermined_session_id not in exclude_session_ids:
|
|
286
|
-
for path in claude_transcript_paths(root, cwd, predetermined_session_id):
|
|
287
|
-
meta = read_claude_transcript_meta(path, cwd)
|
|
288
|
-
if meta and (not require_cwd or meta.get("same_cwd")) and meta.get("has_user_message"):
|
|
289
|
-
return {
|
|
290
|
-
"session_id": str(predetermined_session_id),
|
|
291
|
-
"rollout_path": str(path),
|
|
292
|
-
"timestamp": meta.get("timestamp") or datetime.fromtimestamp(path.stat().st_mtime, timezone.utc),
|
|
293
|
-
"captured_via": "fs_watch",
|
|
294
|
-
"confidence": "high",
|
|
295
|
-
}
|
|
296
|
-
lower_bound = spawn_time - timedelta(seconds=2)
|
|
297
|
-
upper_bound = datetime.now(timezone.utc) + timedelta(seconds=5)
|
|
298
|
-
candidates: list[dict[str, Any]] = []
|
|
299
|
-
for directory in claude_project_dirs(root, cwd):
|
|
300
|
-
for path in sorted(directory.glob("*.jsonl"), key=lambda p: p.stat().st_mtime, reverse=True)[:300]:
|
|
301
|
-
meta = read_claude_transcript_meta(path, cwd)
|
|
302
|
-
if not meta or not meta.get("has_user_message"):
|
|
303
|
-
continue
|
|
304
|
-
if require_cwd and not meta.get("same_cwd"):
|
|
305
|
-
continue
|
|
306
|
-
session_id = str(meta.get("session_id") or path.stem)
|
|
307
|
-
if session_id in exclude_session_ids:
|
|
308
|
-
continue
|
|
309
|
-
ts = meta.get("timestamp") or datetime.fromtimestamp(path.stat().st_mtime, timezone.utc)
|
|
310
|
-
if not allow_older and (ts < lower_bound or ts > upper_bound):
|
|
311
|
-
continue
|
|
312
|
-
text = str(meta.get("text") or "")
|
|
313
|
-
score = claude_agent_match_score(agent_id, text)
|
|
314
|
-
if require_agent_match and score < 2:
|
|
315
|
-
continue
|
|
316
|
-
if score <= 0 and not allow_older:
|
|
317
|
-
continue
|
|
318
|
-
candidates.append(
|
|
319
|
-
{
|
|
320
|
-
"session_id": session_id,
|
|
321
|
-
"rollout_path": str(path),
|
|
322
|
-
"timestamp": ts,
|
|
323
|
-
"captured_via": "fs_watch",
|
|
324
|
-
"confidence": "high" if score >= 2 else "medium",
|
|
325
|
-
"score": score,
|
|
326
|
-
}
|
|
327
|
-
)
|
|
328
|
-
if not candidates:
|
|
329
|
-
return None
|
|
330
|
-
candidates.sort(key=lambda item: (item["score"], item["timestamp"]), reverse=True)
|
|
331
|
-
return candidates[0]
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
def find_compatible_api_claude_transcript_fallback(
|
|
335
|
-
root: Path,
|
|
336
|
-
cwd: Path,
|
|
337
|
-
spawn_time: datetime,
|
|
338
|
-
agent_id: str,
|
|
339
|
-
) -> dict[str, Any] | None:
|
|
340
|
-
_ = agent_id
|
|
341
|
-
if not root.exists():
|
|
342
|
-
return None
|
|
343
|
-
lower_bound = spawn_time - timedelta(seconds=5)
|
|
344
|
-
upper_bound = datetime.now(timezone.utc)
|
|
345
|
-
candidates: list[Path] = []
|
|
346
|
-
for directory in claude_project_dirs(root, cwd):
|
|
347
|
-
try:
|
|
348
|
-
candidates.extend(path for path in directory.glob("*.jsonl") if path.is_file())
|
|
349
|
-
except OSError:
|
|
350
|
-
continue
|
|
351
|
-
try:
|
|
352
|
-
ordered = sorted(candidates, key=lambda p: p.stat().st_mtime, reverse=True)[:5]
|
|
353
|
-
except OSError:
|
|
354
|
-
return None
|
|
355
|
-
for path in ordered:
|
|
356
|
-
try:
|
|
357
|
-
stat = path.stat()
|
|
358
|
-
except OSError:
|
|
359
|
-
continue
|
|
360
|
-
if stat.st_size <= 0:
|
|
361
|
-
continue
|
|
362
|
-
timestamp = datetime.fromtimestamp(stat.st_mtime, timezone.utc)
|
|
363
|
-
if timestamp < lower_bound or timestamp > upper_bound:
|
|
364
|
-
continue
|
|
365
|
-
return {
|
|
366
|
-
"session_id": None,
|
|
367
|
-
"rollout_path": str(path),
|
|
368
|
-
"captured_at": datetime.now(timezone.utc).isoformat(),
|
|
369
|
-
"captured_via": "fs_mtime_fallback",
|
|
370
|
-
"attribution_confidence": "low",
|
|
371
|
-
"spawn_cwd": str(cwd),
|
|
372
|
-
}
|
|
373
|
-
return None
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
def claude_project_dirs(root: Path, cwd: Path) -> list[Path]:
|
|
377
|
-
return [directory for directory in _unique_paths([claude_project_dir(root, cwd), claude_legacy_project_dir(root, cwd)]) if directory.exists()]
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
def claude_project_dir(root: Path, cwd: Path) -> Path:
|
|
381
|
-
try:
|
|
382
|
-
cwd_text = str(cwd.resolve())
|
|
383
|
-
except OSError:
|
|
384
|
-
cwd_text = str(cwd)
|
|
385
|
-
return root / re.sub(r"[^A-Za-z0-9.-]", "-", cwd_text)
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
def claude_legacy_project_dir(root: Path, cwd: Path) -> Path:
|
|
389
|
-
try:
|
|
390
|
-
cwd_text = str(cwd.resolve())
|
|
391
|
-
except OSError:
|
|
392
|
-
cwd_text = str(cwd)
|
|
393
|
-
return root / re.sub(r"[^A-Za-z0-9._-]", "-", cwd_text)
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
def claude_transcript_path(root: Path, cwd: Path, session_id: str) -> Path:
|
|
397
|
-
return claude_project_dir(root, cwd) / f"{session_id}.jsonl"
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
def claude_transcript_paths(root: Path, cwd: Path, session_id: str) -> list[Path]:
|
|
401
|
-
if not session_id:
|
|
402
|
-
return []
|
|
403
|
-
return _unique_paths(
|
|
404
|
-
[
|
|
405
|
-
claude_project_dir(root, cwd) / f"{session_id}.jsonl",
|
|
406
|
-
claude_legacy_project_dir(root, cwd) / f"{session_id}.jsonl",
|
|
407
|
-
]
|
|
408
|
-
)
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
def _unique_paths(paths: list[Path]) -> list[Path]:
|
|
412
|
-
seen: set[str] = set()
|
|
413
|
-
result: list[Path] = []
|
|
414
|
-
for path in paths:
|
|
415
|
-
key = str(path)
|
|
416
|
-
if key in seen:
|
|
417
|
-
continue
|
|
418
|
-
seen.add(key)
|
|
419
|
-
result.append(path)
|
|
420
|
-
return result
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
def read_claude_transcript_meta(path: Path, cwd: Path | None = None) -> dict[str, Any] | None:
|
|
424
|
-
if not path.exists():
|
|
425
|
-
return None
|
|
426
|
-
session_id: str | None = None
|
|
427
|
-
transcript_cwd: str | None = None
|
|
428
|
-
timestamp: datetime | None = None
|
|
429
|
-
has_user_message = False
|
|
430
|
-
text_parts: list[str] = []
|
|
431
|
-
try:
|
|
432
|
-
with path.open(encoding="utf-8") as handle:
|
|
433
|
-
for index, line in enumerate(handle):
|
|
434
|
-
if index >= 200:
|
|
435
|
-
break
|
|
436
|
-
try:
|
|
437
|
-
data = json.loads(line)
|
|
438
|
-
except json.JSONDecodeError:
|
|
439
|
-
continue
|
|
440
|
-
if not session_id and data.get("sessionId"):
|
|
441
|
-
session_id = str(data.get("sessionId"))
|
|
442
|
-
if not transcript_cwd and data.get("cwd"):
|
|
443
|
-
transcript_cwd = str(data.get("cwd"))
|
|
444
|
-
timestamp = timestamp or parse_time(data.get("timestamp"))
|
|
445
|
-
if data.get("type") == "user":
|
|
446
|
-
text = claude_message_text(data.get("message", {}).get("content"))
|
|
447
|
-
if text.strip():
|
|
448
|
-
has_user_message = True
|
|
449
|
-
if sum(len(part) for part in text_parts) < 8000:
|
|
450
|
-
text_parts.append(text[:4000])
|
|
451
|
-
except OSError:
|
|
452
|
-
return None
|
|
453
|
-
same_cwd = True
|
|
454
|
-
if cwd is not None:
|
|
455
|
-
same_cwd = _same_path(transcript_cwd, cwd)
|
|
456
|
-
return {
|
|
457
|
-
"session_id": session_id or path.stem,
|
|
458
|
-
"cwd": transcript_cwd,
|
|
459
|
-
"same_cwd": same_cwd,
|
|
460
|
-
"timestamp": timestamp,
|
|
461
|
-
"has_user_message": has_user_message,
|
|
462
|
-
"text": "\n".join(text_parts),
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
def claude_message_text(content: Any) -> str:
|
|
467
|
-
if isinstance(content, str):
|
|
468
|
-
return content
|
|
469
|
-
if isinstance(content, list):
|
|
470
|
-
parts: list[str] = []
|
|
471
|
-
for item in content:
|
|
472
|
-
if isinstance(item, dict) and isinstance(item.get("text"), str):
|
|
473
|
-
parts.append(item["text"])
|
|
474
|
-
elif isinstance(item, dict) and isinstance(item.get("content"), str):
|
|
475
|
-
parts.append(item["content"])
|
|
476
|
-
return "\n".join(parts)
|
|
477
|
-
return ""
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
def claude_agent_match_score(agent_id: str, text: str) -> int:
|
|
481
|
-
if not agent_id:
|
|
482
|
-
return 0
|
|
483
|
-
lowered = text.lower()
|
|
484
|
-
agent = agent_id.lower()
|
|
485
|
-
score = 0
|
|
486
|
-
if f"agents/{agent}.md" in lowered or f"agents\\/{agent}.md" in lowered:
|
|
487
|
-
score += 1
|
|
488
|
-
if f"team_agent_id={agent}" in lowered or f"team_agent_id={agent_id}" in text:
|
|
489
|
-
score += 2
|
|
490
|
-
if f"your agent id: {agent}" in lowered:
|
|
491
|
-
score += 2
|
|
492
|
-
if f"team agent worker {agent}" in lowered or f"worker `{agent}`" in lowered:
|
|
493
|
-
score += 2
|
|
494
|
-
return score
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
def _same_path(value: str | None, path: Path) -> bool:
|
|
498
|
-
if not value:
|
|
499
|
-
return True
|
|
500
|
-
try:
|
|
501
|
-
return Path(value).resolve() == path.resolve()
|
|
502
|
-
except OSError:
|
|
503
|
-
return str(value) == str(path)
|