godpowers 1.6.14 → 1.6.16

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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,70 @@ All notable changes to Godpowers will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.6.16] - 2026-05-16
9
+
10
+ Feature awareness for existing Godpowers projects.
11
+
12
+ ### Added
13
+ - Added `lib/feature-awareness.js` to detect stale project awareness after a
14
+ Godpowers runtime upgrade.
15
+ - Added state recording for the current Godpowers feature set so existing
16
+ projects can tell whether their context has learned about new capabilities.
17
+ - Added behavioral tests for feature-awareness detection, safe state refresh,
18
+ AI-tool context refresh, migration suggestions, and `god-greenfieldifier`
19
+ escalation.
20
+
21
+ ### Changed
22
+ - `AGENTS.md` context refresh now advertises `/god-sync`, `/god-migrate`, and
23
+ `/god-context refresh` so AI tools opening an existing project see the new
24
+ migration and awareness commands.
25
+ - `/god-doctor`, `/god-context`, `/god-sync`, and `/god-mode` now document the
26
+ feature-awareness auto-invoke path for existing `.godpowers` projects.
27
+ - `state.v1.json` now accepts the `godpowers-features` awareness record.
28
+
29
+ ### Guardrails
30
+ - Detection is read-only by default.
31
+ - The apply path writes only safe state metadata and managed context fences.
32
+ - Ambiguous planning-system evidence is reported as a scoped
33
+ `god-greenfieldifier` recommendation instead of being converted blindly.
34
+
35
+ ## [1.6.15] - 2026-05-16
36
+
37
+ Planning-system migration and sync-back.
38
+
39
+ ### Added
40
+ - Added `lib/planning-systems.js` to detect GSD, BMAD, and Superpowers
41
+ planning context and convert useful signals into Godpowers prep and seed
42
+ artifacts.
43
+ - Added `lib/source-sync.js` to write current Godpowers progress back into
44
+ managed companion files for imported planning systems.
45
+ - Added `/god-migrate` as the explicit command for planning-system detection,
46
+ import, sync-back, and specialist escalation when migration evidence is
47
+ ambiguous.
48
+ - Added `docs/planning-system-migration.md` with detection signals, import
49
+ mapping, sync-back destinations, conflict rules, and return-path guidance.
50
+ - Added behavioral tests for GSD, BMAD, Superpowers, imported seed artifacts,
51
+ state recording, and idempotent sync-back.
52
+
53
+ ### Changed
54
+ - `/god-init` now auto-invokes planning-system import when GSD, BMAD, or
55
+ Superpowers evidence is detected.
56
+ - `/god-sync` now auto-invokes source-system sync-back when `state.json`
57
+ records enabled source systems.
58
+ - `reverse-sync` now includes source-system sync-back in its runtime result.
59
+ - `state.v1.json` now records imported source systems, import hashes,
60
+ sync-back hashes, conflict counts, and sync-back policy.
61
+
62
+ ### Guardrails
63
+ - Imported planning context remains `[HYPOTHESIS]` until confirmed by the user
64
+ or a Godpowers artifact.
65
+ - Existing Godpowers artifacts are preserved unless the user explicitly forces
66
+ overwrite.
67
+ - Source-system files are not rewritten outside Godpowers-owned fences or
68
+ companion files.
69
+ - Low-confidence or conflicting imports route to `god-greenfieldifier` for a
70
+ controlled migration plan.
71
+
8
72
  ## [1.6.14] - 2026-05-16
9
73
 
