pythinker-code 0.57.0__py3-none-any.whl → 0.58.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.
Files changed (109) hide show
  1. pythinker_code/CHANGELOG.md +47 -0
  2. pythinker_code/agents/default/system.md +1 -1
  3. pythinker_code/agentspec.py +171 -11
  4. pythinker_code/benchmark/toolset_characterization.py +1118 -0
  5. pythinker_code/cli/system_prompt.py +2 -1
  6. pythinker_code/skill/__init__.py +139 -8
  7. pythinker_code/skill/catalog.py +509 -0
  8. pythinker_code/soul/agent.py +168 -69
  9. pythinker_code/soul/btw.py +35 -10
  10. pythinker_code/soul/compaction_restore.py +3 -3
  11. pythinker_code/soul/context.py +871 -220
  12. pythinker_code/soul/dynamic_injection.py +120 -80
  13. pythinker_code/soul/dynamic_injections/agent_list.py +2 -1
  14. pythinker_code/soul/dynamic_injections/model_defense.py +47 -12
  15. pythinker_code/soul/dynamic_injections/permissions_state.py +60 -9
  16. pythinker_code/soul/pythinkersoul.py +473 -188
  17. pythinker_code/soul/request_assembly.py +770 -0
  18. pythinker_code/soul/request_lifecycle.py +481 -0
  19. pythinker_code/soul/request_primitives.py +34 -0
  20. pythinker_code/soul/slash.py +64 -2
  21. pythinker_code/soul/toolset.py +14 -5
  22. pythinker_code/subagents/catalogue.py +398 -0
  23. pythinker_code/subagents/discovery.py +139 -22
  24. pythinker_code/subagents/runner.py +6 -2
  25. pythinker_code/telemetry/metrics.py +47 -0
  26. pythinker_code/tools/agent/__init__.py +19 -14
  27. pythinker_code/tools/skill/__init__.py +29 -10
  28. pythinker_code/ui/shell/slash.py +3 -2
  29. pythinker_code/ui/shell/visualize/_activity_tree.py +2 -5
  30. pythinker_code/ui/shell/visualize/_blocks.py +55 -2
  31. pythinker_code/utils/frontmatter.py +14 -3
  32. pythinker_code/web/static/assets/architecture-7EHR7CIX-S-vCW5iB.js +1 -0
  33. pythinker_code/web/static/assets/{architectureDiagram-3BPJPVTR-CMjTHbQr.js → architectureDiagram-3BPJPVTR-DNjSUgP8.js} +1 -1
  34. pythinker_code/web/static/assets/{blockDiagram-GPEHLZMM-DbNV66qZ.js → blockDiagram-GPEHLZMM-Bj6WF362.js} +1 -1
  35. pythinker_code/web/static/assets/{bootstrap-DHJiVjsg.js → bootstrap-DPOVLodG.js} +5 -5
  36. pythinker_code/web/static/assets/{c4Diagram-AAUBKEIU-_L7KfhiY.js → c4Diagram-AAUBKEIU-GGQSrWG4.js} +1 -1
  37. pythinker_code/web/static/assets/channel-BF4DnhOY.js +1 -0
  38. pythinker_code/web/static/assets/{chunk-2J33WTMH-Dsc-vkPL.js → chunk-2J33WTMH-OsiI6Shl.js} +1 -1
  39. pythinker_code/web/static/assets/{chunk-3OPIFGDE-DkPxKRGJ.js → chunk-3OPIFGDE-BT9LH4XF.js} +1 -1
  40. pythinker_code/web/static/assets/{chunk-5ZQYHXKU-DKsi-Xj_.js → chunk-5ZQYHXKU-BKI-R690.js} +1 -1
  41. pythinker_code/web/static/assets/{chunk-727SXJPM-DusG3GJh.js → chunk-727SXJPM-zD8K6bZU.js} +1 -1
  42. pythinker_code/web/static/assets/{chunk-AQP2D5EJ-F4_a1a4u.js → chunk-AQP2D5EJ-C8-RqfOY.js} +1 -1
  43. pythinker_code/web/static/assets/{chunk-CSCIHK7Q-9L6bDdXh.js → chunk-CSCIHK7Q-DauLS_KO.js} +1 -1
  44. pythinker_code/web/static/assets/{chunk-JAPRZBRM-BavSbd1t.js → chunk-JAPRZBRM-B3vK8rJr.js} +4 -4
  45. pythinker_code/web/static/assets/{chunk-KSCS5N6A-D9NmS9a_.js → chunk-KSCS5N6A-q_c8Otyz.js} +1 -1
  46. pythinker_code/web/static/assets/{chunk-L5ZTLDWV-BSMfQ2IM.js → chunk-L5ZTLDWV-L38JietD.js} +1 -1
  47. pythinker_code/web/static/assets/{chunk-LZXEDZCA-r4sJTTgY.js → chunk-LZXEDZCA-JUzQ08Fk.js} +2 -2
  48. pythinker_code/web/static/assets/{chunk-ND2GUHAM-BL7ERbud.js → chunk-ND2GUHAM-B7lN__eE.js} +1 -1
  49. pythinker_code/web/static/assets/{chunk-NZK2D7GU-G9jWyqp3.js → chunk-NZK2D7GU-MT98-VRd.js} +1 -1
  50. pythinker_code/web/static/assets/{chunk-O5CBEL6O-QBSTZ593.js → chunk-O5CBEL6O-HS6UvO8l.js} +1 -1
  51. pythinker_code/web/static/assets/{chunk-WU5MYG2G-DYANwips.js → chunk-WU5MYG2G-2FStZlKC.js} +1 -1
  52. pythinker_code/web/static/assets/classDiagram-4FO5ZUOK-bQ8c0gns.js +1 -0
  53. pythinker_code/web/static/assets/classDiagram-v2-Q7XG4LA2-bQ8c0gns.js +1 -0
  54. pythinker_code/web/static/assets/{code-block-IT6T5CEO-uNhBh7Jk.js → code-block-IT6T5CEO-CSd98pzb.js} +1 -1
  55. pythinker_code/web/static/assets/{dagre-BM42HDAG-Cb91t8pu.js → dagre-BM42HDAG-CRsWJlJl.js} +1 -1
  56. pythinker_code/web/static/assets/{diagram-2AECGRRQ-CLZIVQzB.js → diagram-2AECGRRQ-x6OaKKPB.js} +1 -1
  57. pythinker_code/web/static/assets/{diagram-5GNKFQAL-B6DPBt7v.js → diagram-5GNKFQAL-DC8c6FnZ.js} +1 -1
  58. pythinker_code/web/static/assets/{diagram-KO2AKTUF-vb7QYejh.js → diagram-KO2AKTUF-B7qc5yfP.js} +1 -1
  59. pythinker_code/web/static/assets/{diagram-LMA3HP47-DdFQHXp3.js → diagram-LMA3HP47-BFPLlnJr.js} +1 -1
  60. pythinker_code/web/static/assets/{diagram-OG6HWLK6-nJ1_wWcq.js → diagram-OG6HWLK6-B-WnMmPG.js} +1 -1
  61. pythinker_code/web/static/assets/{dist-D1EQtQ8U.js → dist-Co5o61Cn.js} +1 -1
  62. pythinker_code/web/static/assets/{erDiagram-TEJ5UH35-sZ8vCcB8.js → erDiagram-TEJ5UH35-Vt3XXS0U.js} +1 -1
  63. pythinker_code/web/static/assets/eventmodeling-FCH6USID-BleAriwz.js +1 -0
  64. pythinker_code/web/static/assets/{flowDiagram-I6XJVG4X-NagVrMCI.js → flowDiagram-I6XJVG4X-BIXHEjYH.js} +1 -1
  65. pythinker_code/web/static/assets/{ganttDiagram-6RSMTGT7-D-1_XhUQ.js → ganttDiagram-6RSMTGT7--FC4MYE3.js} +1 -1
  66. pythinker_code/web/static/assets/{gitGraph-WXDBUCRP-DT3QZQPP.js → gitGraph-WXDBUCRP-IE4jYajm.js} +1 -1
  67. pythinker_code/web/static/assets/{gitGraphDiagram-PVQCEYII-D8r0djS7.js → gitGraphDiagram-PVQCEYII-n6_B85cu.js} +1 -1
  68. pythinker_code/web/static/assets/{index-2eH9dBB3.js → index-Denir8Jc.js} +2 -2
  69. pythinker_code/web/static/assets/{info-J43DQDTF-CsKNLP2n.js → info-J43DQDTF-BL7RBP_1.js} +1 -1
  70. pythinker_code/web/static/assets/{infoDiagram-5YYISTIA-CIiPQAr1.js → infoDiagram-5YYISTIA-DyvqlJzB.js} +1 -1
  71. pythinker_code/web/static/assets/{ishikawaDiagram-YF4QCWOH-B0xZv1Ps.js → ishikawaDiagram-YF4QCWOH--AK0oQMB.js} +1 -1
  72. pythinker_code/web/static/assets/{journeyDiagram-JHISSGLW-CSiKJ4Vm.js → journeyDiagram-JHISSGLW-DPt6uw-j.js} +1 -1
  73. pythinker_code/web/static/assets/{kanban-definition-UN3LZRKU-BYVbc39d.js → kanban-definition-UN3LZRKU-CMP28iqQ.js} +1 -1
  74. pythinker_code/web/static/assets/{line-DHysIuAr.js → line-QV0kz4Kh.js} +1 -1
  75. pythinker_code/web/static/assets/mermaid-VLURNSYL-Cw_TmpwX.js +1 -0
  76. pythinker_code/web/static/assets/{mermaid-parser.core-1Xw2pmTV.js → mermaid-parser.core-5eX2XKzs.js} +2 -2
  77. pythinker_code/web/static/assets/{mermaid.core-yguwm67R.js → mermaid.core-xSjkHKy4.js} +3 -3
  78. pythinker_code/web/static/assets/{mindmap-definition-RKZ34NQL-BzbokPP4.js → mindmap-definition-RKZ34NQL-SSQGdG4v.js} +1 -1
  79. pythinker_code/web/static/assets/{packet-YPE3B663-DvwZvo4I.js → packet-YPE3B663-DTfa3Ugh.js} +1 -1
  80. pythinker_code/web/static/assets/{pie-LRSECV5Y-D3m6fHWL.js → pie-LRSECV5Y-D3jK8uBv.js} +1 -1
  81. pythinker_code/web/static/assets/{pieDiagram-4H26LBE5-Ds6AGwnk.js → pieDiagram-4H26LBE5--TRptUQU.js} +1 -1
  82. pythinker_code/web/static/assets/{quadrantDiagram-W4KKPZXB-DX8m3F04.js → quadrantDiagram-W4KKPZXB-Db9MtYHt.js} +1 -1
  83. pythinker_code/web/static/assets/{radar-GUYGQ44K-Bma1Der9.js → radar-GUYGQ44K-DFnRNCTk.js} +1 -1
  84. pythinker_code/web/static/assets/{requirementDiagram-4Y6WPE33-OcYBKZGh.js → requirementDiagram-4Y6WPE33-sTa-nhJU.js} +1 -1
  85. pythinker_code/web/static/assets/{sankeyDiagram-5OEKKPKP-qZTKBl0U.js → sankeyDiagram-5OEKKPKP-Bd2A0AYR.js} +1 -1
  86. pythinker_code/web/static/assets/{sequenceDiagram-3UESZ5HK-Dat3afNR.js → sequenceDiagram-3UESZ5HK-gsJgyFMR.js} +1 -1
  87. pythinker_code/web/static/assets/{stateDiagram-AJRCARHV-C25VdSrM.js → stateDiagram-AJRCARHV-D8aBQA8n.js} +1 -1
  88. pythinker_code/web/static/assets/stateDiagram-v2-BHNVJYJU-CcaDggV3.js +1 -0
  89. pythinker_code/web/static/assets/{timeline-definition-PNZ67QCA-BO52-l4o.js → timeline-definition-PNZ67QCA-DOTZZxx_.js} +1 -1
  90. pythinker_code/web/static/assets/{treeView-BLDUP644-wTS6XClR.js → treeView-BLDUP644-DeRg38Vr.js} +1 -1
  91. pythinker_code/web/static/assets/{treemap-LRROVOQU-H-Ce4Zv7.js → treemap-LRROVOQU-DWxQ3QgK.js} +1 -1
  92. pythinker_code/web/static/assets/{vennDiagram-CIIHVFJN-C8VDHwNL.js → vennDiagram-CIIHVFJN-CYSR8VxH.js} +1 -1
  93. pythinker_code/web/static/assets/{wardley-L42UT6IY-CWdFDSTM.js → wardley-L42UT6IY-DwndHzRK.js} +1 -1
  94. pythinker_code/web/static/assets/{wardleyDiagram-YWT4CUSO-Cl1J0nhW.js → wardleyDiagram-YWT4CUSO-By2G9X0c.js} +1 -1
  95. pythinker_code/web/static/assets/{xychartDiagram-2RQKCTM6-DY3utX2b.js → xychartDiagram-2RQKCTM6-hEjj-Cb8.js} +1 -1
  96. pythinker_code/web/static/index.html +1 -1
  97. {pythinker_code-0.57.0.dist-info → pythinker_code-0.58.0.dist-info}/METADATA +23 -23
  98. {pythinker_code-0.57.0.dist-info → pythinker_code-0.58.0.dist-info}/RECORD +102 -96
  99. pythinker_code/web/static/assets/architecture-7EHR7CIX-CFMeP6t3.js +0 -1
  100. pythinker_code/web/static/assets/channel-CIonX3Sg.js +0 -1
  101. pythinker_code/web/static/assets/classDiagram-4FO5ZUOK-I2Og_7hO.js +0 -1
  102. pythinker_code/web/static/assets/classDiagram-v2-Q7XG4LA2-I2Og_7hO.js +0 -1
  103. pythinker_code/web/static/assets/eventmodeling-FCH6USID-Nxb8XybE.js +0 -1
  104. pythinker_code/web/static/assets/mermaid-VLURNSYL-BepD7Trl.js +0 -1
  105. pythinker_code/web/static/assets/stateDiagram-v2-BHNVJYJU-CH7hdLfc.js +0 -1
  106. {pythinker_code-0.57.0.dist-info → pythinker_code-0.58.0.dist-info}/WHEEL +0 -0
  107. {pythinker_code-0.57.0.dist-info → pythinker_code-0.58.0.dist-info}/entry_points.txt +0 -0
  108. {pythinker_code-0.57.0.dist-info → pythinker_code-0.58.0.dist-info}/licenses/LICENSE +0 -0
  109. {pythinker_code-0.57.0.dist-info → pythinker_code-0.58.0.dist-info}/licenses/NOTICE +0 -0
