thoth-agents 0.3.9 → 0.3.11

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 (40) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/dist/agents/prompt-dialects.d.ts +3 -0
  3. package/dist/{chunk-MY2GIOOH.js → chunk-CB3EBA7H.js} +4 -1
  4. package/dist/{chunk-2TLT6WWY.js → chunk-GIUU6FNE.js} +340 -296
  5. package/dist/{chunk-XEEYNMPC.js → chunk-ZEAAWBF2.js} +28 -83
  6. package/dist/cli/index.js +3 -3
  7. package/dist/cli/tui/index.js +2 -2
  8. package/dist/config/constants.d.ts +3 -3
  9. package/dist/harness/adapters/claude-code.d.ts +8 -0
  10. package/dist/harness/adapters/codex-surfaces.d.ts +2 -2
  11. package/dist/harness/core/agent-pack.d.ts +38 -3
  12. package/dist/harness/core/sdd.d.ts +9 -8
  13. package/dist/index.js +2 -2
  14. package/package.json +1 -1
  15. package/plugin/.claude-plugin/.thoth-agents-plugin-assets.json +7 -7
  16. package/plugin/.claude-plugin/plugin.json +1 -1
  17. package/plugin/.codex-plugin/plugin.json +1 -1
  18. package/plugin/agents/deep.md +10 -31
  19. package/plugin/agents/designer.md +10 -31
  20. package/plugin/agents/explorer.md +10 -30
  21. package/plugin/agents/librarian.md +10 -30
  22. package/plugin/agents/oracle.md +10 -30
  23. package/plugin/agents/orchestrator.md +39 -31
  24. package/plugin/agents/quick.md +10 -31
  25. package/plugin/skills/thoth-archive/SKILL.md +7 -0
  26. package/plugin/skills/thoth-archive/scripts/archive.mjs +58 -84
  27. package/plugin/skills/thoth-sdd/SKILL.md +13 -1
  28. package/plugin/skills/thoth-sdd/references/phases/implement.md +33 -6
  29. package/plugin/skills/thoth-sdd/references/phases/specify.md +12 -1
  30. package/plugin/skills/thoth-sdd/scripts/durable-deltas.mjs +158 -0
  31. package/plugin/skills/thoth-sdd/scripts/validate.mjs +67 -28
  32. package/plugin/skills/thoth-sdd/templates/spec.md +9 -1
  33. package/skills/thoth-archive/SKILL.md +7 -0
  34. package/skills/thoth-archive/scripts/archive.mjs +58 -84
  35. package/skills/thoth-sdd/SKILL.md +13 -1
  36. package/skills/thoth-sdd/references/phases/implement.md +33 -6
  37. package/skills/thoth-sdd/references/phases/specify.md +12 -1
  38. package/skills/thoth-sdd/scripts/durable-deltas.mjs +158 -0
  39. package/skills/thoth-sdd/scripts/validate.mjs +67 -28
  40. package/skills/thoth-sdd/templates/spec.md +9 -1
@@ -213,10 +213,10 @@ var ALL_AGENT_NAMES = [
213
213
  ];
214
214
  var CONFIRMED_OPENAI_SUBAGENT_PRESET = {
215
215
  explorer: { model: "gpt-5.6-luna", effort: "low" },
216
- librarian: { model: "gpt-5.6-luna", effort: "xhigh" },
217
- oracle: { model: "gpt-5.6-sol", effort: "xhigh" },
216
+ librarian: { model: "gpt-5.6-luna", effort: "high" },
217
+ oracle: { model: "gpt-5.6-sol", effort: "high" },
218
218
  designer: { model: "gpt-5.6-sol", effort: "medium" },
219
- quick: { model: "gpt-5.6-luna", effort: "xhigh" },
219
+ quick: { model: "gpt-5.6-luna", effort: "low" },
220
220
  deep: { model: "gpt-5.6-sol", effort: "medium" }
221
221
  };