10
74
  Approved automation setup execution.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![CI](https://github.com/aihxp/godpowers/actions/workflows/ci.yml/badge.svg)](https://github.com/aihxp/godpowers/actions/workflows/ci.yml)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
- [![Version](https://img.shields.io/badge/version-1.6.14-blue)](CHANGELOG.md)
5
+ [![Version](https://img.shields.io/badge/version-1.6.16-blue)](CHANGELOG.md)
6
6
  [![npm](https://img.shields.io/npm/v/godpowers.svg)](https://www.npmjs.com/package/godpowers)
7
7
 
8
8
  **Ship fast. Ship right. Ship everything. Ship accountably.**
@@ -12,16 +12,12 @@ idea to hardened production. It runs as **slash commands inside your AI coding
12
12
  tool** (Claude Code, Codex, Cursor, etc.) that orchestrate **specialist agents**
13
13
  in fresh contexts to do the work.
14
14
 
15
- Version 1.6.14 builds on the executable dashboard engine and CLI status surface:
16
- `godpowers status --project .` and `godpowers next --project .` now compute the
17
- same disk-derived progress, planning visibility, proactive checks, and next
18
- action used by `/god-status`, `/god-next`, and God Mode closeouts.
19
- It adds an opt-in automation-provider layer so Godpowers can detect host
20
- automation surfaces such as Codex App automations, Claude Routines, Cline
21
- schedules, Qwen loops, Cursor Background Agents, Copilot cloud agent, and
22
- scriptable CLI providers without silently creating background work.
23
- Approved setup can now use host tool calling for simple read-only automation
24
- or spawn `god-automation-engineer` for complex automation setup.
15
+ Version 1.6.16 adds feature awareness for existing Godpowers projects. When a
16
+ new runtime adds capabilities, `/god-doctor`, `/god-context`, `/god-sync`, and
17
+ `/god-mode` can detect stale project awareness, record the current feature set
18
+ in `state.json`, refresh AI-tool context fences, and point source-system
19
+ migration cases to `/god-migrate` or `god-greenfieldifier` when judgment is
20
+ needed.
25
21
 
26
22
  It fuses four disciplines into one unified workflow:
27
23
 
@@ -147,6 +143,7 @@ npx godpowers status --project=. --json
147
143
  | `/god-status` | Re-derive state from disk | (built-in) |
148
144
  | `/god-automation-status` | Show host automation provider support | (built-in) |
149
145
  | `/god-automation-setup` | Prepare opt-in automation setup | (built-in) |
146
+ | `/god-migrate` | Detect GSD, BMAD, and Superpowers context; import and sync back | god-greenfieldifier when needed |
150
147
  | `/god-preflight` | Read-only intake audit before project-run readiness and pillars | god-auditor |
151
148
  | `/god-audit` | Score artifacts against have-nots | god-auditor |
152
149
  | `/god-debug` | 4-phase systematic debug | god-debugger |
@@ -217,6 +214,29 @@ background agents, API triggers, or CI workflows. Safe starting templates are
217
214
  read-only status, checkpoint, review queue, hygiene, and release readiness
218
215
  reports.
219
216
 
217
+ Godpowers can migrate from adjacent planning systems:
218
+
219
+ ```bash
220
+ /god-migrate
221
+ ```
222
+
223
+ This detects GSD `.planning/` or `.gsd/`, BMAD `_bmad-output/` or `.bmad/`,
224
+ and Superpowers specs or plans. It writes
225
+ `.godpowers/prep/IMPORTED-CONTEXT.md`, optional imported seed artifacts, and
226
+ managed sync-back files such as `.planning/GODPOWERS-SYNC.md`,
227
+ `_bmad-output/GODPOWERS-SYNC.md`, or
228
+ `docs/superpowers/GODPOWERS-SYNC.md`.
229
+
230
+ Existing Godpowers projects can refresh their awareness after an upgrade:
231
+
232
+ ```bash
233
+ /god-context refresh
234
+ ```
235
+
236
+ This records the current Godpowers feature set in `.godpowers/state.json`,
237
+ refreshes managed AI-tool context fences, and suggests `/god-migrate` or
238
+ `god-greenfieldifier` when source-system evidence needs migration judgment.
239
+
220
240
  For existing codebases and org-constrained new projects, God Mode now runs a
221
241
  greenfield simulation audit and then actions it through a greenfieldification
222
242
  plan. It pauses before risky artifact rewrites because that process can change
@@ -339,9 +359,10 @@ Pi. T3 Code inherits from the underlying agent (Codex / Claude / OpenCode).
339
359
 
340
360
  - [Getting Started](docs/getting-started.md)
341
361
  - [Concepts](docs/concepts.md)
342
- - [Command reference (all 108 skills + 40 agents)](docs/reference.md)
362
+ - [Command reference (all 109 skills + 40 agents)](docs/reference.md)
363
+ - [Feature awareness](docs/feature-awareness.md)
343
364
  - [Roadmap](docs/ROADMAP.md)
344
- - [1.5 Release Notes](RELEASE.md)
365
+ - [Release Notes](RELEASE.md)
345
366
  - [Changelog](CHANGELOG.md)
346
367
  - [Inspiration](INSPIRATION.md)
347
368
 
package/RELEASE.md CHANGED
@@ -1,21 +1,19 @@
1
- # Godpowers 1.6.14 Release
1
+ # Godpowers 1.6.16 Release
2
2
 
3
3
  Date: 2026-05-16
4
4
 
5
- Godpowers 1.6.14 turns automation setup from a plan-only contract into an
6
- approved execution contract for hosts that expose tool calling. The CLI remains
7
- deterministic and read-only, while `/god-automation-setup` can use host-native
8
- tool calling for simple read-only setup or spawn `god-automation-engineer` for
9
- complex setup.
5
+ Godpowers 1.6.16 adds feature awareness for existing Godpowers projects. After
6
+ the installed runtime gains new capabilities, Godpowers can detect stale project
7
+ awareness, record the current feature set in `state.json`, refresh AI-tool
8
+ context fences, and route migration judgment to the right command or agent.
10
9
 
11
10
  ## What is stable
12
11
 
13
- - 108 slash commands
12
+ - 109 slash commands
14
13
  - 40 specialist agents
15
14
  - 13 executable workflows
16
15
  - 36 intent recipes
17
16
  - 15-runtime installer
18
- - 459 package files in the npm tarball
19
17
  - Codex installs with generated `god-*.toml` agent metadata files
20
18
  - Markdown specialist agent contracts at `<runtime>/agents/god-*.md`
21
19
  - Shared runtime bundle at `<runtime>/godpowers-runtime`
@@ -23,63 +21,54 @@ complex setup.
23
21
  - `.godpowers/` workflow state and artifact layout
24
22
  - Safe-sync routing before deploy, observe, harden, launch, or god-mode work
25
23
  - Critical harden finding gate before launch
26
- - GSD-style proposition closeouts for exploratory, diagnostic, audit,
27
- lifecycle, status, reconciliation, and decision-support outputs
28
- - Plain-language project-run wording in user-facing reports
24
+ - Planning-system migration for GSD, BMAD, and Superpowers
25
+ - Managed sync-back companion files for imported source systems
29
26
 
30
27
  ## What is new
31
28
 
32
- - Added `god-automation-engineer`.
33
- - Added automation execution-plan metadata to `lib/automation-providers.js`.
34
- - Added gated automation state recording helpers.
35
- - `/god-automation-setup` now shows direct host tool calling availability,
36
- complex setup delegation, and the state recording path.
37
- - Tests now cover host tool execution plans, complex setup delegation, and
38
- post-success automation recording.
39
-
40
- ## Platform behavior
41
-
42
- Claude Code, Codex, Cursor, Windsurf, Gemini, OpenCode, Copilot, Augment,
43
- Trae, Cline, Kilo, Antigravity, Qwen, CodeBuddy, and Pi all receive the same
44
- portable Markdown agent contracts. Codex also receives `god-*.toml` files as
45
- its registry adapter.
46
-
47
- The dashboard and automation provider engines ship in the installed runtime
48
- bundle so host tools can use shared implementation code instead of parallel
49
- command-specific Markdown contracts. If a host platform cannot provide a true
50
- fresh-context agent spawn, durable scheduler, or callable automation tool,
51
- Godpowers must say so visibly and report the work as local runtime only,
52
- manual workflow only, or simulated in current context.
53
-
54
- ## Safety policy
55
-
56
- Godpowers may proactively suggest next steps and may run directly evidenced
57
- local helpers. It may spawn bounded agents only when the current workflow owns
58
- that surface.
59
-
60
- Godpowers still must not auto-run these without explicit user intent:
61
-
62
- - deployed staging verification against a guessed URL
63
- - production launch
64
- - provider dashboard, admin console, DNS, credential, or secret checks
65
- - schedule, routine, background agent, API trigger, or CI workflow creation
66
- - broad dependency upgrades
67
- - destructive repair, rollback, reset, delete, or cleanup
68
- - clearing `.godpowers/REVIEW-REQUIRED.md`
69
- - accepting Critical security findings
70
- - git stage, commit, push, package, release, or publish
71
- - `.godpowers/automations.json` writes before host setup success
29
+ - Added `lib/feature-awareness.js`.
30
+ - Added `godpowers-features` to `state.v1.json`.
31
+ - Added `scripts/test-feature-awareness.js`.
32
+ - `/god-doctor`, `/god-context`, `/god-sync`, and `/god-mode` now document the
33
+ feature-awareness auto-invoke path.
34
+ - `AGENTS.md` refreshes now include `/god-sync`, `/god-migrate`, and
35
+ `/god-context refresh` in the useful command list.
36
+
37
+ ## Awareness behavior
38
+
39
+ For an initialized `.godpowers` project, the helper:
40
+
41
+ - reads the installed runtime version
42
+ - compares the project `godpowers-features` record to the current feature set
43
+ - detects missing managed AI-tool context fences
44
+ - detects unimported GSD, BMAD, or Superpowers planning artifacts
45
+ - writes only safe state metadata and managed context fences when applied
46
+
47
+ Detection is read-only. Applying awareness does not rewrite product, planning,
48
+ source-system, or code files outside Godpowers-owned fences.
49
+
50
+ ## Auto-invoke and auto-spawn policy
51
+
52
+ Feature awareness is local runtime work and must be reported as:
53
+
54
+ ```
55
+ Agent: none, local runtime only
56
+ ```
57
+
58
+ Godpowers recommends or spawns `god-greenfieldifier` only when imported or
59
+ detected planning-system context has low confidence or conflicts that need
60
+ migration judgment.
72
61
 
73
62
  ## Validation
74
63
 
75
64
  Release validation includes:
76
65
 
77
- - `node scripts/test-dashboard.js`
78
- - `node scripts/test-automation-providers.js`
79
- - `npm test`
80
- - `npm run test:audit`
81
- - `node scripts/check-package-contents.js`
66
+ - `node scripts/test-feature-awareness.js`
67
+ - `node scripts/test-context-writer.js`
68
+ - `node scripts/test-planning-systems.js`
69
+ - `node scripts/test-doc-surface-counts.js`
70
+ - `node scripts/validate-skills.js`
82
71
  - `git diff --check`
83
72
 
84
- The `v1.6.14` git tag points to the release commit that matches the npm
85
- `godpowers@1.6.14` package.
73
+ The `v1.6.16` tag should point to the release commit that matches the npm
74
+ `godpowers@1.6.16` package.
package/SKILL.md CHANGED
@@ -214,7 +214,7 @@ Auto-invoked:
214
214
  Trigger: <what caused this automatic step>
215
215
  Agent: <god-updater | god-context-writer | none, local runtime only>
216
216
  Local syncs:
217
- + <reverse-sync | pillars-sync | checkpoint-sync | context-refresh>: <result or skipped reason>
217
+ + <feature-awareness | planning-system-import | reverse-sync | source-sync | pillars-sync | checkpoint-sync | context-refresh>: <result or skipped reason>
218
218
  Artifacts: <changed files, no-op, or deferred>
219
219
  Log: <SYNC-LOG.md, CHECKPOINT.md, REVIEW-REQUIRED.md, or none>
220
220
  ```
@@ -238,6 +238,10 @@ Automatic steps that especially need visible reporting:
238
238
  - checkpoint refresh after state mutations
239
239
  - automation provider detection in `/god-status`, `/god-next`,
240
240
  `/god-automation-status`, and `/god-automation-setup`
241
+ - planning-system import during `/god-init` or `/god-migrate`
242
+ - source-system sync-back during `/god-sync`, `/god-scan`, or `/god-migrate`
243
+ - feature-awareness refresh during `/god-doctor`, `/god-context`,
244
+ `/god-sync`, or `/god-mode`
241
245
 
242
246
  ### 13. Proactive Auto-Invoke Policy
243
247
  Godpowers should be proactive from disk evidence, not from guesswork. Before
@@ -265,6 +269,15 @@ Run these local runtime helpers automatically when their trigger is present:
265
269
  `PROGRESS.md` mutation.
266
270
  - Lightweight reverse-sync or linkage scan after code or artifact edits.
267
271
  - Pillars sync planning after durable artifact truth changes.
272
+ - `lib/planning-systems.importPlanningContext` when GSD, BMAD, or
273
+ Superpowers planning context is detected during `/god-init` or
274
+ `/god-migrate`.
275
+ - `lib/source-sync.run` when `state.json` records enabled `source-systems`
276
+ entries and `/god-sync`, `/god-scan`, or `/god-migrate` closes a workflow.
277
+ - `lib/feature-awareness.detect` during `/god-doctor` and
278
+ `lib/feature-awareness.run` during `/god-context`, `/god-sync`, or
279
+ `/god-mode` when an initialized `.godpowers` project lacks current runtime
280
+ feature metadata or managed AI-tool context fences.
268
281
  - Context refresh dry-run after `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`,
269
282
  `.cursor/rules/`, `.windsurfrules`, `.github/copilot-instructions.md`,
270
283
  `.clinerules`, `.roo/`, or `.continue/` changes.
@@ -289,6 +302,11 @@ Spawn these agents only when the trigger is direct and scope is bounded:
289
302
  - `god-automation-engineer` after the user approves provider, template,
290
303
  cadence, and scope for multi-template, write-capable, background-agent,
291
304
  scriptable-scheduler, or provider-uncertain automation setup.
305
+ - `god-greenfieldifier` when imported GSD, BMAD, or Superpowers context has
306
+ low confidence, conflicting systems, or missing canonical Godpowers seed
307
+ artifacts after local import.
308
+ - `god-greenfieldifier` when feature-awareness detects unimported or imported
309
+ source-system context that is low confidence or conflicting.
292
310
 
293
311
  #### Level 4: Explicit approval required
294
312
  Never auto-run these from inference alone:
package/lib/README.md CHANGED
@@ -12,6 +12,7 @@ package-level integrations.
12
12
  | `state-lock.js` | Coordinate state writes with a lock file. |
13
13
  | `intent.js` | Read and validate `intent.yaml` from project roots or `.godpowers/`. |
14
14
  | `checkpoint.js` | Create and inspect resumable checkpoint artifacts. |
15
+ | `feature-awareness.js` | Detect and refresh existing-project awareness after runtime upgrades. |
15
16
  | `budget.js` | Read and enforce configured budget controls. |
16
17
  | `cost-tracker.js` | Track token and cost estimates from event streams. |
17
18
 
@@ -52,6 +53,8 @@ package-level integrations.
52
53
  |--------|---------|
53
54
  | `context-writer.js` | Produce tool-specific context files. |
54
55
  | `context-budget.js` | Keep generated context within budget. |
56
+ | `planning-systems.js` | Detect and import GSD, BMAD, and Superpowers planning context. |
57
+ | `source-sync.js` | Write managed Godpowers progress back to source-system companion files. |
55
58
  | `design-detector.js` | Detect design-system conventions. |
56
59
  | `design-spec.js` | Normalize design specifications. |
57
60
  | `awesome-design.js` | Validate design guidance against awesome-design rules. |
@@ -97,11 +97,10 @@ function buildCanonicalContent(state, opts = {}) {
97
97
  lines.push('');
98
98
  lines.push('- `/god-status` - re-derive state from disk');
99
99
  lines.push('- `/god-next` - what to run next, with reason');
100
- lines.push('- `/god <free text>` - match intent to a recipe');
101
100
  lines.push('- `/god-mode` - run the full autonomous project run');
102
- lines.push('- `/god-lint` - validate artifacts against have-nots');
103
- lines.push('- `/god-scan` - rebuild linkage map from code');
104
- lines.push('- `/god-review-changes` - walk REVIEW-REQUIRED.md');
101
+ lines.push('- `/god-sync` - refresh artifacts, context, and source-system sync-back');
102
+ lines.push('- `/god-migrate` - import or sync GSD, BMAD, or Superpowers context');
103
+ lines.push('- `/god-context refresh` - refresh AI-tool awareness for this project');
105
104
  lines.push('');
106
105
 
107
106
  // Pointers to design and product files when present
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Godpowers Feature Awareness
3
+ *
4
+ * Keeps existing Godpowers projects aware of capabilities added by newer
5
+ * installed runtimes. This module is deliberately conservative: detect is
6
+ * read-only, run applies only safe state and context refreshes, and ambiguous
7
+ * migration cases are returned as spawn recommendations.
8
+ */
9
+
10
+ const fs = require('fs');
11
+ const path = require('path');
12
+
13
+ const state = require('./state');
14
+ const contextWriter = require('./context-writer');
15
+ const planningSystems = require('./planning-systems');
16
+
17
+ const FEATURE_SET_VERSION = 1;
18
+
19
+ const FEATURES = [
20
+ {
21
+ id: 'planning-system-migration',
22
+ since: '1.6.15',
23
+ commands: ['/god-migrate', '/god-init'],
24
+ description: 'Detect and import GSD, BMAD, and Superpowers planning artifacts.'
25
+ },
26
+ {
27
+ id: 'source-system-sync-back',
28
+ since: '1.6.15',
29
+ commands: ['/god-sync', '/god-migrate'],
30
+ description: 'Write managed Godpowers progress summaries back to detected source systems.'
31
+ },
32
+ {
33
+ id: 'feature-awareness',
34
+ since: '1.6.16',
35
+ commands: ['/god-doctor', '/god-context', '/god-sync', '/god-mode'],
36
+ description: 'Refresh existing Godpowers projects when the installed runtime gains new capabilities.'
37
+ }
38
+ ];
39
+
40
+ function packageVersion(projectRoot) {
41
+ const candidates = [
42
+ path.join(__dirname, '..', 'package.json'),
43
+ path.join(projectRoot || process.cwd(), 'package.json')
44
+ ];
45
+ for (const candidate of candidates) {
46
+ if (!fs.existsSync(candidate)) continue;
47
+ try {
48
+ const parsed = JSON.parse(fs.readFileSync(candidate, 'utf8'));
49
+ if (parsed && parsed.name === 'godpowers' && parsed.version) return parsed.version;
50
+ } catch (err) {
51
+ // Ignore malformed package metadata. Awareness can still run with unknown.
52
+ }
53
+ }
54
+ return 'unknown';
55
+ }
56
+
57
+ function expectedFeatureIds() {
58
+ return FEATURES.map((feature) => feature.id);
59
+ }
60
+
61
+ function existingFeatureIds(current) {
62
+ const record = current && current['godpowers-features'];
63
+ return Array.isArray(record && record.known) ? record.known : [];
64
+ }
65
+
66
+ function missingFeatureIds(current) {
67
+ const known = new Set(existingFeatureIds(current));
68
+ return expectedFeatureIds().filter((id) => !known.has(id));
69
+ }
70
+
71
+ function sourceSystemsNeedJudgment(current) {
72
+ const systems = Array.isArray(current && current['source-systems'])
73
+ ? current['source-systems']
74
+ : [];
75
+ return systems.filter((system) => {
76
+ return system.confidence === 'low' || Number(system['conflict-count'] || 0) > 0;
77
+ });
78
+ }
79
+
80
+ function missingContextTargets(projectRoot) {
81
+ const status = contextWriter.status(projectRoot);
82
+ const missing = [];
83
+ if (!status.canonical.hasFence) missing.push('AGENTS.md');
84
+ for (const pointer of status.pointers) {
85
+ if (!pointer.hasFence) {
86
+ missing.push(path.relative(projectRoot, pointer.path).split(path.sep).join('/'));
87
+ }
88
+ }
89
+ return missing;
90
+ }
91
+
92
+ function detect(projectRoot, opts = {}) {
93
+ const current = state.read(projectRoot);
94
+ const runtimeVersion = opts.runtimeVersion || packageVersion(projectRoot);
95
+ if (!current) {
96
+ return {
97
+ initialized: false,
98
+ runtimeVersion,
99
+ actions: [],
100
+ missingFeatures: expectedFeatureIds(),
101
+ missingContext: [],
102
+ migrationCandidates: [],
103
+ spawnRecommendation: null
104
+ };
105
+ }
106
+
107
+ const record = current['godpowers-features'] || {};
108
+ const missingFeatures = missingFeatureIds(current);
109
+ const missingContext = missingContextTargets(projectRoot);
110
+ const migrationCandidates = planningSystems.detect(projectRoot).systems
111
+ .filter((system) => {
112
+ const configured = Array.isArray(current['source-systems'])
113
+ ? current['source-systems']
114
+ : [];
115
+ return !configured.some((entry) => entry.id === system.id);
116
+ })
117
+ .map((system) => ({
118
+ id: system.id,
119
+ name: system.name,
120
+ confidence: system.confidence,
121
+ files: system.files.length
122
+ }));
123
+
124
+ const actions = [];
125
+ if (record['runtime-version'] !== runtimeVersion) actions.push('record-runtime-version');
126
+ if (missingFeatures.length > 0) actions.push('record-feature-set');
127
+ if (missingContext.length > 0) actions.push('refresh-context');
128
+ if (migrationCandidates.length > 0) actions.push('suggest-god-migrate');
129
+
130
+ const needsJudgment = sourceSystemsNeedJudgment(current);
131
+ const lowConfidenceCandidates = migrationCandidates.filter((system) => system.confidence === 'low');
132
+ const spawnRecommendation = needsJudgment.length > 0 || lowConfidenceCandidates.length > 0
133
+ ? {
134
+ agent: 'god-greenfieldifier',
135
+ reason: 'Imported or detected planning-system context needs migration judgment.',
136
+ systems: [...needsJudgment.map((system) => system.id), ...lowConfidenceCandidates.map((system) => system.id)]
137
+ }
138
+ : null;
139
+
140
+ return {
141
+ initialized: true,
142
+ runtimeVersion,
143
+ featureSetVersion: FEATURE_SET_VERSION,
144
+ actions,
145
+ currentFeatures: existingFeatureIds(current),
146
+ expectedFeatures: FEATURES,
147
+ missingFeatures,
148
+ missingContext,
149
+ migrationCandidates,
150
+ spawnRecommendation
151
+ };
152
+ }
153
+
154
+ function buildFeatureRecord(runtimeVersion, now) {
155
+ return {
156
+ 'feature-set-version': FEATURE_SET_VERSION,
157
+ 'runtime-version': runtimeVersion,
158
+ known: expectedFeatureIds(),
159
+ 'last-awareness-refresh-at': now
160
+ };
161
+ }
162
+
163
+ function sameFeatureRecord(existing, next) {
164
+ if (!existing) return false;
165
+ return existing['feature-set-version'] === next['feature-set-version']
166
+ && existing['runtime-version'] === next['runtime-version']
167
+ && JSON.stringify(existing.known || []) === JSON.stringify(next.known || []);
168
+ }
169
+
170
+ function applyStateAwareness(projectRoot, current, runtimeVersion, now) {
171
+ const nextRecord = buildFeatureRecord(runtimeVersion, now);
172
+ if (sameFeatureRecord(current['godpowers-features'], nextRecord)) {
173
+ return { written: false, record: current['godpowers-features'] };
174
+ }
175
+ const nextState = {
176
+ ...current,
177
+ 'godpowers-features': nextRecord
178
+ };
179
+ state.write(projectRoot, nextState);
180
+ return { written: true, record: nextRecord };
181
+ }
182
+
183
+ function run(projectRoot, opts = {}) {
184
+ const before = detect(projectRoot, opts);
185
+ if (!before.initialized) {
186
+ return {
187
+ ...before,
188
+ applied: false,
189
+ stateWritten: false,
190
+ contextResults: [],
191
+ reason: '.godpowers/state.json not found'
192
+ };
193
+ }
194
+
195
+ const current = state.read(projectRoot);
196
+ const now = opts.now || new Date().toISOString();
197
+ const stateResult = applyStateAwareness(projectRoot, current, before.runtimeVersion, now);
198
+ const refreshedState = state.read(projectRoot);
199
+ const shouldRefreshContext = opts.refreshContext !== false;
200
+ const contextResults = shouldRefreshContext
201
+ ? contextWriter.apply(projectRoot, refreshedState, { projectRoot })
202
+ : [];
203
+ const after = detect(projectRoot, opts);
204
+
205
+ return {
206
+ ...after,
207
+ applied: true,
208
+ stateWritten: stateResult.written,
209
+ contextResults,
210
+ stateRecord: stateResult.record
211
+ };
212
+ }
213
+
214
+ module.exports = {
215
+ FEATURE_SET_VERSION,
216
+ FEATURES,
217
+ packageVersion,
218
+ detect,
219
+ run
220
+ };