@@ -15,6 +15,53 @@ GitHub Releases page; `0.8.0` is the new starting line.
15
15
 
16
16
  ## Unreleased
17
17
 
18
+ ## 0.58.0 (2026-07-11)
19
+
20
+ - **Agent-spec loading is more defensive and truthful.** Subagent `path`, `extend`, and
21
+ `system_prompt_path` references that resolve outside their spec's directory (or the built-in
22
+ agents directory) are now rejected instead of loaded, and the markdown agent catalogue no longer
23
+ reclassifies an unexpected parser error as a harmless "invalid field" skip — only genuinely
24
+ malformed frontmatter is skipped.
25
+ - **Thinking and subagent activity now render cleanly in the terminal.** Live reasoning previews
26
+ render complete Markdown without exposing top-level HTML comments, activity-tree rows remain
27
+ visually stable, and the coral shimmer is reserved for the active verb spinner.
28
+ - **Agent request compatibility is now executable and reviewable.** Provider handoff,
29
+ prompt ordering, persisted-versus-effective history, context JSONL restoration,
30
+ agent projections, and Toolset lifecycle behavior now have explicit compatibility
31
+ contracts guarding future agent-core changes.
32
+ - **Skill discovery is bounded without making skills unreachable.** Pythinker now
33
+ searches one deterministic `SkillCatalog`, keeps exhaustive exact-name resolution,
34
+ and sends only task-relevant candidates to the model within an 8,000-character
35
+ request budget. The exhaustive `Runtime.skills` mapping remains available during
36
+ the compatibility window.
37
+ - **Agent requests now have one observable assembly path.** Required guidance fails
38
+ closed, optional guidance reports sanitized degradation outcomes, and the new
39
+ `/prompt-manifest` command explains the latest request composition without storing
40
+ raw prompts, user text, or provenance paths.
41
+ - **Conversation history updates are transactional.** Normal appends persist before
42
+ changing memory, while compaction, pruning, revert, and clear flows use atomic
43
+ replacement with coherent cancellation and rollback behavior. Concurrent revert
44
+ conflicts now stop after a bounded retry budget instead of starving indefinitely.
45
+ Existing JSONL records and restoration behavior remain compatible.
46
+ - **Agent definitions now resolve through one source-aware catalogue.** YAML and
47
+ Markdown definitions share deterministic precedence, collision diagnostics, and
48
+ safe provenance handling. Unknown fields warn in this release, become errors in
49
+ the following minor release, and the `LaborMarket`, `AgentTypeDefinition`, and
50
+ generated-wrapper adapters remain through that strict-default release.
51
+ - **Tool execution and MCP lifecycle behavior now have deterministic fault coverage.**
52
+ Publication rebuilds preserve the previous MCP tool registry if registration
53
+ fails. Characterization crossed the execution-overhead threshold, but a controlled
54
+ private extraction measured slightly worse and was reverted, so
55
+ `PythinkerToolset` remains the implementation boundary.
56
+ - **Agent-core seams hardened from review.** Persisted usage/checkpoint records reject
57
+ boolean and negative token counts, `update_token_count` validates at the boundary, a
58
+ temporary system-prompt descriptor is closed if `fdopen` fails, request finalization
59
+ surfaces every provider acknowledgement failure, a failed skill projection is always
60
+ recorded as failed (never blurred to not-applicable), and request-assembly telemetry no
61
+ longer emits unbounded per-request token values as metric attributes.
62
+
63
+ Upgrade with `pythinker update`, `pip install --upgrade pythinker-code==0.58.0`, or use the native installer for your platform from the [Releases page](https://github.com/Pythoughts-labs/pythinker-code/releases/latest).
64
+
18
65
  ## 0.57.0 (2026-07-05)
19
66
 
20
67
  - **No more ghost/duplicate input prompt while the agent works.** After
@@ -255,7 +255,7 @@ Precedence per §2. `README`/`README.md` files are optional supplementary contex
255
255
 
256
256
  ## 12. Skills
257
257
 
258
- Skills are reusable, self-contained capability directories, each with a `SKILL.md` of instructions, examples, scripts, and reference material — specialized domain knowledge, workflow patterns, pre-configured tool chains, and templates. They are grouped by scope (`Project`, `User`, `Extra`, `Built-in`); when scopes define the same name, the more specific wins: **Project › User › Extra › Built-in.**
258
+ Skills are reusable, self-contained capability directories, each with a `SKILL.md` of instructions, examples, scripts, and reference material — specialized domain knowledge, workflow patterns, pre-configured tool chains, and templates. When scopes define the same name, the more specific wins: **Project › User › Extra › Built-in.**
259
259
 
260
260
  ${PYTHINKER_SKILLS}
261
261
 
@@ -1,11 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import hashlib
4
+ import re
3
5
  from dataclasses import dataclass
4
6
  from pathlib import Path
5
7
  from typing import Any, Literal, NamedTuple, cast
6
8
 
7
9
  import yaml
8
- from pydantic import BaseModel, Field
10
+ from pydantic import BaseModel, Field, ValidationError
9
11
 
10
12
  from pythinker_code.exception import AgentSpecError
11
13
 
@@ -89,6 +91,14 @@ class ResolvedAgentSpec:
89
91
  subagents: dict[str, SubagentSpec]
90
92
 
91
93
 
94
+ @dataclass(frozen=True, slots=True, kw_only=True)
95
+ class AgentSpecSourceValidation:
96
+ """Unknown fields observed in one canonical YAML source before projection."""
97
+
98
+ source_path: Path
99
+ field_paths: tuple[str, ...]
100
+
101
+
92
102
  def load_agent_spec(agent_file: Path) -> ResolvedAgentSpec:
93
103
  """
94
104
  Load agent specification from file.
@@ -97,7 +107,22 @@ def load_agent_spec(agent_file: Path) -> ResolvedAgentSpec:
97
107
  FileNotFoundError: If the agent spec file is not found.
98
108
  AgentSpecError: If the agent spec is not valid.
99
109
  """
100
- agent_spec = _load_agent_spec(agent_file)
110
+ agent_spec, _ = load_agent_spec_validated(agent_file)
111
+ return agent_spec
112
+
113
+
114
+ def load_agent_spec_validated(
115
+ agent_file: Path,
116
+ *,
117
+ forbid_unknown_fields: bool = False,
118
+ ) -> tuple[ResolvedAgentSpec, tuple[AgentSpecSourceValidation, ...]]:
119
+ """Load a spec and report raw unknown fields from every inherited source."""
120
+ validations: dict[Path, AgentSpecSourceValidation] = {}
121
+ agent_spec = _load_agent_spec(
122
+ agent_file,
123
+ _validations=validations,
124
+ _forbid_unknown_fields=forbid_unknown_fields,
125
+ )
101
126
  assert agent_spec.extend is None, "agent extension should be recursively resolved"
102
127
  if isinstance(agent_spec.name, Inherit):
103
128
  raise AgentSpecError("Agent name is required")
@@ -111,7 +136,7 @@ def load_agent_spec(agent_file: Path) -> ResolvedAgentSpec:
111
136
  agent_spec.exclude_tools = []
112
137
  if isinstance(agent_spec.subagents, Inherit):
113
138
  agent_spec.subagents = {}
114
- return ResolvedAgentSpec(
139
+ resolved = ResolvedAgentSpec(
115
140
  name=agent_spec.name,
116
141
  system_prompt_path=agent_spec.system_prompt_path,
117
142
  system_prompt_args=agent_spec.system_prompt_args,
@@ -127,9 +152,36 @@ def load_agent_spec(agent_file: Path) -> ResolvedAgentSpec:
127
152
  exclude_tools=agent_spec.exclude_tools or [],
128
153
  subagents=agent_spec.subagents or {},
129
154
  )
155
+ return resolved, tuple(validations.values())
156
+
157
+
158
+ def _resolve_within_agent_roots(agent_file: Path, declared: str | Path) -> Path:
159
+ """Join *declared* onto *agent_file*'s directory, rejecting escaping paths.
160
+
161
+ Trusted local agent specs reference sibling files with relative paths. A
162
+ ``..`` traversal or symlink whose canonical target lands outside both the
163
+ originating spec's directory and the built-in agents directory is rejected
164
+ fail-closed as defense-in-depth, since the joined path is otherwise opened
165
+ or recursively loaded directly. The stored value keeps its ``.absolute()``
166
+ form, so permitted paths are unchanged.
167
+ """
168
+ parent = agent_file.parent
169
+ absolute = (parent / declared).absolute()
170
+ allowed_roots = (parent.resolve(), get_agents_dir().resolve())
171
+ if not any(absolute.resolve().is_relative_to(root) for root in allowed_roots):
172
+ raise AgentSpecError(
173
+ f"Agent spec reference {declared!r} resolves outside the permitted agent directories"
174
+ )
175
+ return absolute
130
176
 
131
177
 
132
- def _load_agent_spec(agent_file: Path, _visited: set[Path] | None = None) -> AgentSpec:
178
+ def _load_agent_spec(
179
+ agent_file: Path,
180
+ _visited: set[Path] | None = None,
181
+ *,
182
+ _validations: dict[Path, AgentSpecSourceValidation] | None = None,
183
+ _forbid_unknown_fields: bool = False,
184
+ ) -> AgentSpec:
133
185
  resolved = agent_file.resolve()
134
186
  if _visited is None:
135
187
  _visited = set()
@@ -149,24 +201,46 @@ def _load_agent_spec(agent_file: Path, _visited: set[Path] | None = None) -> Age
149
201
  raise AgentSpecError(f"Agent spec file must contain a mapping: {agent_file}")
150
202
  data = cast("dict[str, Any]", data)
151
203
 
204
+ unknown_fields, has_invalid_field_key = _unknown_agent_spec_fields(data)
205
+ if unknown_fields:
206
+ if has_invalid_field_key:
207
+ fields = ", ".join(unknown_fields)
208
+ raise AgentSpecError(f"Invalid agent field key: {fields}")
209
+ if _forbid_unknown_fields:
210
+ fields = ", ".join(unknown_fields)
211
+ raise AgentSpecError(f"Unknown fields in required agent source: {fields}")
212
+ if _validations is not None and resolved not in _validations:
213
+ _validations[resolved] = AgentSpecSourceValidation(
214
+ source_path=resolved,
215
+ field_paths=unknown_fields,
216
+ )
217
+
152
218
  version = str(data.get("version", DEFAULT_AGENT_SPEC_VERSION))
153
219
  if version not in SUPPORTED_AGENT_SPEC_VERSIONS:
154
220
  raise AgentSpecError(f"Unsupported agent spec version: {version}")
155
221
 
156
- agent_spec = AgentSpec(**data.get("agent", {}))
222
+ try:
223
+ agent_spec = AgentSpec(**data.get("agent", {}))
224
+ except (TypeError, ValidationError) as exc:
225
+ raise AgentSpecError("Agent spec contains an invalid known field") from exc
157
226
  if isinstance(agent_spec.system_prompt_path, Path):
158
- agent_spec.system_prompt_path = (
159
- agent_file.parent / agent_spec.system_prompt_path
160
- ).absolute()
227
+ agent_spec.system_prompt_path = _resolve_within_agent_roots(
228
+ agent_file, agent_spec.system_prompt_path
229
+ )
161
230
  if isinstance(agent_spec.subagents, dict):
162
231
  for v in agent_spec.subagents.values():
163
- v.path = (agent_file.parent / v.path).absolute()
232
+ v.path = _resolve_within_agent_roots(agent_file, v.path)
164
233
  if agent_spec.extend:
165
234
  if agent_spec.extend == "default":
166
235
  base_agent_file = DEFAULT_AGENT_FILE
167
236
  else:
168
- base_agent_file = (agent_file.parent / agent_spec.extend).absolute()
169
- base_agent_spec = _load_agent_spec(base_agent_file, _visited)
237
+ base_agent_file = _resolve_within_agent_roots(agent_file, agent_spec.extend)
238
+ base_agent_spec = _load_agent_spec(
239
+ base_agent_file,
240
+ _visited,
241
+ _validations=_validations,
242
+ _forbid_unknown_fields=_forbid_unknown_fields,
243
+ )
170
244
  if not isinstance(agent_spec.name, Inherit):
171
245
  base_agent_spec.name = agent_spec.name
172
246
  if not isinstance(agent_spec.system_prompt_path, Inherit):
@@ -207,3 +281,89 @@ def _load_agent_spec(agent_file: Path, _visited: set[Path] | None = None) -> Age
207
281
  base_agent_spec.subagents = agent_spec.subagents
208
282
  agent_spec = base_agent_spec
209
283
  return agent_spec
284
+
285
+
286
+ def _unknown_agent_spec_fields(data: dict[str, Any]) -> tuple[tuple[str, ...], bool]:
287
+ unknown: list[str] = []
288
+ has_invalid_key = False
289
+ for key in cast("dict[object, object]", data):
290
+ if isinstance(key, str) and key in {"version", "agent"}:
291
+ continue
292
+ rendered = render_agent_field_segment(key)
293
+ unknown.append(rendered.text)
294
+ has_invalid_key = has_invalid_key or rendered.structurally_invalid
295
+ raw_agent = data.get("agent")
296
+ if not isinstance(raw_agent, dict):
297
+ return tuple(sorted(unknown)), has_invalid_key
298
+ agent = cast("dict[str, Any]", raw_agent)
299
+ known_agent_fields = set(AgentSpec.model_fields)
300
+ for key in cast("dict[object, object]", agent):
301
+ if isinstance(key, str) and key in known_agent_fields:
302
+ continue
303
+ rendered = render_agent_field_segment(key)
304
+ unknown.append(f"agent.{rendered.text}")
305
+ has_invalid_key = has_invalid_key or rendered.structurally_invalid
306
+ raw_subagents = agent.get("subagents")
307
+ if isinstance(raw_subagents, dict):
308
+ known_subagent_fields = set(SubagentSpec.model_fields)
309
+ for name, raw_subagent in cast("dict[object, object]", raw_subagents).items():
310
+ rendered_name = render_agent_field_segment(name)
311
+ has_invalid_key = has_invalid_key or rendered_name.structurally_invalid
312
+ if rendered_name.structurally_invalid:
313
+ unknown.append(f"agent.subagents.{rendered_name.text}")
314
+ if not isinstance(raw_subagent, dict):
315
+ continue
316
+ for key in cast("dict[object, object]", raw_subagent):
317
+ if isinstance(key, str) and key in known_subagent_fields:
318
+ continue
319
+ rendered = render_agent_field_segment(key)
320
+ unknown.append(f"agent.subagents.{rendered_name.text}.{rendered.text}")
321
+ has_invalid_key = has_invalid_key or rendered.structurally_invalid
322
+ return tuple(sorted(unknown)), has_invalid_key
323
+
324
+
325
+ _FIELD_IDENTIFIER_RE = re.compile(r"[A-Za-z_][A-Za-z0-9_-]*")
326
+ _SENSITIVE_FIELD_HINTS = (
327
+ "password",
328
+ "passwd",
329
+ "secret",
330
+ "token",
331
+ "api_key",
332
+ "apikey",
333
+ "access_key",
334
+ "private_key",
335
+ "credential",
336
+ "auth",
337
+ )
338
+
339
+
340
+ @dataclass(frozen=True, slots=True, kw_only=True)
341
+ class AgentFieldSegment:
342
+ text: str
343
+ redacted_for_safety: bool
344
+ structurally_invalid: bool
345
+
346
+
347
+ def render_agent_field_segment(value: object) -> AgentFieldSegment:
348
+ """Render a stable field segment without conflating redaction and validity."""
349
+ if isinstance(value, str):
350
+ lowered = value.casefold()
351
+ if _FIELD_IDENTIFIER_RE.fullmatch(value) and not any(
352
+ hint in lowered for hint in _SENSITIVE_FIELD_HINTS
353
+ ):
354
+ return AgentFieldSegment(
355
+ text=value,
356
+ redacted_for_safety=False,
357
+ structurally_invalid=False,
358
+ )
359
+ digest_input = f"str:{value}"
360
+ structurally_invalid = _FIELD_IDENTIFIER_RE.fullmatch(value) is None
361
+ else:
362
+ digest_input = f"{type(value).__qualname__}:{value!r}"
363
+ structurally_invalid = True
364
+ digest = hashlib.sha256(digest_input.encode(encoding="utf-8")).hexdigest()[:12]
365
+ return AgentFieldSegment(
366
+ text=f"field[{digest}]",
367
+ redacted_for_safety=True,
368
+ structurally_invalid=structurally_invalid,
369
+ )