@ionivetech/mugiwara 0.6.6 → 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 (138) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +2 -7
  3. package/.codex-plugin/plugin.json +2 -7
  4. package/.cursor-plugin/plugin.json +2 -7
  5. package/.kimi-plugin/plugin.json +2 -7
  6. package/.opencode/mugiwara-helpers.mjs +2 -2
  7. package/.opencode/plugins/mugiwara.mjs +3 -18
  8. package/AGENTS.md +5 -4
  9. package/GEMINI.md +3 -3
  10. package/README.md +203 -331
  11. package/content/agents/brook-healing.md +8 -4
  12. package/content/agents/chopper-checkpoint.md +7 -3
  13. package/content/agents/eval-runner.md +4 -4
  14. package/content/agents/franky-gates.md +4 -4
  15. package/content/agents/jinbe-security.md +6 -7
  16. package/content/agents/luffy-orchestrator.md +11 -13
  17. package/content/agents/memory-keeper.md +4 -4
  18. package/content/agents/nami-planner.md +4 -4
  19. package/content/agents/resume-coordinator.md +7 -7
  20. package/content/agents/robin-reviewer.md +7 -3
  21. package/content/agents/sanji-quality.md +2 -2
  22. package/content/agents/skeptic-verifier.md +2 -2
  23. package/content/agents/usopp-brainstorm.md +3 -3
  24. package/content/agents/zoro-execution.md +6 -6
  25. package/content/skills/mugiwara-backend/SKILL.md +54 -43
  26. package/content/skills/mugiwara-backend/references/database.md +61 -0
  27. package/content/skills/mugiwara-brainstorm/SKILL.md +1 -1
  28. package/content/skills/mugiwara-checkpoint/SKILL.md +23 -11
  29. package/content/skills/mugiwara-checkpoint/references/ledger-format.md +1 -1
  30. package/content/skills/mugiwara-contract-first/SKILL.md +46 -1
  31. package/content/skills/mugiwara-execution/SKILL.md +37 -37
  32. package/content/skills/mugiwara-execution/references/dispatch.md +1 -1
  33. package/content/skills/mugiwara-execution/references/execution-phase-flows.md +18 -0
  34. package/content/skills/mugiwara-execution/references/resume-batching.md +2 -2
  35. package/content/skills/mugiwara-frontend/SKILL.md +44 -43
  36. package/content/skills/mugiwara-frontend/references/checklist.md +14 -0
  37. package/content/skills/mugiwara-gates/SKILL.md +23 -14
  38. package/content/skills/mugiwara-healing/SKILL.md +26 -25
  39. package/content/skills/mugiwara-lessons/SKILL.md +2 -2
  40. package/content/skills/mugiwara-orchestration/SKILL.md +11 -11
  41. package/content/skills/mugiwara-orchestration/references/check-ins.md +2 -2
  42. package/content/skills/mugiwara-orchestration/references/closure.md +17 -12
  43. package/content/skills/mugiwara-orchestration/references/control-commands.md +14 -0
  44. package/content/skills/mugiwara-orchestration/references/triage-escalation.md +11 -1
  45. package/content/skills/mugiwara-planning/SKILL.md +26 -29
  46. package/content/skills/mugiwara-planning/references/large-campaign-subplan.md +41 -0
  47. package/content/skills/mugiwara-planning/references/plan-template.md +24 -2
  48. package/content/skills/mugiwara-quality/SKILL.md +21 -12
  49. package/content/skills/mugiwara-resume/SKILL.md +8 -3
  50. package/content/skills/mugiwara-review/SKILL.md +19 -13
  51. package/content/skills/mugiwara-security/SKILL.md +47 -36
  52. package/content/skills/mugiwara-ship/SKILL.md +1 -1
  53. package/content/skills/mugiwara-ship/references/cleanup.md +17 -16
  54. package/content/skills/mugiwara-workflow/SKILL.md +11 -17
  55. package/content/skills/mugiwara-workflow/references/adaptive-budget-governor.md +5 -0
  56. package/content/skills/mugiwara-workflow/references/benchmark-governor.md +53 -0
  57. package/content/skills/mugiwara-workflow/references/cognitive-output-governor.md +5 -0
  58. package/content/skills/mugiwara-workflow/references/large-campaign-subplan.md +29 -0
  59. package/content/skills/mugiwara-workflow/references/scope-code-governor.md +14 -0
  60. package/content/skills/mugiwara-workflow/references/stop-slop-governor.md +14 -0
  61. package/content/skills/mugiwara-workflow/references/workspace-layout.md +42 -38
  62. package/dist/mugiwara.js +1642 -528
  63. package/gemini-extension.json +1 -1
  64. package/hooks/auto-savepoint.js +18 -10
  65. package/hooks/auto-savepoint.ts +23 -23
  66. package/hooks/engagement-marker.js +1 -1
  67. package/hooks/engagement-marker.ts +1 -1
  68. package/hooks/pipeline-guard.js +17 -13
  69. package/hooks/pipeline-guard.ts +24 -20
  70. package/hooks/session-start.js +13 -10
  71. package/hooks/session-start.ts +24 -19
  72. package/package.json +2 -2
  73. package/plugin.json +1 -1
  74. package/references/complexity.md +27 -4
  75. package/references/definition-of-done.md +1 -1
  76. package/references/multi-actor.md +20 -2
  77. package/references/posture-routing.md +31 -0
  78. package/references/prose-style.md +54 -0
  79. package/scripts/benchmark-governor.ts +516 -0
  80. package/scripts/benchmark-thresholds.json +47 -0
  81. package/scripts/check-doc-links.ts +46 -0
  82. package/scripts/conformance.ts +6 -16
  83. package/scripts/coverage-gate.ts +20 -6
  84. package/scripts/gate-selftest.ts +138 -7
  85. package/scripts/lane.sh +54 -8
  86. package/scripts/lib/lane-base.sh +4 -4
  87. package/scripts/lib/patterns.sh +5 -0
  88. package/scripts/policy-force.ts +22 -0
  89. package/scripts/retrieval-eval.ts +10 -4
  90. package/scripts/savepoint.sh +155 -58
  91. package/scripts/validate-content.ts +43 -11
  92. package/scripts/verify-install.ts +9 -7
  93. package/src/adaptive-budget.ts +178 -0
  94. package/src/args.ts +4 -3
  95. package/src/budget.ts +47 -0
  96. package/src/check-artifacts.ts +45 -0
  97. package/src/cli.ts +257 -108
  98. package/src/cognition.ts +234 -0
  99. package/src/config.ts +107 -0
  100. package/src/context.ts +72 -0
  101. package/src/continue.ts +29 -10
  102. package/src/cost.ts +186 -0
  103. package/src/evidence.ts +160 -0
  104. package/src/installer.ts +25 -34
  105. package/src/integrity.ts +158 -0
  106. package/src/investigation.ts +72 -0
  107. package/src/mission.ts +341 -94
  108. package/src/policy.ts +156 -0
  109. package/src/posture.ts +86 -0
  110. package/src/provenance.ts +116 -0
  111. package/src/reporting.ts +225 -0
  112. package/src/rollback.ts +95 -0
  113. package/src/routing.ts +69 -0
  114. package/src/run.ts +2 -2
  115. package/src/scope.ts +321 -0
  116. package/src/sign.ts +235 -0
  117. package/src/slop.ts +306 -0
  118. package/src/targets/claude.ts +2 -2
  119. package/src/work.ts +273 -0
  120. package/.opencode/commands/mugiwara-execute.md +0 -13
  121. package/.opencode/commands/mugiwara-heal.md +0 -13
  122. package/.opencode/commands/mugiwara-onboard.md +0 -14
  123. package/.opencode/commands/mugiwara-plan.md +0 -17
  124. package/.opencode/commands/mugiwara-ship.md +0 -13
  125. package/.opencode/commands/using-mugiwara.md +0 -20
  126. package/content/skills/mugiwara-agent-security/SKILL.md +0 -58
  127. package/content/skills/mugiwara-agent-security/references/checklist.md +0 -20
  128. package/content/skills/mugiwara-context-budget/SKILL.md +0 -66
  129. package/content/skills/mugiwara-context-budget/references/context-budget.md +0 -37
  130. package/content/skills/mugiwara-pr/SKILL.md +0 -69
  131. package/content/skills/mugiwara-pr/references/verdict-format.md +0 -31
  132. package/content/skills/mugiwara-sunset/SKILL.md +0 -82
  133. package/content/skills/using-mugiwara/SKILL.md +0 -51
  134. package/references/token-budget.md +0 -56
  135. package/scripts/evidence.sh +0 -81
  136. package/scripts/initiative.ts +0 -296
  137. package/scripts/mission-report.sh +0 -293
  138. package/src/onboard.ts +0 -207
