mycode-coding-agent 0.1.0__py3-none-any.whl
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.
- mycode/__init__.py +0 -0
- mycode/adapters/__init__.py +21 -0
- mycode/adapters/jsonl.py +692 -0
- mycode/agent/__init__.py +25 -0
- mycode/agent/events.py +111 -0
- mycode/agent/outcome.py +103 -0
- mycode/agent/progress.py +373 -0
- mycode/agent/runner.py +1481 -0
- mycode/application/__init__.py +38 -0
- mycode/application/agent_session.py +367 -0
- mycode/application/events.py +59 -0
- mycode/application/runtime.py +211 -0
- mycode/application/sessions.py +180 -0
- mycode/cli.py +840 -0
- mycode/config.py +355 -0
- mycode/context/__init__.py +1 -0
- mycode/context/artifacts.py +672 -0
- mycode/context/budget.py +752 -0
- mycode/context/builder.py +112 -0
- mycode/context/compact.py +795 -0
- mycode/context/tool_result_format.py +199 -0
- mycode/context/tool_result_retention.py +261 -0
- mycode/conversation.py +78 -0
- mycode/error_handling.py +481 -0
- mycode/event_format.py +147 -0
- mycode/instructions.py +285 -0
- mycode/llm.py +771 -0
- mycode/mcp/__init__.py +41 -0
- mycode/mcp/client.py +44 -0
- mycode/mcp/config.py +207 -0
- mycode/mcp/errors.py +302 -0
- mycode/mcp/manager.py +339 -0
- mycode/mcp/models.py +20 -0
- mycode/mcp/result_adapter.py +58 -0
- mycode/mcp/tool_adapter.py +145 -0
- mycode/mcp/trust.py +313 -0
- mycode/memory.py +570 -0
- mycode/memory_context.py +245 -0
- mycode/messages.py +63 -0
- mycode/observability.py +28 -0
- mycode/permissions.py +262 -0
- mycode/persistence/__init__.py +1 -0
- mycode/persistence/filesystem.py +291 -0
- mycode/persistence/project_storage.py +208 -0
- mycode/persistence/session_lock.py +138 -0
- mycode/persistence/session_store.py +503 -0
- mycode/presentation/__init__.py +1 -0
- mycode/presentation/cli/__init__.py +14 -0
- mycode/presentation/cli/confirmer.py +116 -0
- mycode/presentation/cli/mcp_trust.py +61 -0
- mycode/presentation/cli/presenter.py +320 -0
- mycode/presentation/cli/session_menu.py +146 -0
- mycode/presentation/cli/subagent_observer.py +124 -0
- mycode/presentation/command_format.py +90 -0
- mycode/presentation/commands.py +95 -0
- mycode/presentation/tui/__init__.py +6 -0
- mycode/presentation/tui/app.py +1351 -0
- mycode/presentation/tui/interactions.py +253 -0
- mycode/presentation/tui/presenter.py +266 -0
- mycode/presentation/tui/screens.py +305 -0
- mycode/presentation/tui/widgets.py +214 -0
- mycode/project.py +22 -0
- mycode/prompts.py +181 -0
- mycode/reasoning.py +40 -0
- mycode/session.py +86 -0
- mycode/skills/__init__.py +27 -0
- mycode/skills/builtin/database-recovery/SKILL.md +138 -0
- mycode/skills/builtin/database-recovery/references/sqlite.md +235 -0
- mycode/skills/registry.py +295 -0
- mycode/skills/state.py +68 -0
- mycode/subagents/__init__.py +1 -0
- mycode/subagents/audit.py +212 -0
- mycode/subagents/concurrency.py +124 -0
- mycode/subagents/contracts.py +421 -0
- mycode/subagents/delegate.py +80 -0
- mycode/subagents/delegation.py +128 -0
- mycode/subagents/lifecycle.py +86 -0
- mycode/subagents/limits.py +7 -0
- mycode/subagents/observability.py +150 -0
- mycode/subagents/persistence.py +152 -0
- mycode/subagents/profiles.py +184 -0
- mycode/subagents/prompts.py +67 -0
- mycode/subagents/results.py +178 -0
- mycode/subagents/runtime.py +528 -0
- mycode/subagents/snapshots.py +211 -0
- mycode/subagents/tool_batch.py +260 -0
- mycode/tools/__init__.py +81 -0
- mycode/tools/base.py +222 -0
- mycode/tools/bounds.py +14 -0
- mycode/tools/command_executor.py +167 -0
- mycode/tools/command_output.py +166 -0
- mycode/tools/command_risk.py +596 -0
- mycode/tools/defaults.py +59 -0
- mycode/tools/edit_file.py +524 -0
- mycode/tools/file_mutation.py +30 -0
- mycode/tools/glob.py +247 -0
- mycode/tools/grep.py +324 -0
- mycode/tools/ignore.py +122 -0
- mycode/tools/inspect_changes.py +269 -0
- mycode/tools/load_skill.py +92 -0
- mycode/tools/memory.py +264 -0
- mycode/tools/path_permissions.py +78 -0
- mycode/tools/patterns.py +48 -0
- mycode/tools/permission_metadata.py +27 -0
- mycode/tools/process_tree.py +166 -0
- mycode/tools/read_file.py +242 -0
- mycode/tools/read_skill_resource.py +93 -0
- mycode/tools/registry.py +279 -0
- mycode/tools/run_command.py +237 -0
- mycode/tools/run_skill_script.py +206 -0
- mycode/tools/run_validation.py +107 -0
- mycode/tools/submit_result.py +93 -0
- mycode/tools/text.py +15 -0
- mycode/tools/validation_command.py +377 -0
- mycode/tools/workspace.py +33 -0
- mycode/tools/write_file.py +169 -0
- mycode_coding_agent-0.1.0.dist-info/METADATA +244 -0
- mycode_coding_agent-0.1.0.dist-info/RECORD +121 -0
- mycode_coding_agent-0.1.0.dist-info/WHEEL +4 -0
- mycode_coding_agent-0.1.0.dist-info/entry_points.txt +2 -0
- mycode_coding_agent-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""One-way model context construction shared by Agent and Chat."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, replace
|
|
4
|
+
from typing import Literal
|
|
5
|
+
|
|
6
|
+
from mycode.context.budget import (
|
|
7
|
+
ContextBudget,
|
|
8
|
+
MemoryContextStats,
|
|
9
|
+
ModelContext,
|
|
10
|
+
TokenEstimator,
|
|
11
|
+
TokenUsage,
|
|
12
|
+
budget_model_context,
|
|
13
|
+
)
|
|
14
|
+
from mycode.context.compact import ConversationCompactor
|
|
15
|
+
from mycode.conversation import Conversation
|
|
16
|
+
from mycode.messages import Message
|
|
17
|
+
from mycode.context.tool_result_retention import ToolResultRetentionPolicy, TurnLocalFullGroup
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True)
|
|
21
|
+
class ContextBuildResult:
|
|
22
|
+
context: ModelContext
|
|
23
|
+
compact_attempt_token_usage: TokenUsage | None = None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
ContextCompactionMode = Literal["auto", "preview", "force"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class ContextBuilder:
|
|
31
|
+
budget: ContextBudget
|
|
32
|
+
token_estimator: TokenEstimator
|
|
33
|
+
compactor: ConversationCompactor | None = None
|
|
34
|
+
retention_policy: ToolResultRetentionPolicy | None = None
|
|
35
|
+
|
|
36
|
+
def build(
|
|
37
|
+
self,
|
|
38
|
+
conversation: Conversation,
|
|
39
|
+
*,
|
|
40
|
+
tools: list[dict[str, object]] | None = None,
|
|
41
|
+
memory_message: Message | None = None,
|
|
42
|
+
memory_stats: MemoryContextStats | None = None,
|
|
43
|
+
guidance: tuple[str, ...] = (),
|
|
44
|
+
request_messages: tuple[Message, ...] = (),
|
|
45
|
+
persistent_system_messages: tuple[Message, ...] = (),
|
|
46
|
+
turn_local_full_group: TurnLocalFullGroup | None = None,
|
|
47
|
+
observability_turn: int | None = None,
|
|
48
|
+
compaction_mode: ContextCompactionMode = "auto",
|
|
49
|
+
) -> ContextBuildResult:
|
|
50
|
+
"""Project tool retention, Compact, assemble this request, then budget once.
|
|
51
|
+
|
|
52
|
+
Persistent system messages are request-scoped but visible to Compact's
|
|
53
|
+
trigger. Guidance and request messages remain invisible to Compact. An
|
|
54
|
+
over-budget result is returned to the caller, which must not send it.
|
|
55
|
+
"""
|
|
56
|
+
projection = None
|
|
57
|
+
if self.retention_policy is not None:
|
|
58
|
+
projection = self.retention_policy.project(
|
|
59
|
+
conversation, turn_local_full_group=turn_local_full_group,
|
|
60
|
+
)
|
|
61
|
+
conversation = projection.conversation
|
|
62
|
+
if any(message.role != "system" for message in persistent_system_messages):
|
|
63
|
+
raise ValueError("persistent_system_messages must use the system role.")
|
|
64
|
+
if persistent_system_messages:
|
|
65
|
+
conversation = Conversation.from_messages(
|
|
66
|
+
[*conversation.get_messages(), *persistent_system_messages]
|
|
67
|
+
)
|
|
68
|
+
compact_stats = None
|
|
69
|
+
compact_usage = None
|
|
70
|
+
if self.compactor is not None:
|
|
71
|
+
if compaction_mode == "preview":
|
|
72
|
+
prepared = self.compactor.preview(
|
|
73
|
+
conversation,
|
|
74
|
+
self.budget,
|
|
75
|
+
tools=tools,
|
|
76
|
+
token_estimator=self.token_estimator,
|
|
77
|
+
memory_message=memory_message,
|
|
78
|
+
)
|
|
79
|
+
else:
|
|
80
|
+
prepared = self.compactor.prepare(
|
|
81
|
+
conversation,
|
|
82
|
+
self.budget,
|
|
83
|
+
tools=tools,
|
|
84
|
+
token_estimator=self.token_estimator,
|
|
85
|
+
memory_message=memory_message,
|
|
86
|
+
observability_turn=observability_turn,
|
|
87
|
+
force=compaction_mode == "force",
|
|
88
|
+
)
|
|
89
|
+
conversation = prepared.conversation
|
|
90
|
+
compact_stats = prepared.stats
|
|
91
|
+
compact_usage = prepared.attempt_token_usage
|
|
92
|
+
|
|
93
|
+
messages = list(conversation.get_messages())
|
|
94
|
+
if memory_message is not None:
|
|
95
|
+
messages.append(memory_message)
|
|
96
|
+
if guidance:
|
|
97
|
+
messages.append(Message(role="system", content="\n\n".join(guidance)))
|
|
98
|
+
messages.extend(request_messages)
|
|
99
|
+
context = budget_model_context(
|
|
100
|
+
tuple(messages),
|
|
101
|
+
self.budget,
|
|
102
|
+
tools=tools,
|
|
103
|
+
token_estimator=self.token_estimator,
|
|
104
|
+
memory_message=memory_message,
|
|
105
|
+
memory_stats=memory_stats,
|
|
106
|
+
retention_policy=self.retention_policy,
|
|
107
|
+
retention_projection=projection,
|
|
108
|
+
)
|
|
109
|
+
return ContextBuildResult(
|
|
110
|
+
context=replace(context, compact_stats=compact_stats),
|
|
111
|
+
compact_attempt_token_usage=compact_usage,
|
|
112
|
+
)
|