@ionivetech/mugiwara 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.cursor-plugin/plugin.json +1 -1
  5. package/.kimi-plugin/plugin.json +1 -1
  6. package/.opencode/mugiwara-helpers.mjs +2 -2
  7. package/README.md +194 -328
  8. package/content/agents/franky-gates.md +1 -1
  9. package/content/agents/luffy-orchestrator.md +2 -2
  10. package/content/skills/mugiwara-backend/SKILL.md +52 -43
  11. package/content/skills/mugiwara-checkpoint/SKILL.md +19 -8
  12. package/content/skills/mugiwara-contract-first/SKILL.md +46 -1
  13. package/content/skills/mugiwara-execution/SKILL.md +32 -32
  14. package/content/skills/mugiwara-execution/references/execution-phase-flows.md +18 -0
  15. package/content/skills/mugiwara-frontend/SKILL.md +44 -44
  16. package/content/skills/mugiwara-gates/SKILL.md +22 -16
  17. package/content/skills/mugiwara-healing/SKILL.md +26 -25
  18. package/content/skills/mugiwara-orchestration/SKILL.md +6 -6
  19. package/content/skills/mugiwara-orchestration/references/control-commands.md +14 -0
  20. package/content/skills/mugiwara-planning/SKILL.md +26 -14
  21. package/content/skills/mugiwara-planning/references/large-campaign-subplan.md +41 -0
  22. package/content/skills/mugiwara-planning/references/plan-template.md +22 -0
  23. package/content/skills/mugiwara-quality/SKILL.md +19 -13
  24. package/content/skills/mugiwara-resume/SKILL.md +6 -1
  25. package/content/skills/mugiwara-review/SKILL.md +17 -12
  26. package/content/skills/mugiwara-security/SKILL.md +46 -35
  27. package/content/skills/mugiwara-workflow/SKILL.md +6 -9
  28. package/content/skills/mugiwara-workflow/references/adaptive-budget-governor.md +5 -0
  29. package/content/skills/mugiwara-workflow/references/benchmark-governor.md +53 -0
  30. package/content/skills/mugiwara-workflow/references/cognitive-output-governor.md +5 -0
  31. package/content/skills/mugiwara-workflow/references/large-campaign-subplan.md +29 -0
  32. package/content/skills/mugiwara-workflow/references/scope-code-governor.md +14 -0
  33. package/content/skills/mugiwara-workflow/references/stop-slop-governor.md +14 -0
  34. package/content/skills/mugiwara-workflow/references/workspace-layout.md +6 -3
  35. package/dist/mugiwara.js +925 -253
  36. package/gemini-extension.json +1 -1
  37. package/hooks/pipeline-guard.js +1 -1
  38. package/hooks/pipeline-guard.ts +2 -1
  39. package/package.json +2 -2
  40. package/plugin.json +1 -1
  41. package/references/multi-actor.md +21 -0
  42. package/references/posture-routing.md +31 -0
  43. package/scripts/benchmark-governor.ts +516 -0
  44. package/scripts/benchmark-thresholds.json +47 -0
  45. package/scripts/check-doc-links.ts +8 -2
  46. package/scripts/gate-selftest.ts +20 -0
  47. package/scripts/lib/lane-base.sh +4 -4
  48. package/scripts/retrieval-eval.ts +9 -3
  49. package/scripts/savepoint.sh +20 -1
  50. package/scripts/validate-content.ts +22 -3
  51. package/src/adaptive-budget.ts +178 -0
  52. package/src/args.ts +3 -2
  53. package/src/budget.ts +7 -16
  54. package/src/check-artifacts.ts +45 -0
  55. package/src/cli.ts +102 -4
  56. package/src/cognition.ts +234 -0
  57. package/src/config.ts +107 -0
  58. package/src/context.ts +72 -0
  59. package/src/cost.ts +186 -0
  60. package/src/evidence.ts +160 -0
  61. package/src/installer.ts +2 -16
  62. package/src/integrity.ts +1 -1
  63. package/src/investigation.ts +72 -0
  64. package/src/mission.ts +124 -10
  65. package/src/posture.ts +86 -0
  66. package/src/reporting.ts +225 -0
  67. package/src/scope.ts +321 -0
  68. package/src/sign.ts +194 -20
  69. package/src/slop.ts +306 -0
  70. package/src/work.ts +273 -0