@@ -0,0 +1,178 @@
1
+ // src/adaptive-budget.ts
2
+ // Phase 7 Adaptive Budget & Circuit Breaker — reservation, projection,
3
+ // adaptive/expansion, progressive thresholds, circuit breaker, anomaly
4
+ // (Native Cost Governor, plan §51 Phase 7, §24–§29).
5
+ //
6
+ // Boundary: pure verdict functions over explicit inputs (unit-testable), plus a
7
+ // record helper that persists via the sanitized recordOptDecision (§41). No new
8
+ // config keys; savepoint.sh/lane-base.sh untouched. The crew acts — this module
9
+ // records.
10
+
11
+ import { recordOptDecision } from './cost.ts';
12
+
13
+ // ── Budget reservation (§25) ──
14
+
15
+ export type BudgetReservation = { remaining: number; expected_max: number; available: number; reserved: number };
16
+
17
+ export function reserveBudget(input: { remaining: number; expected_max: number }): BudgetReservation {
18
+ const reserved = input.expected_max;
19
+ const available = Math.max(0, input.remaining - reserved);
20
+ return { remaining: input.remaining, expected_max: input.expected_max, available, reserved };
21
+ }
22
+
23
+ // ── Budget projection (§26) ──
24
+
25
+ export type BudgetProjection = {
26
+ current: number;
27
+ remaining_required: number;
28
+ expected_conditional: number;
29
+ possible_healing: number;
30
+ projected_min: number;
31
+ projected_max: number;
32
+ };
33
+
34
+ export function projectBudget(input: {
35
+ current: number;
36
+ remaining_required: number;
37
+ expected_conditional: number;
38
+ possible_healing: number;
39
+ }): BudgetProjection {
40
+ const projected_min = input.current + input.remaining_required + input.expected_conditional;
41
+ const projected_max = projected_min + input.possible_healing;
42
+ return {
43
+ current: input.current,
44
+ remaining_required: input.remaining_required,
45
+ expected_conditional: input.expected_conditional,
46
+ possible_healing: input.possible_healing,
47
+ projected_min,
48
+ projected_max,
49
+ };
50
+ }
51
+
52
+ // ── Evidence-backed expansion (§27) ──
53
+
54
+ export type ExpansionInput = {
55
+ reason: string;
56
+ has_evidence: boolean;
57
+ scope_expanded?: boolean;
58
+ security_path?: boolean;
59
+ test_surface_expanded?: boolean;
60
+ architecture_dependency?: boolean;
61
+ legitimate_healing?: boolean;
62
+ };
63
+
64
+ export type ExpansionVerdict = { allowed: boolean; reason: string };
65
+
66
+ const VALID_REASONS = new Set([
67
+ 'scope legitimately expanded',
68
+ 'security-sensitive path',
69
+ 'test surface larger',
70
+ 'architecture dependency',
71
+ 'legitimate healing',
72
+ ]);
73
+
74
+ function isValidReason(reason: string): boolean {
75
+ return VALID_REASONS.has(reason);
76
+ }
77
+
78
+ function hasValidFlag(input: ExpansionInput): boolean {
79
+ return !!(
80
+ input.scope_expanded ||
81
+ input.security_path ||
82
+ input.test_surface_expanded ||
83
+ input.architecture_dependency ||
84
+ input.legitimate_healing
85
+ );
86
+ }
87
+
88
+ export function evaluateExpansion(input: ExpansionInput): ExpansionVerdict {
89
+ if (!input.has_evidence) {
90
+ return { allowed: false, reason: 'deny — no evidence' };
91
+ }
92
+ if (!input.reason || !isValidReason(input.reason)) {
93
+ return { allowed: false, reason: `deny — invalid reason: ${input.reason || '(empty)'}` };
94
+ }
95
+ if (!hasValidFlag(input)) {
96
+ return { allowed: false, reason: `deny — valid reason ${input.reason} but no matching flag set` };
97
+ }
98
+ return { allowed: true, reason: `allow — ${input.reason} with evidence` };
99
+ }
100
+
101
+ // ── Progressive thresholds (§28) ──
102
+
103
+ export type AdaptiveStatus = 'ok' | 'optimize' | 'aggressive' | 'protect' | 'pause' | 'warning' | 'stop';
104
+
105
+ export function checkProgressiveThreshold(input: { budget: number; used: number }): { status: AdaptiveStatus; pct: number } {
106
+ const pct = input.budget > 0 ? Math.round((input.used / input.budget) * 100) : 0;
107
+ let status: AdaptiveStatus = 'ok';
108
+ if (pct >= 300) status = 'stop';
109
+ else if (pct >= 150) status = 'warning';
110
+ else if (pct >= 100) status = 'pause';
111
+ else if (pct >= 90) status = 'protect';
112
+ else if (pct >= 75) status = 'aggressive';
113
+ else if (pct >= 60) status = 'optimize';
114
+ return { status, pct };
115
+ }
116
+
117
+ // ── Cost circuit breaker (§29) ──
118
+
119
+ export type CircuitBreakerInput = {
120
+ expected: number;
121
+ actual: number;
122
+ progress_delta: number;
123
+ scope_expanded: boolean;
124
+ evidence_delta: number;
125
+ };
126
+
127
+ export type CircuitBreakerVerdict = { tripped: boolean; reason: string };
128
+
129
+ export function checkCircuitBreaker(input: CircuitBreakerInput): CircuitBreakerVerdict {
130
+ // note: double-threshold (actual >= expected*2), tune if §29 needs finer signal
131
+ const doubled = input.expected * 2;
132
+ const noProgress = input.progress_delta === 0;
133
+ const noScopeOrEvidence = !input.scope_expanded && input.evidence_delta === 0;
134
+ const overDoubled = input.actual >= doubled;
135
+ if (overDoubled && noProgress && noScopeOrEvidence) {
136
+ return { tripped: true, reason: `breaker tripped — actual ${input.actual} ≥ 2× expected ${input.expected} with no progress/scope/evidence` };
137
+ }
138
+ if (!overDoubled) return { tripped: false, reason: `no breaker — actual ${input.actual} < 2× expected ${input.expected}` };
139
+ if (!noProgress) return { tripped: false, reason: 'no breaker — progress made' };
140
+ return { tripped: false, reason: 'no breaker — scope expanded or evidence gained' };
141
+ }
142
+
143
+ // ── Budget anomaly (§24, re-consumes slop 5k-zero-progress signal) ──
144
+
145
+ export type BudgetAnomalyInput = {
146
+ progress_before: number;
147
+ progress_after: number;
148
+ tokens_before: number;
149
+ tokens_after: number;
150
+ };
151
+
152
+ export type BudgetAnomaly = { anomaly: boolean; reason: string };
153
+
154
+ export function detectBudgetAnomaly(input: BudgetAnomalyInput): BudgetAnomaly {
155
+ const tokens_delta = input.tokens_after - input.tokens_before;
156
+ const progress_delta = input.progress_after - input.progress_before;
157
+ if (tokens_delta >= 5000 && progress_delta === 0) {
158
+ return { anomaly: true, reason: `anomaly — ${tokens_delta} tokens with no progress` };
159
+ }
160
+ if (tokens_delta < 5000 && progress_delta === 0) {
161
+ return { anomaly: false, reason: `no anomaly — ${tokens_delta} tokens below 5k floor` };
162
+ }
163
+ return { anomaly: false, reason: `no anomaly — progress ${progress_delta} over ${tokens_delta} tokens` };
164
+ }
165
+
166
+ // ── Decision trail (§41) ──
167
+
168
+ export function recordBudgetDecision(
169
+ missionDir: string,
170
+ d: { decision: string; reason: string; evidence?: string },
171
+ ): void {
172
+ recordOptDecision(missionDir, {
173
+ actor: 'budget-governor',
174
+ decision: d.decision,
175
+ reason: d.reason,
176
+ evidence: d.evidence,
177
+ });
178
+ }
package/src/args.ts CHANGED
@@ -6,11 +6,12 @@ export type Args = {
6
6
  flags: Record<string, FlagValue>;
7
7
  };