222
222
  var OPENCODE_OPENAI_ORCHESTRATOR_PRESET = {
@@ -735,6 +735,269 @@ function loadAgentPrompt(agentName, preset) {
735
735
  return result;
736
736
  }
737
737
 
738
+ // src/harness/core/agent-pack.ts
739
+ var AGENT_ROLES = [
740
+ {
741
+ name: "orchestrator",
742
+ mode: "adaptive-root",
743
+ dispatch: "root-coordinator",
744
+ canMutateWorkspace: true,
745
+ scope: "requirements, SDD coordination, routing, bounded implementation, decisions, and synthesis",
746
+ responsibility: "Keep requirements, decisions, sequential SDD coordination, and final synthesis in the root thread; evaluate implementation ownership independently in every route and implement directly or delegate according to explicit user direction and demonstrated net gain.",
747
+ useWhen: [
748
+ "Coordinate requirements, governed artifacts, routing, and synthesis.",
749
+ "Implement an accepted mutable surface in any route when accumulated context and continuity outweigh delegation overhead."
750
+ ],
751
+ doNotUseWhen: ["Not for independent plan review or final verification."],
752
+ escalateWhen: [
753
+ "Delegate implementation when specialization, context isolation, or independent bounded work creates a demonstrated net gain; then select designer, quick, or deep by task shape."
754
+ ],
755
+ toolGovernance: [
756
+ "may inspect and edit the accepted bounded implementation surface in every route, but every verification is delegated to oracle",
757
+ "loads the matching thoth-sdd phase contract on demand instead of carrying every phase protocol in its prompt",
758
+ "owns governed coordination writes under openspec/ and uses append-only tasks.md updates during convergence",
759
+ "delegates independent or specialist work only when it produces a net gain",
760
+ "keeps requirements, decisions, and final synthesis in the root thread"
761
+ ],
762
+ verification: [
763
+ "delegates selected plan-review and every verify phase to oracle; plan review stays optional and final verification stays mandatory",
764
+ "consolidates summarized evidence returned by child agents"
765
+ ]
766
+ },
767
+ {
768
+ name: "explorer",
769
+ mode: "read-only",
770
+ dispatch: "task",
771
+ canMutateWorkspace: false,
772
+ scope: "local repository discovery",
773
+ responsibility: "Resolve broad or uncertain repository questions and return distilled evidence.",
774
+ useWhen: ["Repository ownership or behavior is broad or uncertain."],
775
+ doNotUseWhen: ["Not for implementation, edits, or known narrow questions."],
776
+ escalateWhen: [
777
+ "Send external evidence to librarian and mutation scope to root."
778
+ ],
779
+ toolGovernance: [
780
+ "uses read, search, and code-navigation tools only",
781
+ "does not mutate files or delegate further"
782
+ ],
783
+ verification: ["reports inspected paths, confidence, and remaining gaps"]
784
+ },
785
+ {
786
+ name: "librarian",
787
+ mode: "read-only",
788
+ dispatch: "task",
789
+ canMutateWorkspace: false,
790
+ scope: "authoritative external research with local confirmation when needed",
791
+ responsibility: "Gather current authoritative evidence and separate documented facts from inference.",
792
+ useWhen: ["Current authoritative external evidence is required."],
793
+ doNotUseWhen: ["Not for implementation, edits, or purely local discovery."],
794
+ escalateWhen: ["Report contradictory or insufficient sources to root."],
795
+ toolGovernance: [
796
+ "uses research and read-only local tools",
797
+ "does not mutate files or delegate further"
798
+ ],
799
+ verification: ["provides direct sources for substantive external claims"]
800
+ },
801
+ {
802
+ name: "oracle",
803
+ mode: "read-only",
804
+ dispatch: "synchronous-task-only",
805
+ canMutateWorkspace: false,
806
+ scope: "diagnosis, architecture, optional plan review, and independent verification",
807
+ responsibility: "Independently review plans when the user requests it and perform every implementation verification, exposing correctness risks and judging whether results satisfy their contracts.",
808
+ useWhen: [
809
+ "Selected plan review, diagnosis, or final verification needs independent judgment."
810
+ ],
811
+ doNotUseWhen: [
812
+ "Not for implementation, mutation, persistence, or self-review."
813
+ ],
814
+ escalateWhen: ["Return blockers and remediation anchors to root."],
815
+ toolGovernance: [
816
+ "performs read-only analysis and independent review and is never the implementer of the work it judges",
817
+ "does not implement, persist artifacts, or delegate further"
818
+ ],
819
+ verification: ["separates observations, risks, and recommendations"]
820
+ },
821
+ {
822
+ name: "designer",
823
+ mode: "write-capable",
824
+ dispatch: "synchronous-task-only",
825
+ canMutateWorkspace: true,
826
+ scope: "UI/UX decisions, implementation, and visual verification",
827
+ responsibility: "Own user-facing implementation choices and visual quality for UI work.",
828
+ useWhen: [
829
+ "User-facing UI/UX, interaction, accessibility, or visual quality is material."
830
+ ],
831
+ doNotUseWhen: [
832
+ "Not for backend-only, non-visual, or correctness-heavy cross-cutting work."
833
+ ],
834
+ escalateWhen: [
835
+ "Escalate coupled contracts, migrations, or high risk to deep."
836
+ ],
837
+ toolGovernance: [
838
+ "may edit focused UI/UX files",
839
+ "owns screenshots and visual QA",
840
+ "does not delegate further"
841
+ ],
842
+ verification: ["includes visual verification when applicable"]
843
+ },
844
+ {
845
+ name: "quick",
846
+ mode: "write-capable",
847
+ dispatch: "synchronous-task-only",
848
+ canMutateWorkspace: true,
849
+ scope: "fast bounded implementation",
850
+ responsibility: "Implement narrow, clear, low-risk changes within an explicitly bounded surface.",
851
+ useWhen: ["Known narrow mechanical low-risk work has exact targets."],
852
+ doNotUseWhen: [
853
+ "Not for coupled contracts, migrations, broad discovery, concurrency, edge cases, or high risk."
854
+ ],
855
+ escalateWhen: [
856
+ "Escalate discovery, coupling, edge cases, or higher risk to deep."
857
+ ],
858
+ toolGovernance: [
859
+ "edits only bounded targets",
860
+ "escalates when discovery or correctness risk exceeds the assignment",
861
+ "does not delegate further"
862
+ ],
863
+ verification: ["runs the smallest sufficient focused check"]
864
+ },
865
+ {
866
+ name: "deep",
867
+ mode: "write-capable",
868
+ dispatch: "synchronous-task-only",
869
+ canMutateWorkspace: true,
870
+ scope: "correctness-critical implementation and verification",
871
+ responsibility: "Handle multi-file, edge-case-heavy, or high-risk implementation with full local context.",
872
+ useWhen: [
873
+ "Implementation is multi-file, edge-case-heavy, migration, concurrency, shared-contract, or high-risk."
874
+ ],
875
+ doNotUseWhen: ["Not for visual-only work or narrow known low-risk edits."],
876
+ escalateWhen: ["Return product or architecture choices to root."],
877
+ toolGovernance: [
878
+ "may edit implementation and tests within the assigned surface",
879
+ "validates shared behavior against related code and call sites",
880
+ "does not delegate further"
881
+ ],
882
+ verification: ["reports focused checks and relevant edge-case evidence"]
883
+ }
884
+ ];
885
+ var ORCHESTRATION_POLICY = {
886
+ maxDelegationDepth: 1,
887
+ singleWriter: true,
888
+ implementationOwnership: {
889
+ eligibleOwners: ["orchestrator", "designer", "quick", "deep"],
890
+ routeIndependent: true,
891
+ delegationBenefits: [
892
+ "specialization",
893
+ "context isolation",
894
+ "independent bounded work",
895
+ "safe parallelism",
896
+ "quality, latency, or total-cost gain"
897
+ ],
898
+ rootContinuityBenefits: [
899
+ "short work",
900
+ "one ordered reasoning chain",
901
+ "frequent shared-state writes",
902
+ "already-loaded context",
903
+ "rediscovery and coordination cost"
904
+ ],
905
+ userDirection: "explicit safe user direction is an ownership input",
906
+ insufficientSignals: [
907
+ "SDD route name",
908
+ "file count alone",
909
+ "cheaper model price without end-to-end evidence"
910
+ ]
911
+ },
912
+ rules: [
913
+ "Direct, Accelerated, Full, and no-artifact execution govern artifacts and gates, not implementation ownership.",
914
+ "Root or a specialist may implement in every route; delegate only when specialization, context isolation, independent bounded work, or safe parallelism creates a demonstrated quality, latency, or total-cost net gain.",
915
+ "Keep implementation in root when short work, one ordered reasoning chain, frequent shared-state writes, already-loaded context, rediscovery, or coordination cost outweigh delegation benefit.",
916
+ "Treat explicit safe user direction as an ownership input; route name, file count alone, or cheaper model price without end-to-end evidence cannot choose an owner.",
917
+ "After deciding to delegate implementation, select designer for UI/UX, quick for known narrow low-risk work, and deep for coupled or high-risk work.",
918
+ "Use one writer for each mutable surface and never parallelize overlapping writes.",
919
+ "A fresh subagent instance is the default when the objective, SDD phase, mutable surface, or independent judgment changes.",
920
+ "Continue an existing subagent only to steer, complete, or clarify the same bounded assignment; completed agents are not a reusable role pool.",
921
+ "Every Oracle plan review, verification round, and approval or PASS judgment uses a fresh Oracle instance; reuse is limited to clarifying current findings.",
922
+ "Wait and status operations collect only the active nonterminal assignment and do not authorize later reuse.",
923
+ "Child agents return distilled evidence instead of raw logs or file dumps."
924
+ ]
925
+ };
926
+ var AGENT_RETURN_CONTRACT = [
927
+ "conclusion",
928
+ "evidence",
929
+ "verification",
930
+ "risks",
931
+ "openQuestions",
932
+ "nextAction"
933
+ ];
934
+ var VERIFICATION_PROTOCOL = [
935
+ "Completion reports identify changed files and verification evidence.",
936
+ "Behavior changes receive the smallest sufficient automated check or a declared manual check.",
937
+ "Visual changes receive designer-owned visual QA when applicable."
938
+ ];
939
+ var AGENT_PACK_CONTRACT = {
940
+ roles: [...AGENT_ROLES],
941
+ orchestrationPolicy: {
942
+ ...ORCHESTRATION_POLICY,
943
+ rules: [...ORCHESTRATION_POLICY.rules]
944
+ },
945
+ returnContract: [...AGENT_RETURN_CONTRACT],
946
+ verificationProtocol: [...VERIFICATION_PROTOCOL]
947
+ };
948
+ function getAgentRole(name) {
949
+ const role = AGENT_ROLES.find((candidate) => candidate.name === name);
950
+ if (!role) {
951
+ throw new Error(`Unknown agent role: ${name}`);
952
+ }
953
+ return role;
954
+ }
955
+ function renderAgentRoutingDescription(role) {
956
+ return [
957
+ role.responsibility,
958
+ `Use when: ${role.useWhen.join(" ")}`,
959
+ `Do not use when: ${role.doNotUseWhen.join(" ")}`,
960
+ `Escalate when: ${role.escalateWhen.join(" ")}`,
961
+ `Mutation: ${role.canMutateWorkspace ? `only the assigned ${role.scope} surface` : "read-only; never mutate the workspace"}.`,
962
+ `Verification: ${role.verification.join(" ")}`,
963
+ `Return: ${AGENT_RETURN_CONTRACT.join(", ")}.`
964
+ ].join(" ");
965
+ }
966
+ function getAgentPackContract() {
967
+ return {
968
+ roles: AGENT_PACK_CONTRACT.roles.map((role) => ({
969
+ ...role,
970
+ useWhen: [...role.useWhen],
971
+ doNotUseWhen: [...role.doNotUseWhen],
972
+ escalateWhen: [...role.escalateWhen],
973
+ writeScope: role.writeScope ? [...role.writeScope] : void 0,
974
+ toolGovernance: [...role.toolGovernance],
975
+ verification: [...role.verification]
976
+ })),
977
+ orchestrationPolicy: {
978
+ ...AGENT_PACK_CONTRACT.orchestrationPolicy,
979
+ implementationOwnership: {
980
+ ...AGENT_PACK_CONTRACT.orchestrationPolicy.implementationOwnership,
981
+ eligibleOwners: [
982
+ ...AGENT_PACK_CONTRACT.orchestrationPolicy.implementationOwnership.eligibleOwners
983
+ ],
984
+ delegationBenefits: [
985
+ ...AGENT_PACK_CONTRACT.orchestrationPolicy.implementationOwnership.delegationBenefits
986
+ ],
987
+ rootContinuityBenefits: [
988
+ ...AGENT_PACK_CONTRACT.orchestrationPolicy.implementationOwnership.rootContinuityBenefits
989
+ ],
990
+ insufficientSignals: [
991
+ ...AGENT_PACK_CONTRACT.orchestrationPolicy.implementationOwnership.insufficientSignals
992
+ ]
993
+ },
994
+ rules: [...AGENT_PACK_CONTRACT.orchestrationPolicy.rules]
995
+ },
996
+ returnContract: [...AGENT_PACK_CONTRACT.returnContract],
997
+ verificationProtocol: [...AGENT_PACK_CONTRACT.verificationProtocol]
998
+ };
999
+ }
1000
+
738
1001
  // src/agents/prompt-dialects.ts
739
1002
  var OPENCODE_CAPABILITIES = {
740
1003
  agentDefinitions: "supported",
@@ -802,6 +1065,9 @@ var OPENCODE_PROMPT_DIALECT = {
802
1065
  progressTool: "todowrite",
803
1066
  hostStatusSurface: "task_status",
804
1067
  lifecycle: {
1068
+ freshDelegation: "`task` without `task_id`",
1069
+ sameAssignmentContinuation: "`task` with the prior `task_id`",
1070
+ independentContext: "omitting `task_id` creates an isolated child session",
805
1071
  statusAction: "wait, poll, and collect",
806
1072
  terminalState: "terminal task_status result",
807
1073
  nonterminalState: "nonterminal task_status result",
@@ -835,6 +1101,9 @@ var CODEX_PROMPT_DIALECT = {
835
1101
  progressTool: "functions.update_plan",
836
1102
  hostStatusSurface: "collaboration.list_agents",
837
1103
  lifecycle: {
1104
+ freshDelegation: '`collaboration.spawn_agent` with `fork_turns="none"`',
1105
+ sameAssignmentContinuation: "`collaboration.followup_task` for the existing agent",
1106
+ independentContext: '`fork_turns="none"` prevents parent-history inheritance',
838
1107
  statusAction: "wait and inspect status",
839
1108
  terminalState: "terminal mailbox completion or failure update",
840
1109
  nonterminalState: "collaboration.wait_agent timeout or silence",
@@ -875,6 +1144,9 @@ var CLAUDE_CODE_PROMPT_DIALECT = {
875
1144
  progressTool: "TodoWrite",
876
1145
  hostStatusSurface: "TodoWrite",
877
1146
  lifecycle: {
1147
+ freshDelegation: "a normal `Agent` invocation",
1148
+ sameAssignmentContinuation: "`SendMessage` to the prior agent ID",
1149
+ independentContext: "do not use `fork` for independent work",
878
1150
  statusAction: "wait, inspect, and collect",
879
1151
  terminalState: "terminal TaskOutput result",
880
1152
  nonterminalState: "nonterminal TaskOutput result",
@@ -902,166 +1174,6 @@ var CLAUDE_CODE_PROMPT_DIALECT = {
902
1174
  }
903
1175
  };
904
1176
 
905
- // src/harness/core/agent-pack.ts
906
- var AGENT_ROLES = [
907
- {
908
- name: "orchestrator",
909
- mode: "adaptive-root",
910
- dispatch: "root-coordinator",
911
- canMutateWorkspace: true,
912
- scope: "requirements, SDD coordination, routing, bounded direct work, decisions, and synthesis",
913
- responsibility: "Keep the task coherent, own sequential specification, planning, task, convergence, and archive coordination, act directly when work is clear and bounded, and delegate only for net gain.",
914
- toolGovernance: [
915
- "may inspect and edit bounded direct work, but every verification is delegated to oracle",
916
- "loads the matching thoth-sdd phase contract on demand instead of carrying every phase protocol in its prompt",
917
- "owns governed coordination writes under openspec/ and uses append-only tasks.md updates during convergence",
918
- "delegates independent or specialist work only when it produces a net gain",
919
- "keeps requirements, decisions, and final synthesis in the root thread"
920
- ],
921
- verification: [
922
- "delegates selected plan-review and every verify phase to oracle; plan review stays optional and final verification stays mandatory",
923
- "consolidates summarized evidence returned by child agents"
924
- ]
925
- },
926
- {
927
- name: "explorer",
928
- mode: "read-only",
929
- dispatch: "task",
930
- canMutateWorkspace: false,
931
- scope: "local repository discovery",
932
- responsibility: "Resolve broad or uncertain repository questions and return distilled evidence.",
933
- toolGovernance: [
934
- "uses read, search, and code-navigation tools only",
935
- "does not mutate files or delegate further"
936
- ],
937
- verification: ["reports inspected paths, confidence, and remaining gaps"]
938
- },
939
- {
940
- name: "librarian",
941
- mode: "read-only",
942
- dispatch: "task",
943
- canMutateWorkspace: false,
944
- scope: "authoritative external research with local confirmation when needed",
945
- responsibility: "Gather current authoritative evidence and separate documented facts from inference.",
946
- toolGovernance: [
947
- "uses research and read-only local tools",
948
- "does not mutate files or delegate further"
949
- ],
950
- verification: ["provides direct sources for substantive external claims"]
951
- },
952
- {
953
- name: "oracle",
954
- mode: "read-only",
955
- dispatch: "synchronous-task-only",
956
- canMutateWorkspace: false,
957
- scope: "diagnosis, architecture, optional plan review, and independent verification",
958
- responsibility: "Independently review plans when the user requests it and perform every implementation verification, exposing correctness risks and judging whether results satisfy their contracts.",
959
- toolGovernance: [
960
- "performs read-only analysis and independent review and is never the implementer of the work it judges",
961
- "does not implement, persist artifacts, or delegate further"
962
- ],
963
- verification: ["separates observations, risks, and recommendations"]
964
- },
965
- {
966
- name: "designer",
967
- mode: "write-capable",
968
- dispatch: "synchronous-task-only",
969
- canMutateWorkspace: true,
970
- scope: "UI/UX decisions, implementation, and visual verification",
971
- responsibility: "Own user-facing implementation choices and visual quality for UI work.",
972
- toolGovernance: [
973
- "may edit focused UI/UX files",
974
- "owns screenshots and visual QA",
975
- "does not delegate further"
976
- ],
977
- verification: ["includes visual verification when applicable"]
978
- },
979
- {
980
- name: "quick",
981
- mode: "write-capable",
982
- dispatch: "synchronous-task-only",
983
- canMutateWorkspace: true,
984
- scope: "fast bounded implementation",
985
- responsibility: "Implement narrow, clear, low-risk changes within an explicitly bounded surface.",
986
- toolGovernance: [
987
- "edits only bounded targets",
988
- "escalates when discovery or correctness risk exceeds the assignment",
989
- "does not delegate further"
990
- ],
991
- verification: ["runs the smallest sufficient focused check"]
992
- },
993
- {
994
- name: "deep",
995
- mode: "write-capable",
996
- dispatch: "synchronous-task-only",
997
- canMutateWorkspace: true,
998
- scope: "correctness-critical implementation and verification",
999
- responsibility: "Handle multi-file, edge-case-heavy, or high-risk implementation with full local context.",
1000
- toolGovernance: [
1001
- "may edit implementation and tests within the assigned surface",
1002
- "validates shared behavior against related code and call sites",
1003
- "does not delegate further"
1004
- ],
1005
- verification: ["reports focused checks and relevant edge-case evidence"]
1006
- }
1007
- ];
1008
- var ORCHESTRATION_POLICY = {
1009
- maxDelegationDepth: 1,
1010
- singleWriter: true,
1011
- rules: [
1012
- "The root performs bounded direct work when scope and intent are clear.",
1013
- "Delegate only when specialization, context isolation, or independent parallel work creates a net gain.",
1014
- "Prefer child agents for read-heavy exploration, research, analysis, and verification.",
1015
- "Use one writer for each mutable surface and never parallelize overlapping writes.",
1016
- "Child agents return distilled evidence instead of raw logs or file dumps."
1017
- ]
1018
- };
1019
- var AGENT_RETURN_CONTRACT = [
1020
- "conclusion",
1021
- "evidence",
1022
- "verification",
1023
- "risks",
1024
- "openQuestions",
1025
- "nextAction"
1026
- ];
1027
- var VERIFICATION_PROTOCOL = [
1028
- "Completion reports identify changed files and verification evidence.",
1029
- "Behavior changes receive the smallest sufficient automated check or a declared manual check.",
1030
- "Visual changes receive designer-owned visual QA when applicable."
1031
- ];
1032
- var AGENT_PACK_CONTRACT = {
1033
- roles: [...AGENT_ROLES],
1034
- orchestrationPolicy: {
1035
- ...ORCHESTRATION_POLICY,
1036
- rules: [...ORCHESTRATION_POLICY.rules]
1037
- },
1038
- returnContract: [...AGENT_RETURN_CONTRACT],
1039
- verificationProtocol: [...VERIFICATION_PROTOCOL]
1040
- };
1041
- function getAgentRole(name) {
1042
- const role = AGENT_ROLES.find((candidate) => candidate.name === name);
1043
- if (!role) {
1044
- throw new Error(`Unknown agent role: ${name}`);
1045
- }
1046
- return role;
1047
- }
1048
- function getAgentPackContract() {
1049
- return {
1050
- roles: AGENT_PACK_CONTRACT.roles.map((role) => ({
1051
- ...role,
1052
- writeScope: role.writeScope ? [...role.writeScope] : void 0,
1053
- toolGovernance: [...role.toolGovernance],
1054
- verification: [...role.verification]
1055
- })),
1056
- orchestrationPolicy: {
1057
- ...AGENT_PACK_CONTRACT.orchestrationPolicy,
1058
- rules: [...AGENT_PACK_CONTRACT.orchestrationPolicy.rules]
1059
- },
1060
- returnContract: [...AGENT_PACK_CONTRACT.returnContract],
1061
- verificationProtocol: [...AGENT_PACK_CONTRACT.verificationProtocol]
1062
- };
1063
- }
1064
-
1065
1177
  // src/harness/core/sdd.ts
1066
1178
  var SDD_PHASES = [
1067
1179
  {
@@ -1159,9 +1271,9 @@ var SDD_PHASES = [
1159
1271
  activation: "required",
1160
1272
  prerequisites: ["tasks"],
1161
1273
  producesArtifact: false,
1162
- defaultAgentRole: "orchestrator",
1274
+ defaultAgentRole: "adaptive-implementation",
1163
1275
  eligibleAgentRoles: ["orchestrator", "designer", "quick", "deep"],
1164
- reason: "Let the adaptive root act directly or route the settled work to one writer."
1276
+ reason: "Choose root, designer, quick, or deep from task-shaped net gain independently from the SDD route."
1165
1277
  },
1166
1278
  {
1167
1279
  id: "verify",
@@ -1201,85 +1313,6 @@ var SDD_PHASES = [
1201
1313
  reason: "Transactionally sync declared durable deltas and close verified work with a dated audit trail."
1202
1314
  }
1203
1315
  ];
1204
- var SDD_ARTIFACT_GRAPH = [
1205
- {
1206
- id: "spec",
1207
- path: "spec.md",
1208
- producedBy: "specify",
1209
- consumes: [],
1210
- requiredFor: ["accelerated", "full"]
1211
- },
1212
- {
1213
- id: "plan",
1214
- path: "plan.md",
1215
- producedBy: "plan",
1216
- consumes: ["spec"],
1217
- requiredFor: ["accelerated", "full"]
1218
- },
1219
- {
1220
- id: "tasks",
1221
- path: "tasks.md",
1222
- producedBy: "tasks",
1223
- consumes: ["spec", "plan"],
1224
- requiredFor: ["accelerated", "full"]
1225
- },
1226
- {
1227
- id: "requirements-checklist",
1228
- path: "checklists/requirements.md",
1229
- producedBy: "checklist",
1230
- consumes: ["spec"],
1231
- requiredFor: []
1232
- },
1233
- {
1234
- id: "research",
1235
- path: "research.md",
1236
- producedBy: "plan",
1237
- consumes: ["spec"],
1238
- requiredFor: []
1239
- },
1240
- {
1241
- id: "data-model",
1242
- path: "data-model.md",
1243
- producedBy: "plan",
1244
- consumes: ["spec"],
1245
- requiredFor: []
1246
- },
1247
- {
1248
- id: "contracts",
1249
- path: "contracts/",
1250
- producedBy: "plan",
1251
- consumes: ["spec"],
1252
- requiredFor: []
1253
- },
1254
- {
1255
- id: "quickstart",
1256
- path: "quickstart.md",
1257
- producedBy: "plan",
1258
- consumes: ["spec", "plan"],
1259
- requiredFor: []
1260
- },
1261
- {
1262
- id: "plan-review",
1263
- path: "plan-review.md",
1264
- producedBy: "plan-review",
1265
- consumes: ["spec", "plan", "tasks"],
1266
- requiredFor: []
1267
- },
1268
- {
1269
- id: "verify-report",
1270
- path: "verify-report.md",
1271
- producedBy: "verify",
1272
- consumes: ["spec", "plan", "tasks"],
1273
- requiredFor: ["accelerated", "full"]
1274
- },
1275
- {
1276
- id: "archive-report",
1277
- path: "archive-report.md",
1278
- producedBy: "archive",
1279
- consumes: ["spec", "plan", "tasks", "verify-report"],
1280
- requiredFor: ["accelerated", "full"]
1281
- }
1282
- ];
1283
1316
  var SDD_ROUTE_EXECUTION_POLICIES = [
1284
1317
  {
1285
1318
  route: "direct",
@@ -1326,7 +1359,7 @@ var SDD_WORKFLOW_CONTRACT = {
1326
1359
  "Spec Kit artifact semantics are preserved inside the governed openspec store.",
1327
1360
  "Accelerated and full routes require spec.md, plan.md, tasks.md, verify-report.md, and archive-report.md.",
1328
1361
  "Research, data model, contracts, quickstart, requirements checklist, and plan-review.md are optional and created only when useful or selected.",
1329
- "The adaptive root writes coordination artifacts after loading the matching bundled phase contract; implementation ownership stays with the root or one writer role.",
1362
+ "The adaptive root writes coordination artifacts after loading the matching bundled phase contract; Accelerated and Full implementation selects designer, quick, or deep, while Direct permits one isolated low-risk root micro-action.",
1330
1363
  "After oracle PASS, archive transactionally synchronizes only explicitly declared durable ADDED, MODIFIED, REMOVED, and RENAMED requirement deltas into openspec/specs; INTERNAL requirements and undeclared prose never update permanent specifications.",
1331
1364
  "Archive stages and backs up writes so handled failures roll back within the active process; forced process or operating-system termination is not crash-atomic."
1332
1365
  ],
@@ -1372,20 +1405,6 @@ function getSddRouteExecutionPolicy(route) {
1372
1405
  validationGates: [...policy.validationGates]
1373
1406
  };
1374
1407
  }
1375
- function getSddArtifactGraph() {
1376
- return SDD_ARTIFACT_GRAPH.map((artifact) => ({
1377
- ...artifact,
1378
- consumes: [...artifact.consumes],
1379
- requiredFor: [...artifact.requiredFor]
1380
- }));
1381
- }
1382
- function getSddPhase(id) {
1383
- const phase = SDD_PHASES.find((candidate) => candidate.id === id);
1384
- if (!phase) {
1385
- throw new Error(`Unknown SDD phase: ${id}`);
1386
- }
1387
- return clonePhase(phase);
1388
- }
1389
1408
  function renderSddPhaseDispatchTemplate() {
1390
1409
  return `## PHASE
1391
1410
  phase=<phase-id>
@@ -1422,9 +1441,6 @@ authorization=<none|recall|observe>
1422
1441
  context:
1423
1442
  <bounded recalled context or - none>`;
1424
1443
  }
1425
- function getSddPhaseOwner(_route, phaseId) {
1426
- return getSddPhase(phaseId).defaultAgentRole;
1427
- }
1428
1444
  function getRequiredSddPhaseOrder(route) {
1429
1445
  return SDD_PHASES.filter(
1430
1446
  (phase) => phase.requiredFor.includes(route)
@@ -1479,15 +1495,25 @@ function roleTemplate(role) {
1479
1495
  return `{{role.${role}}}`;
1480
1496
  }
1481
1497
  function renderSddRoute(route) {
1482
- return getRequiredSddPhaseOrder(route).map(
1483
- (phase) => `${phase} (${roleTemplate(getSddPhaseOwner(route, phase))})`
1484
- ).join(" -> ");
1498
+ return getRequiredSddPhaseOrder(route).join(" -> ");
1499
+ }
1500
+ function renderImplementationOwnershipPolicy(policy) {
1501
+ return `<implementation-ownership>
1502
+ - SDD routes govern artifacts and gates, not implementation ownership.
1503
+ - Eligible owners in every route: ${policy.eligibleOwners.map((owner) => roleTemplate(owner)).join(", ")}.
1504
+ - Delegation benefits: ${policy.delegationBenefits.join("; ")}.
1505
+ - Root continuity benefits: ${policy.rootContinuityBenefits.join("; ")}.
1506
+ - Explicit safe user direction is an ownership input.
1507
+ - Insufficient signals: ${policy.insufficientSignals.join("; ")}.
1508
+ - Only after deciding delegation creates net gain: use ${roleTemplate("designer")} for UI/UX, ${roleTemplate("quick")} for known narrow low-risk work, and ${roleTemplate("deep")} for coupled or high-risk work.
1509
+ </implementation-ownership>`;
1485
1510
  }
1486
1511
  function renderRoleDirectory() {
1487
- return getAgentPackContract().roles.filter((role) => role.name !== "orchestrator").map((role) => `- ${roleTemplate(role.name)}: ${role.responsibility}`).join("\n");
1488
- }
1489
- function renderArtifactSummary() {
1490
- return getSddArtifactGraph().filter((artifact) => artifact.requiredFor.length === 0).map((artifact) => artifact.path).join(", ");
1512
+ return [
1513
+ `- ${roleTemplate("explorer")}: uncertain local discovery; read-only.`,
1514
+ `- ${roleTemplate("librarian")}: external evidence; read-only.`,
1515
+ `- ${roleTemplate("oracle")}: review/verify; read-only, never implementer.`
1516
+ ].join("\n");
1491
1517
  }
1492
1518
  function createOrchestratorPromptSections() {
1493
1519
  const workflow = getSddWorkflowContract();
@@ -1496,22 +1522,33 @@ function createOrchestratorPromptSections() {
1496
1522
  const full = getSddRouteExecutionPolicy("full");
1497
1523
  return [
1498
1524
  roleText(`<role>
1499
- You are the adaptive root for thoth-agents. Keep requirements, decisions, execution ownership, and final synthesis in this thread.
1525
+ You are the adaptive root for thoth-agents. Keep requirements, decisions, ownership, and synthesis here.
1500
1526
  </role>
1501
1527
 
1502
1528
  <operating-model>
1503
- - Handle bounded direct work when intent and risk are clear; never verify your own implementation.
1504
- - Delegate only for net gain from specialization, context isolation, review, or safe parallelism. The maximum delegation depth is ${policy.maxDelegationDepth}; children never delegate.
1505
- - Maintain one writer for each mutable surface. Parallelize only independent work with no overlapping writes.
1529
+ - Handle bounded implementation directly in any route when continuity outweighs delegation overhead; never self-verify.
1530
+ - The maximum delegation depth is ${policy.maxDelegationDepth}; children never delegate.
1531
+ - Keep one writer per mutable surface; parallelize only non-overlapping work.
1506
1532
  - Keep prompts bounded; request distilled evidence, not raw logs or full files.
1533
+ - Preserve unrelated changes; report changed files, evidence, risks, and capability gaps.
1507
1534
  - Use \`{{userQuestionTool}}\` only when a material unresolved choice changes the result. Continue all safe non-blocked work first.
1508
1535
  - Use \`{{progressTool}}\` only when the work genuinely has multiple dependent steps.
1509
1536
  </operating-model>
1510
1537
 
1538
+ <delegation-lifecycle>
1539
+ - A new objective, SDD phase, mutable surface, or independent judgment is a work boundary: start a fresh specialist using {{lifecycleFreshDelegation}}. Never treat completed agents as a reusable role pool.
1540
+ - Independent context: {{lifecycleIndependentContext}}.
1541
+ - Continue with {{lifecycleSameAssignmentContinuation}} only to steer, complete, or clarify the same bounded assignment; never to cross a work boundary.
1542
+ - {{lifecycleSameSessionProbe}} only collects the active nonterminal assignment and does not authorize later reuse.
1543
+ - Every Oracle plan review, verification round, and approval or PASS judgment uses a fresh Oracle instance. An existing Oracle session may only clarify its current findings.
1544
+ </delegation-lifecycle>
1545
+
1511
1546
  <routing>
1512
1547
  ${renderRoleDirectory()}
1513
1548
  </routing>
1514
1549
 
1550
+ ${renderImplementationOwnershipPolicy(policy.implementationOwnership)}
1551
+
1515
1552
  <sdd-routing>
1516
1553
  - An explicitly requested route wins: no duplicate route-selection prompt. Otherwise assess and recommend one route, ask with \`{{userQuestionTool}}\`, and wait for the user to select Direct, Accelerated, or Full. The recommendation is not the decision. The user's selected route wins; explain risk without overriding it. A generic SDD request sets Accelerated as the minimum unless Full risk applies.
1517
1554
  - Direct: clear, bounded, low-risk work. ${renderSddRoute("direct")}.
@@ -1527,6 +1564,7 @@ ${renderRoleDirectory()}
1527
1564
  - When implementation discoveries refine the same intent, update the canonical artifact and revalidate only affected downstream artifacts. Split a new change when the intent changes.
1528
1565
  - Load the bundled \`thoth-sdd\` skill only after selecting Accelerated or Full, then read only the reference for the current phase.
1529
1566
  - Root owns specify, clarify, plan, checklist, tasks, converge, and archive coordination; these phases are not delegated merely to change prompts.
1567
+ - Record owner, net-gain rationale, surface, requirements, and checks before implement or dispatch.
1530
1568
  - Delegate each user-selected plan review and every verify phase to ${roleTemplate("oracle")}. The implementation writer must never review itself.
1531
1569
  </sdd-routing>
1532
1570
 
@@ -1541,29 +1579,20 @@ ${renderRoleDirectory()}
1541
1579
  </external-skills>
1542
1580
 
1543
1581
  <memory>
1544
- - Load the installed \`thoth-mem\` skill for resume or prior work and provider-backed memory; never invent its protocol.
1545
- - Preserve a durable decision, root cause, convention, or discovery only when reusable. Root owns the stable root session ID, project, lifecycle, real-user intent, and authorization; never invent identity or confirmed effects.
1546
- - Follow the skill at verified compaction and a meaningful semantic boundary. Children receive only bounded MEMORY dispatch and never own root lifecycle.
1547
- - \`openspec/\` remains canonical; do not mirror SDD phase artifacts into provider memory. A memory failure degrades memory only and does not block unrelated implementation or verification.
1582
+ - Load the installed \`thoth-mem\` skill for resume or prior work; never invent its protocol.
1583
+ - Preserve a durable decision, root cause, convention, or discovery only when reusable. Root owns the stable root session ID, project, lifecycle, real-user intent, and authorization.
1584
+ - Follow the skill at verified compaction or a meaningful semantic boundary; children receive only bounded MEMORY and never own root lifecycle.
1585
+ - \`openspec/\` remains canonical; do not mirror SDD phase artifacts. A memory failure does not block unrelated work.
1548
1586
  </memory>
1549
1587
 
1550
1588
  <artifacts>
1551
- - Preserve Spec Kit semantics inside ${workflow.artifactRoot}.
1552
- - Accelerated and Full require spec.md, plan.md, tasks.md, verify-report.md, and archive-report.md; optional when useful: ${renderArtifactSummary()}.
1553
- - Root owns openspec/ coordination and thoth-sdd gates; product work has one writer, and root alone moves [~] -> [x] after evidence.
1554
- - ${roleTemplate("oracle")} returns read-only findings. Root persists verification; after PASS, archive syncs declared durable deltas and moves the change to openspec/changes/archive/YYYY-MM-DD-<feature>/.
1589
+ - In ${workflow.artifactRoot}, Accelerated and Full require spec.md, plan.md, tasks.md, verify-report.md, and archive-report.md.
1590
+ - Root owns openspec/ gates and task state, moves [~] -> [x] after evidence, and keeps one product writer.
1591
+ - ${roleTemplate("oracle")} returns read-only findings; root persists verification and archives declared durable deltas after PASS.
1555
1592
  </artifacts>
1556
1593
 
1557
- <execution>
1558
- - Validate contracts and tests first; use test-first work for behavior. Root or one writer implements; do not delegate merely because an agent exists.
1559
- - ${roleTemplate("oracle")} owns selected plan review and every verification; root and writers never self-approve.
1560
- - Preserve unrelated working-tree changes. Never instruct an agent to discard them.
1561
- - Report changed files, evidence, risks, and capability gaps truthfully.
1562
- </execution>
1563
-
1564
1594
  <delegation>
1565
- - Dispatch through \`{{delegationTool}}\` with this envelope; use the same boundaries for non-SDD work.
1566
- - Parallelize only independent work and await requested results before synthesis.
1595
+ - Use this envelope for all \`{{delegationTool}}\` delegation; parallelize only independent work and await results.
1567
1596
  - Child return fields: conclusion, evidence, verification, risks, openQuestions, nextAction.
1568
1597
 
1569
1598
  ${renderSddPhaseDispatchTemplate()}
@@ -1624,13 +1653,18 @@ You are ${roleName}.
1624
1653
 
1625
1654
  <responsibility>
1626
1655
  ${role.responsibility}
1627
- </responsibility>`),
1656
+ </responsibility>
1657
+
1658
+ <routing-contract>
1659
+ - Use when: ${role.useWhen.join(" ")}
1660
+ - Do not use when: ${role.doNotUseWhen.join(" ")}
1661
+ - Escalate when: ${role.escalateWhen.join(" ")}
1662
+ - Verification: ${role.verification.join(" ")}
1663
+ </routing-contract>`),
1628
1664
  createReasoningDisciplineSection(),
1629
1665
  roleText(`<rules>
1630
- - Do not delegate further or manage root progress.
1631
1666
  - ${modeRules.join("\n- ")}
1632
1667
  - ${ROLE_SPECIFIC_RULES[roleName].join("\n- ")}
1633
- - Ask only when a local blocking decision cannot be resolved from the assignment and evidence.
1634
1668
  </rules>`),
1635
1669
  createSubagentRulesSection(),
1636
1670
  createQuestionProtocolSection(),
@@ -1673,8 +1707,7 @@ Use \`${dialect.tools.userQuestionTool}\` only for a blocking material choice, d
1673
1707
  }
1674
1708
  function renderSubagentRules(section, dialect) {
1675
1709
  const rules = [
1676
- `- Do not delegate further or call \`${dialect.tools.progressTool}\`.`,
1677
- `- Use \`${dialect.tools.userQuestionTool}\` only for a local blocking choice.`,
1710
+ `- Do not delegate further or call \`${dialect.tools.progressTool}\`; root owns progress.`,
1678
1711
  "- Use terminating checks; avoid watch processes and indefinite waits.",
1679
1712
  "- Never discard or overwrite unrelated working-tree changes."
1680
1713
  ];
@@ -1741,6 +1774,15 @@ function renderRoleText(section, dialect) {
1741
1774
  ).replaceAll("{{userQuestionTool}}", dialect.tools.userQuestionTool).replaceAll("{{progressTool}}", dialect.tools.progressTool).replaceAll(
1742
1775
  "{{lifecycleStatusAction}}",
1743
1776
  dialect.tools.lifecycle.statusAction
1777
+ ).replaceAll(
1778
+ "{{lifecycleFreshDelegation}}",
1779
+ dialect.tools.lifecycle.freshDelegation
1780
+ ).replaceAll(
1781
+ "{{lifecycleIndependentContext}}",
1782
+ dialect.tools.lifecycle.independentContext
1783
+ ).replaceAll(
1784
+ "{{lifecycleSameAssignmentContinuation}}",
1785
+ dialect.tools.lifecycle.sameAssignmentContinuation
1744
1786
  ).replaceAll(
1745
1787
  "{{lifecycleTerminalState}}",
1746
1788
  dialect.tools.lifecycle.terminalState
@@ -1889,12 +1931,14 @@ export {
1889
1931
  loadAgentPrompt,
1890
1932
  getAgentOverride,
1891
1933
  getPrimaryModelId,
1934
+ getAgentRole,
1935
+ renderAgentRoutingDescription,
1936
+ getAgentPackContract,
1892
1937
  OPENCODE_PROMPT_DIALECT,
1893
1938
  CODEX_PROMPT_DIALECT,
1894
1939
  CLAUDE_CODE_SUBAGENT_NAMESPACE,
1895
1940
  claudeCodeSubagentType,
1896
1941
  CLAUDE_CODE_PROMPT_DIALECT,
1897
- getAgentPackContract,
1898
1942
  createStepBudgetSection,
1899
1943
  createModelFamilySection,
1900
1944
  createOrchestratorPromptSections,