package/src/work.ts ADDED
@@ -0,0 +1,273 @@
1
+ // src/work.ts
2
+ // Phase 3 Work Governor — verdict engine + decision trail
3
+ // (Native Cost Governor initiative, plan §51 Phase 3, spec §7/§8/§9/§19/§30/§41).
4
+ //
5
+ // Turns the Phase-2 signals into auditable skip/avoid/delegate/complete
6
+ // verdicts. Honest boundary (same as Phase 2 for investigation.ts): this
7
+ // module PRODUCES and RECORDS verdicts; the LLM crew (workflow skill, T4) is
8
+ // the only thing that acts on them. The module makes the decision structured
9
+ // and auditable — it does not pretend a TS function can force the model.
10
+ //
11
+ // Every verdict is a pure function of explicit inputs (unit-testable, parity
12
+ // locked by fixtures) and every skip/avoid/delegate/complete decision lands in
13
+ // the trail via recordWorkDecision → recordOptDecision (§41, S2 sanitizer).
14
+ import { delegateAt, laneBaseForLane, recordOptDecision } from './cost.ts';
15
+
16
+ // ── Stage classification (§7/§34) ───────────────────────────────────────────
17
+
18
+ export type StageClass = 'required' | 'conditional' | 'optional';
19
+
20
+ export type StageClassifyInput = {
21
+ stage: string;
22
+ requirement_kind: 'explicit' | 'exploratory' | 'ambiguous';
23
+ uncertainty_high: boolean;
24
+ provides_required_evidence: boolean;
25
+ protects_quality_security: boolean;
26
+ };
27
+
28
+ export type StageClassifyVerdict = { stage: string; class: StageClass; reason: string };
29
+
30
+ /**
31
+ * Classify a flow stage as required/conditional/optional. A stage that
32
+ * protects quality/security or provides required evidence is `required`
33
+ * (never skipped); a stage with high uncertainty or a non-explicit
34
+ * requirement is `conditional`; everything else is `optional`.
35
+ */
36
+ export function classifyStage(input: StageClassifyInput): StageClassifyVerdict {
37
+ if (input.protects_quality_security) {
38
+ return { stage: input.stage, class: 'required', reason: 'protects quality/security — required' };
39
+ }
40
+ if (input.provides_required_evidence) {
41
+ return { stage: input.stage, class: 'required', reason: 'provides required evidence — required' };
42
+ }
43
+ if (input.uncertainty_high || input.requirement_kind !== 'explicit') {
44
+ return { stage: input.stage, class: 'conditional', reason: 'uncertain or non-explicit requirement — conditional' };
45
+ }
46
+ return { stage: input.stage, class: 'optional', reason: 'explicit, no protection/evidence need — optional' };
47
+ }
48
+
49
+ // ── Evidence-backed stage skipping (§7/§13) ─────────────────────────────────
50
+
51
+ export type SkipInput = {
52
+ stage: string;
53
+ classification: StageClass;
54
+ evidence_present: boolean;
55
+ investigation_stopped: boolean;
56
+ context_over: boolean;
57
+ };
58
+
59
+ export type SkipVerdict = { stage: string; skip: boolean; reason: string; evidence?: string };
60
+
61
+ /**
62
+ * Decide whether a classified stage may be skipped on evidence. `required`
63
+ * never skips (protects quality/security). `conditional` skips when evidence
64
+ * already answers or the investigation stopped; `optional` skips when
65
+ * evidence answers or the context is over budget. Every skip carries an
66
+ * explicit reason (§7 — never skipped silently).
67
+ */
68
+ export function shouldSkipStage(input: SkipInput): SkipVerdict {
69
+ if (input.classification === 'required') {
70
+ return { stage: input.stage, skip: false, reason: 'required — protects quality/security' };
71
+ }
72
+ if (input.classification === 'conditional') {
73
+ if (input.evidence_present) {
74
+ return { stage: input.stage, skip: true, reason: 'evidence already answers', evidence: input.stage };
75
+ }
76
+ if (input.investigation_stopped) {
77
+ return { stage: input.stage, skip: true, reason: 'investigation stopped — no further value' };
78
+ }
79
+ return { stage: input.stage, skip: false, reason: 'conditional — no skip signal; run' };
80
+ }
81
+ // optional
82
+ if (input.evidence_present) {
83
+ return { stage: input.stage, skip: true, reason: 'evidence already answers', evidence: input.stage };
84
+ }
85
+ if (input.context_over) {
86
+ return { stage: input.stage, skip: true, reason: 'context over budget — tighten, do not expand' };
87
+ }
88
+ return { stage: input.stage, skip: false, reason: 'optional — no skip signal; run' };
89
+ }
90
+
91
+ // ── Agent invocation control (§8) ───────────────────────────────────────────
92
+
93
+ export type InvocationInput = {
94
+ agent: string;
95
+ unique_responsibility: boolean;
96
+ evidence_answers: boolean;
97
+ stage_can_perform: boolean;
98
+ expected_value_gt_cost: boolean;
99
+ };
100
+
101
+ export type InvocationVerdict = { agent: string; invoke: boolean; reason: string };
102
+
103
+ /**
104
+ * Decide whether an agent earns invocation. Invoke only when the agent has
105
+ * unique responsibility, evidence cannot answer, the stage cannot perform
106
+ * itself, and expected value exceeds cost. Never invoke merely because the
107
+ * agent exists in the crew. On refusal, name the first failing clause.
108
+ */
109
+ export function evaluateInvocation(input: InvocationInput): InvocationVerdict {
110
+ if (!input.unique_responsibility) {
111
+ return { agent: input.agent, invoke: false, reason: 'no unique responsibility' };
112
+ }
113
+ if (input.evidence_answers) {
114
+ return { agent: input.agent, invoke: false, reason: 'evidence already answers' };
115
+ }
116
+ if (input.stage_can_perform) {
117
+ return { agent: input.agent, invoke: false, reason: 'stage can perform itself' };
118
+ }
119
+ if (!input.expected_value_gt_cost) {
120
+ return { agent: input.agent, invoke: false, reason: 'expected value not greater than cost' };
121
+ }
122
+ return { agent: input.agent, invoke: true, reason: 'unique responsibility, evidence cannot answer, value exceeds cost' };
123
+ }
124
+
125
+ // ── Skill loading control (§9) ──────────────────────────────────────────────
126
+
127
+ export type SkillInput = {
128
+ skill: string;
129
+ required_by_task: boolean;
130
+ required_by_policy: boolean;
131
+ required_by_dependency: boolean;
132
+ failing_verification: boolean;
133
+ };
134
+
135
+ export type SkillVerdict = { skill: string; load: boolean; reason: string };
136
+
137
+ /**
138
+ * Decide whether a skill earns loading — minimum sufficient set (§9): load
139
+ * only when required by the task, by policy, by a dependency, or by a failing
140
+ * verification. Else refuse with the standard reason.
141
+ */
142
+ export function shouldLoadSkill(input: SkillInput): SkillVerdict {
143
+ if (input.required_by_task) return { skill: input.skill, load: true, reason: 'required by task' };
144
+ if (input.required_by_policy) return { skill: input.skill, load: true, reason: 'required by policy' };
145
+ if (input.required_by_dependency) return { skill: input.skill, load: true, reason: 'required by dependency' };
146
+ if (input.failing_verification) return { skill: input.skill, load: true, reason: 'required by failing verification' };
147
+ return { skill: input.skill, load: false, reason: 'not required by task/policy/dependency/verification' };
148
+ }
149
+
150
+ // ── Delegation optimization (§30, consumes delegateAt + laneBaseForLane) ────
151
+
152
+ export type DelegationInput = {
153
+ lane: string;
154
+ budget: number;
155
+ tokens_used: number;
156
+ threshold_pct: number;
157
+ independent_tasks: number;
158
+ parallel_value: number;
159
+ estimated_overhead: number;
160
+ };
161
+
162
+ export type DelegationVerdict = {
163
+ delegate: boolean;
164
+ reason: string;
165
+ budget_at: number;
166
+ lane_base: number;
167
+ parallel_value: number;
168
+ overhead: number;
169
+ };
170
+
171
+ /**
172
+ * Decide whether delegation is worthwhile. Closes the Phase-2 Q1 remainder:
173
+ * budget ceiling = delegateAt(budget, threshold_pct); overhead floor = one
174
+ * delegate costs at least one agent's context load (laneBaseForLane). Delegate
175
+ * only when there are ≥2 independent tasks, parallel value beats the overhead
176
+ * floor, and usage is inside the delegation budget. Else refuse naming the
177
+ * failing clause.
178
+ */
179
+ export function evaluateDelegation(input: DelegationInput): DelegationVerdict {
180
+ const budget_at = delegateAt(input.budget, input.threshold_pct);
181
+ const lane_base = laneBaseForLane(input.lane);
182
+ const overhead = Math.max(input.estimated_overhead, lane_base);
183
+ if (input.independent_tasks < 2) {
184
+ return {
185
+ delegate: false,
186
+ reason: 'not enough independent tasks (needs >= 2)',
187
+ budget_at,
188
+ lane_base,
189
+ parallel_value: input.parallel_value,
190
+ overhead,
191
+ };
192
+ }
193
+ if (input.parallel_value <= overhead) {
194
+ return {
195
+ delegate: false,
196
+ reason: 'parallel value not greater than overhead',
197
+ budget_at,
198
+ lane_base,
199
+ parallel_value: input.parallel_value,
200
+ overhead,
201
+ };
202
+ }
203
+ if (input.tokens_used > budget_at) {
204
+ return {
205
+ delegate: false,
206
+ reason: 'over delegation budget',
207
+ budget_at,
208
+ lane_base,
209
+ parallel_value: input.parallel_value,
210
+ overhead,
211
+ };
212
+ }
213
+ return {
214
+ delegate: true,
215
+ reason: 'parallel value exceeds overhead and within budget',
216
+ budget_at,
217
+ lane_base,
218
+ parallel_value: input.parallel_value,
219
+ overhead,
220
+ };
221
+ }
222
+
223
+ // ── Completion detection (§19) ──────────────────────────────────────────────
224
+
225
+ export type CompletionInput = {
226
+ acceptance_satisfied: boolean;
227
+ implementation_complete: boolean;
228
+ tests_complete: boolean;
229
+ quality_gates_complete: boolean;
230
+ evidence_collected: boolean;
231
+ };
232
+
233
+ export type CompletionVerdict = { complete: boolean; missing: string[]; reason: string };
234
+
235
+ const COMPLETION_FIELDS: Array<keyof CompletionInput> = [
236
+ 'acceptance_satisfied',
237
+ 'implementation_complete',
238
+ 'tests_complete',
239
+ 'quality_gates_complete',
240
+ 'evidence_collected',
241
+ ];
242
+
243
+ /**
244
+ * A mission is complete only when all five §19 conditions hold. `missing`
245
+ * lists every condition still open; `reason` is `ready for closure` or the
246
+ * comma-joined missing list.
247
+ */
248
+ export function completionCheck(input: CompletionInput): CompletionVerdict {
249
+ const missing = COMPLETION_FIELDS.filter((f) => !input[f]);
250
+ if (missing.length === 0) {
251
+ return { complete: true, missing: [], reason: 'ready for closure' };
252
+ }
253
+ return { complete: false, missing, reason: `missing: ${missing.join(', ')}` };
254
+ }
255
+
256
+ // ── Decision trail (§41) ────────────────────────────────────────────────────
257
+
258
+ /**
259
+ * Record any skip/avoid/delegate/complete verdict as an optimization decision
260
+ * with the `work-governor` actor. Thin wrapper over the sanitized
261
+ * recordOptDecision (S2 — newline/CR stripped, no markdown injection).
262
+ */
263
+ export function recordWorkDecision(
264
+ missionDir: string,
265
+ d: { decision: string; reason: string; evidence?: string },
266
+ ): void {
267
+ recordOptDecision(missionDir, {
268
+ actor: 'work-governor',
269
+ decision: d.decision,
270
+ reason: d.reason,
271
+ ...(d.evidence ? { evidence: d.evidence } : {}),
272
+ });
273
+ }