8
8
 
9
- const VALUE_FLAGS: Record<string, string> = { '--project': 'project', '--target': 'target' };
9
+ const VALUE_FLAGS: Record<string, string> = { '--project': 'project', '--target': 'target', '--before': 'before', '--backend': 'backend', '--mission': 'mission' };
10
10
  const BOOL_FLAGS: Record<string, string> = {
11
11
  '--global': 'global', '--yes': 'yes', '-y': 'yes', '--force': 'force',
12
- '--dry-run': 'dryRun', '--keep-logs': 'keepLogs', '--check': 'check', '--all': 'all',
13
- '--help': 'help', '-h': 'help', '--version': 'version', '-v': 'version',
12
+ '--dry-run': 'dryRun', '--keep-logs': 'keepLogs', '--check': 'check', '--all': 'all', '--verify': 'verify',
13
+ '--gen-key': 'genKey', '--help': 'help', '-h': 'help', '--version': 'version', '-v': 'version',
14
+ '--json': 'json', '--ledger': 'ledger',
14
15
  };
15
16
 
16
17
  export function parseArgs(argv: string[]): Args {
package/src/budget.ts ADDED
@@ -0,0 +1,47 @@
1
+ // src/budget.ts
2
+ // Context budget as a gate: a mission's trail is itself
3
+ // context the next reader must load. At archive time, measure the total
4
+ // footprint of the artifacts that survive and compare against the configured
5
+ // ceiling — a bloated trail is caught like a failed test, with a visible
6
+ // number in the report.
7
+ //
8
+ // Token telemetry stays honest elsewhere: the estimator remains the default;
9
+ // `tokens_source: reported` activates only where the harness exposes real
10
+ // usage (see docs/concepts/cost.md). This module does not estimate tokens.
11
+ import { existsSync, readdirSync, statSync } from 'node:fs';
12
+ import { join } from 'node:path';
13
+ import { readConfig } from './config.ts';
14
+
15
+ export function readBudgetConfig(projectDir: string): number {
16
+ const cfg = readConfig(projectDir);
17
+ const raw = cfg.context_budget_chars;
18
+ if (raw === undefined || raw === '') return 0;
19
+ const n = Number(raw);
20
+ return Number.isFinite(n) && n > 0 ? n : 0;
21
+ }
22
+
23
+ /** Sum of bytes across the trail: top-level *.md + flows/* (legacy waves/* counts too). */
24
+ export function measureContextChars(missionDir: string): number {
25
+ let total = 0;
26
+ const add = (p: string): void => {
27
+ try { total += statSync(p).size; } catch { /* vanished mid-measure */ }
28
+ };
29
+ for (const f of readdirSync(missionDir)) {
30
+ if (/\.md$/.test(f)) add(join(missionDir, f));
31
+ }
32
+ for (const sub of ['flows', 'waves']) {
33
+ const dir = join(missionDir, sub);
34
+ if (existsSync(dir)) {
35
+ for (const f of readdirSync(dir)) add(join(dir, f));
36
+ }
37
+ }
38
+ return total;
39
+ }
40
+
41
+ export function formatFootprint(chars: number, budget: number): string {
42
+ const base = `Context footprint: ${chars} chars`;
43
+ if (!budget) return `${base} (no budget configured)`;
44
+ return chars > budget
45
+ ? `${base} — OVER budget ${budget}`
46
+ : `${base} (budget ${budget})`;
47
+ }
@@ -0,0 +1,45 @@
1
+ // src/check-artifacts.ts
2
+ // Mission artifact gate (roadmap v0.8 item 4): every Lane 2+ mission must
3
+ // carry its evidence trail — plan.md (the contract) and flows/* execution
4
+ // evidence — or the archive refuses to fold, same as the secret gate.
5
+ // Lane 0/1 missions are audit-lite: no plan/flows required.
6
+ import { existsSync, readFileSync, readdirSync } from 'node:fs';
7
+ import { join } from 'node:path';
8
+
9
+ export interface ArtifactCheck {
10
+ ok: boolean;
11
+ missing: string[];
12
+ lane: string | null;
13
+ }
14
+
15
+ const LANE_MIN = new Set(['standard', 'full', 'spike']);
16
+
17
+ /** Lane 2+ (standard/full/spike) missions require the evidence trail. */
18
+ export function checkMissionArtifacts(missionDir: string): ArtifactCheck {
19
+ const statePath = join(missionDir, 'state.json');
20
+ if (!existsSync(statePath)) {
21
+ // archived mission (report.md survives, state folded away) — nothing to check
22
+ return { ok: true, missing: [], lane: null };
23
+ }
24
+ let lane = 'unknown';
25
+ try {
26
+ const s = JSON.parse(readFileSyncSafe(statePath)) as Record<string, unknown>;
27
+ if (typeof s.lane === 'string') lane = s.lane;
28
+ } catch { /* unreadable state → treat as unknown lane */ }
29
+
30
+ if (!LANE_MIN.has(lane)) {
31
+ return { ok: true, missing: [], lane }; // audit-lite lanes pass without trail
32
+ }
33
+
34
+ const missing: string[] = [];
35
+ if (!existsSync(join(missionDir, 'plan.md'))) missing.push('plan.md');
36
+ const flowsDir = join(missionDir, 'flows');
37
+ const hasFlows = existsSync(flowsDir) && readdirSync(flowsDir).length > 0;
38
+ if (!hasFlows) missing.push('flows/ (no execution evidence)');
39
+
40
+ return { ok: missing.length === 0, missing, lane };
41
+ }
42
+
43
+ function readFileSyncSafe(p: string): string {
44
+ try { return readFileSync(p, 'utf8'); } catch { return ''; }
45
+ }