ultra-builder-pro-cli 5.0.1 → 6.0.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 (159) hide show
  1. package/CHANGELOG.md +103 -3
  2. package/README.md +67 -478
  3. package/README.zh-CN.md +49 -422
  4. package/adapters/_shared/frontmatter.cjs +1 -18
  5. package/adapters/_shared/plugin-core.cjs +17 -83
  6. package/adapters/_shared/runtime-assets.cjs +6 -120
  7. package/adapters/claude.js +8 -24
  8. package/adapters/codex.js +13 -32
  9. package/bin/install.js +35 -57
  10. package/docs/PLUGIN-ISOLATION-CONTRACT.md +13 -101
  11. package/docs/examples/drive/claude-reviewer.sh +53 -0
  12. package/docs/examples/drive/claude-writer.sh +43 -0
  13. package/engine/FORMATS.md +1051 -0
  14. package/engine/checks.cjs +139 -0
  15. package/engine/cli.cjs +148 -0
  16. package/engine/completion.cjs +48 -0
  17. package/engine/context.cjs +94 -0
  18. package/engine/drive.cjs +220 -0
  19. package/engine/expect-worker.cjs +5 -0
  20. package/engine/expect.cjs +33 -0
  21. package/engine/formats.cjs +189 -0
  22. package/engine/git-state.cjs +112 -0
  23. package/engine/ledger.cjs +205 -0
  24. package/engine/loading.cjs +28 -0
  25. package/engine/merge.cjs +273 -0
  26. package/engine/milestone.cjs +89 -0
  27. package/engine/plan.cjs +232 -0
  28. package/engine/project.cjs +5 -0
  29. package/engine/signals.cjs +3 -0
  30. package/engine/states.cjs +175 -0
  31. package/hooks/session-start.cjs +54 -0
  32. package/package.json +17 -52
  33. package/skills/ultra/SKILL.md +395 -0
  34. package/.ultra-template/changes/abandoned/.gitkeep +0 -0
  35. package/.ultra-template/changes/active/.gitkeep +0 -1
  36. package/.ultra-template/changes/archive/.gitkeep +0 -1
  37. package/.ultra-template/contexts/TEMPLATE.md +0 -135
  38. package/.ultra-template/decisions/.gitkeep +0 -1
  39. package/.ultra-template/evidence/.gitkeep +0 -1
  40. package/.ultra-template/north-star.md +0 -52
  41. package/.ultra-template/project-brief.md +0 -28
  42. package/.ultra-template/research/.gitkeep +0 -1
  43. package/.ultra-template/specs/architecture.md +0 -81
  44. package/.ultra-template/specs/discovery.md +0 -74
  45. package/.ultra-template/specs/product.md +0 -80
  46. package/.ultra-template/specs/research-distillate.md +0 -57
  47. package/.ultra-template/tasks.json +0 -4
  48. package/.ultra-template/test-report.json +0 -44
  49. package/adapters/_shared/host-profile.cjs +0 -5
  50. package/adapters/grok.js +0 -242
  51. package/adapters/kimi.js +0 -232
  52. package/adapters/opencode.js +0 -408
  53. package/adapters/zcode.js +0 -375
  54. package/bin/delegate-worker.cjs +0 -5
  55. package/bin/delegate.cjs +0 -5
  56. package/docs/ARCHITECTURE.md +0 -274
  57. package/docs/ARTIFACT-AUTHORITY.md +0 -305
  58. package/docs/DECISIONS.md +0 -229
  59. package/docs/PHILOSOPHY.md +0 -261
  60. package/docs/RUNTIME-COMPAT-MATRIX.md +0 -316
  61. package/docs/SKILL-AUTHORING.md +0 -113
  62. package/docs/WORKFLOW-LIFECYCLE.md +0 -350
  63. package/docs/evals/adversarial-review-2026-08-14.md +0 -84
  64. package/docs/evals/ultra-5-0-journey-results.md +0 -62
  65. package/docs/evals/ultra-5-0-live-acp-conformance.md +0 -93
  66. package/docs/evals/ultra-5-0-route-journeys.md +0 -145
  67. package/docs/evals/zcode-automation-2026-08-14.md +0 -103
  68. package/hooks/README.md +0 -52
  69. package/hooks/_common.py +0 -1779
  70. package/hooks/adapters/codex.py +0 -295
  71. package/hooks/adapters/grok.py +0 -134
  72. package/hooks/adapters/kimi.py +0 -156
  73. package/hooks/adapters/zcode.py +0 -227
  74. package/hooks/block_dangerous_commands.py +0 -201
  75. package/hooks/compact_context.py +0 -224
  76. package/hooks/mid_workflow_recall.py +0 -47
  77. package/hooks/post_edit_guard.py +0 -215
  78. package/hooks/session_context.py +0 -741
  79. package/skills/ultra-change/SKILL.md +0 -165
  80. package/skills/ultra-change/references/change-contract.md +0 -199
  81. package/skills/ultra-change/references/execution-grant.md +0 -109
  82. package/skills/ultra-change/references/primary-transfer.md +0 -273
  83. package/skills/ultra-change/scripts/validate_primary_transfer.cjs +0 -1928
  84. package/skills/ultra-delegate/SKILL.md +0 -195
  85. package/skills/ultra-delegate/patches/zcode-acp-0.1.0-zcode-0.16.5.patch +0 -184
  86. package/skills/ultra-delegate/references/delegation-contract.md +0 -138
  87. package/skills/ultra-delegate/scripts/acp-conformance.cjs +0 -287
  88. package/skills/ultra-delegate/scripts/acp-driver.cjs +0 -762
  89. package/skills/ultra-delegate/scripts/agent-execution-driver.cjs +0 -320
  90. package/skills/ultra-delegate/scripts/cli-driver.cjs +0 -61
  91. package/skills/ultra-delegate/scripts/delegate-profiles/kimi-read-only.md +0 -15
  92. package/skills/ultra-delegate/scripts/delegate-profiles/kimi-write.md +0 -17
  93. package/skills/ultra-delegate/scripts/delegate-worker.cjs +0 -328
  94. package/skills/ultra-delegate/scripts/delegate.cjs +0 -690
  95. package/skills/ultra-delegate/scripts/delegate_wait.py +0 -86
  96. package/skills/ultra-delegate/scripts/host-profile.cjs +0 -267
  97. package/skills/ultra-deliver/SKILL.md +0 -194
  98. package/skills/ultra-deliver/references/baseline-reconciliation.md +0 -41
  99. package/skills/ultra-dev/SKILL.md +0 -265
  100. package/skills/ultra-dev/references/debugging.md +0 -22
  101. package/skills/ultra-domain-modeling/SKILL.md +0 -79
  102. package/skills/ultra-grilling/SKILL.md +0 -121
  103. package/skills/ultra-grilling/references/reframing.md +0 -76
  104. package/skills/ultra-init/SKILL.md +0 -143
  105. package/skills/ultra-init/references/brownfield-adoption.md +0 -32
  106. package/skills/ultra-init/scripts/init_project.cjs +0 -1031
  107. package/skills/ultra-plan/SKILL.md +0 -160
  108. package/skills/ultra-plan/references/task-evidence-v2.md +0 -300
  109. package/skills/ultra-plan/scripts/validate_task_evidence.cjs +0 -859
  110. package/skills/ultra-research/SKILL.md +0 -167
  111. package/skills/ultra-research/references/00-problem-validation.md +0 -36
  112. package/skills/ultra-research/references/01-opportunity-discovery.md +0 -33
  113. package/skills/ultra-research/references/02-market-assessment.md +0 -31
  114. package/skills/ultra-research/references/03-alternatives.md +0 -31
  115. package/skills/ultra-research/references/04-product-strategy.md +0 -41
  116. package/skills/ultra-research/references/05-assumptions-validation.md +0 -31
  117. package/skills/ultra-research/references/10-user-personas.md +0 -30
  118. package/skills/ultra-research/references/11-user-scenarios.md +0 -28
  119. package/skills/ultra-research/references/20-user-stories.md +0 -31
  120. package/skills/ultra-research/references/21-features-scope.md +0 -38
  121. package/skills/ultra-research/references/22-success-metrics.md +0 -33
  122. package/skills/ultra-research/references/30-architecture-context.md +0 -30
  123. package/skills/ultra-research/references/31-solution-strategy.md +0 -28
  124. package/skills/ultra-research/references/32-building-blocks.md +0 -28
  125. package/skills/ultra-research/references/40-deployment.md +0 -29
  126. package/skills/ultra-research/references/41-quality-risks.md +0 -28
  127. package/skills/ultra-research/references/99-synthesis.md +0 -59
  128. package/skills/ultra-research/references/north-star-v2.md +0 -168
  129. package/skills/ultra-research/references/wayfinding.md +0 -50
  130. package/skills/ultra-research/scripts/validate_north_star.cjs +0 -1174
  131. package/skills/ultra-review/SKILL.md +0 -275
  132. package/skills/ultra-review/references/adversarial-evaluation.md +0 -31
  133. package/skills/ultra-review/references/code.md +0 -17
  134. package/skills/ultra-review/references/comments.md +0 -12
  135. package/skills/ultra-review/references/design.md +0 -12
  136. package/skills/ultra-review/references/errors.md +0 -13
  137. package/skills/ultra-review/references/review-modes.md +0 -29
  138. package/skills/ultra-review/references/spec.md +0 -18
  139. package/skills/ultra-review/references/tests.md +0 -12
  140. package/skills/ultra-review/references/unified-schema.md +0 -284
  141. package/skills/ultra-review/references/worker-packet.md +0 -183
  142. package/skills/ultra-review/scripts/review_wait.py +0 -2943
  143. package/skills/ultra-status/SKILL.md +0 -209
  144. package/skills/ultra-status/references/route-contract.md +0 -100
  145. package/skills/ultra-tdd/SKILL.md +0 -91
  146. package/skills/ultra-tdd/references/templates/README.md +0 -20
  147. package/skills/ultra-tdd/references/templates/feature-flag-default-audit.sh +0 -79
  148. package/skills/ultra-tdd/references/templates/persistence-real.ts +0 -78
  149. package/skills/ultra-tdd/references/templates/testcontainer-postgres.py +0 -78
  150. package/skills/ultra-tdd/references/templates/testcontainer-postgres.ts +0 -73
  151. package/skills/ultra-tdd/references/templates/vertical-slice.ts +0 -66
  152. package/skills/ultra-tdd/references/test-execution.md +0 -23
  153. package/skills/ultra-test/SKILL.md +0 -244
  154. package/skills/ultra-test/references/export-syntax.md +0 -18
  155. package/skills/ultra-test/scripts/validate_review_transport.cjs +0 -549
  156. package/skills/ultra-test/scripts/worktree_digest.cjs +0 -576
  157. package/skills/ultra-think/SKILL.md +0 -56
  158. package/skills/ultra-think/references/autonomy-boundary.md +0 -48
  159. package/skills/ultra-think/references/interaction-boundary.md +0 -42
@@ -1,81 +0,0 @@
1
- # Architecture Specification
2
-
3
- Define accepted system boundaries, authority, runtime paths, operational behavior, and
4
- implementation constraints. Describe observed architecture before proposed changes.
5
-
6
- ## Scope
7
-
8
- - Repository or system boundary:
9
- - Product contracts supported:
10
- - Revision and environments inspected:
11
-
12
- ## Observed
13
-
14
- | Architectural fact | Source or runtime evidence | Consumer or impact |
15
- |---|---|---|
16
- | | | |
17
-
18
- ## Decisions
19
-
20
- | Decision | Driver and evidence | Consequence and recovery | Owner |
21
- |---|---|---|---|
22
- | | | | |
23
-
24
- ## Unknowns
25
-
26
- | Unknown | Consequence | Blocking | Owner or next check |
27
- |---|---|---|---|
28
- | | | | |
29
-
30
- ## 30 Architecture Context
31
-
32
- | Boundary or external system | Responsibility | Inputs and outputs | Trust or authority | Consumers |
33
- |---|---|---|---|---|
34
- | | | | | |
35
-
36
- Record material quality goals, technical and organizational constraints, data
37
- sensitivity, permissions, and compliance boundaries with evidence.
38
-
39
- ## 31 Solution Strategy
40
-
41
- | Accepted direction | Existing pattern or constraint | Consequence | Compatibility or recovery |
42
- |---|---|---|---|
43
- | | | | |
44
-
45
- ## 32 Building Blocks and Runtime Paths
46
-
47
- | Building block | Responsibility | Authority and contract | Dependencies | Consumers |
48
- |---|---|---|---|---|
49
- | | | | | |
50
-
51
- | Runtime path | Entry point | State and side effects | Observable result | Failure and recovery |
52
- |---|---|---|---|---|
53
- | | | | | |
54
-
55
- ## Data and State Authority
56
-
57
- | State | Authoritative owner | Writers | Readers | Consistency or migration rule |
58
- |---|---|---|---|---|
59
- | | | | | |
60
-
61
- ## 40 Deployment and Operations
62
-
63
- | Environment or operation | Entry point | Configuration or migration | Observation | Rollback or recovery |
64
- |---|---|---|---|---|
65
- | | | | | |
66
-
67
- ## 41 Quality Scenarios and Risks
68
-
69
- | Trigger and condition | Expected response | Measurement | Failure response | Owner |
70
- |---|---|---|---|---|
71
- | | | | | |
72
-
73
- | Risk or debt | Evidence | Consequence | Mitigation and verification | Status |
74
- |---|---|---|---|---|
75
- | | | | | |
76
-
77
- ## Product Traceability
78
-
79
- | Product requirement | Architecture path | Public seam | Verification evidence |
80
- |---|---|---|---|
81
- | | | | |
@@ -1,74 +0,0 @@
1
- # Discovery Evidence
2
-
3
- Record product evidence and accepted decisions. Link to durable sources instead of
4
- copying provider payloads or research transcripts.
5
-
6
- ## Scope
7
-
8
- - Repository or product boundary:
9
- - Inspected Git revision and dirty boundary:
10
- - Decision this evidence must unlock:
11
- - Freshness boundary:
12
-
13
- ## Observed
14
-
15
- | Fact or current behavior | Evidence reference | Observed at | Affected section |
16
- |---|---|---|---|
17
- | | | | |
18
-
19
- ## Decisions
20
-
21
- | Decision | Evidence and rationale | Owner | Affected contract |
22
- |---|---|---|---|
23
- | | | | |
24
-
25
- ## Unknowns
26
-
27
- | Unknown | Consequence | Blocking | Owner or next evidence |
28
- |---|---|---|---|
29
- | | | | |
30
-
31
- ## 00 Problem Validation
32
-
33
- - Problem and affected actor:
34
- - Current workaround and consequence:
35
- - Demand or usage evidence:
36
- - Accepted problem boundary:
37
-
38
- ## 01 Opportunity Discovery
39
-
40
- | Desired outcome | Opportunity | Evidence | Constraint or dependency |
41
- |---|---|---|---|
42
- | | | | |
43
-
44
- ## 02 Market Assessment
45
-
46
- Record only market, regulatory, commercial, or operational facts that affect a
47
- decision. Include source date, segment, geography, and assumptions when applicable.
48
-
49
- ## 03 Alternatives
50
-
51
- | Current alternative | Evidence | Meaningful difference | Strategy implication |
52
- |---|---|---|---|
53
- | | | | |
54
-
55
- ## 04 Product Strategy
56
-
57
- - Intended actors and outcome:
58
- - Value delivered through observable behavior:
59
- - Accepted tradeoffs:
60
- - Explicit constraints or exclusions:
61
-
62
- ## 05 Assumptions and Validation
63
-
64
- | Assumption | Current evidence | Validation signal | Decision rule | Owner |
65
- |---|---|---|---|---|
66
- | | | | | |
67
-
68
- ## Baseline Gaps
69
-
70
- Assign stable ids here and cite the repository evidence that exposed each gap.
71
-
72
- | Gap id | Category | Status | Evidence | Owner |
73
- |---|---|---|---|---|
74
- | | | | | |
@@ -1,80 +0,0 @@
1
- # Product Specification
2
-
3
- Define accepted product behavior and scope. Keep current behavior distinct from
4
- proposed behavior; this is not a transcript or task list.
5
-
6
- ## Scope
7
-
8
- - Product or repository boundary:
9
- - Intended outcome:
10
- - Explicit non-goals or constraints:
11
-
12
- ## Observed
13
-
14
- | Current behavior or constraint | Evidence reference | Status | Affected requirement |
15
- |---|---|---|---|
16
- | | | | |
17
-
18
- ## Decisions
19
-
20
- | Decision | Rationale | Acceptance impact | Owner |
21
- |---|---|---|---|
22
- | | | | |
23
-
24
- ## Unknowns
25
-
26
- | Unknown | Blocking | Owner | Resolution evidence |
27
- |---|---|---|---|
28
- | | | | |
29
-
30
- ## 10 Actors and Jobs
31
-
32
- | Actor or system | Job and context | Entry point | Constraints | Evidence |
33
- |---|---|---|---|---|
34
- | | | | | |
35
-
36
- ## 11 User Scenarios
37
-
38
- | Scenario id | Actor and trigger | Flow | Observable outcome | Failure and recovery | Evidence |
39
- |---|---|---|---|---|---|
40
- | | | | | | |
41
-
42
- ## 20 Behavioral Requirements and Acceptance
43
-
44
- ### Requirement: pending
45
-
46
- - Source scenario or constraint:
47
- - Preconditions:
48
- - Action:
49
- - Observable result:
50
- - Error behavior and recovery:
51
- - Verification:
52
-
53
- ## 21 Capability and Scope Boundary
54
-
55
- | Capability | Included requirements | Dependencies | Status and rationale |
56
- |---|---|---|---|
57
- | | | | |
58
-
59
- Scope status must reflect an explicit decision. Do not infer a reduced product posture.
60
-
61
- ## 22 Outcomes and Measurements
62
-
63
- The accepted project direction and any single North Star outcome or metric live in
64
- `.ultra/north-star.md`. Record supporting outcomes, measures, and guardrails here; do
65
- not force one metric when an observable outcome plus guardrails is the honest contract.
66
-
67
- | Outcome or guardrail | Definition | Evidence source | Decision use | Owner |
68
- |---|---|---|---|---|
69
- | | | | | |
70
-
71
- ## Documentation Impact
72
-
73
- List maintained documents that must stay consistent, or record a specific no-change
74
- rationale.
75
-
76
- ## Architecture Traceability
77
-
78
- | Requirement | Public seam | Architecture path | Verification evidence |
79
- |---|---|---|---|
80
- | | | | |
@@ -1,57 +0,0 @@
1
- # Research Traceability
2
-
3
- This file is a navigation and convergence artifact. Do not duplicate the baseline
4
- specifications' prose.
5
-
6
- ## Scope
7
-
8
- - Baseline or change id:
9
- - Research workflow id and mode:
10
- - Repository revision:
11
- - Coverage dispositions and selected evidence work:
12
-
13
- ## Observed
14
-
15
- | Claim | Evidence reference | Specification anchor |
16
- |---|---|---|
17
- | | | |
18
-
19
- ## Decisions
20
-
21
- | Decision | Owner and approval | Specification anchor |
22
- |---|---|---|
23
- | | | |
24
-
25
- ## Unknowns
26
-
27
- | Unknown or gap id | Blocking | Owner and revisit condition |
28
- |---|---|---|
29
- | | | |
30
-
31
- ## Source Revisions
32
-
33
- | Canonical source | Git blob hash from `git hash-object` | Status |
34
- |---|---|---|
35
- | `.ultra/specs/product.md` | | current or stale |
36
- | `.ultra/specs/architecture.md` | | current or stale |
37
- | `.ultra/specs/discovery.md` | | current or stale |
38
-
39
- ## End-to-End Trace
40
-
41
- | Problem or constraint | Actor and scenario | Requirement and acceptance | Architecture path | Verification |
42
- |---|---|---|---|---|
43
- | | | | | |
44
-
45
- ## Verification
46
-
47
- | Command or observation | Result | Evidence location | Freshness |
48
- |---|---|---|---|
49
- | | | | |
50
-
51
- ## Planning Entry
52
-
53
- - Accepted scope and posture:
54
- - Required references:
55
- - Blocking gaps:
56
- - Allowed transitions:
57
- - Host recommendation and rationale:
@@ -1,4 +0,0 @@
1
- {
2
- "$schema": "ultra-task-ledger-v2",
3
- "tasks": []
4
- }
@@ -1,44 +0,0 @@
1
- {
2
- "$schema": "ultra-test-report-v2",
3
- "change_id": null,
4
- "task_ids": [],
5
- "task_evidence": [],
6
- "git_commit": null,
7
- "intent_digest": null,
8
- "worktree": {
9
- "dirty": null,
10
- "diff_digest": null
11
- },
12
- "commands": [],
13
- "areas": {
14
- "anti_patterns": {"status": "not_run", "evidence_refs": [], "omissions": ["Not yet run"]},
15
- "coverage_gaps": {"status": "not_run", "evidence_refs": [], "omissions": ["Not yet run"]},
16
- "wiring": {"status": "not_run", "evidence_refs": [], "omissions": ["Not yet run"]},
17
- "e2e": {"status": "not_run", "evidence_refs": [], "omissions": ["Not yet run"]},
18
- "performance": {"status": "not_run", "evidence_refs": [], "omissions": ["Not yet run"]},
19
- "security": {"status": "not_run", "evidence_refs": [], "omissions": ["Not yet run"]}
20
- },
21
- "review": {
22
- "session": null,
23
- "packet_digest": null,
24
- "admission_digest": null,
25
- "subject_digest": null,
26
- "execution_mode": null,
27
- "finding_schema": "ultra-review-findings-v4",
28
- "summary_ref": null,
29
- "summary_digest": null,
30
- "context_digest": null,
31
- "worktree_digest": null,
32
- "verdict": "INCOMPLETE",
33
- "coverage_refs": [],
34
- "limitations": ["Not yet run"]
35
- },
36
- "verified_seams": [],
37
- "findings": [],
38
- "omissions": ["Not yet run"],
39
- "residual_risks": [],
40
- "owner_disposition": [],
41
- "passed": false,
42
- "run_count": 0,
43
- "timestamp": null
44
- }
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- // One-cycle compatibility import. The installed Skill owns the live delegation
4
- // profile so package CLI users and direct Skill callers execute the same contract.
5
- module.exports = require('../../skills/ultra-delegate/scripts/host-profile.cjs');
package/adapters/grok.js DELETED
@@ -1,242 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('node:fs');
4
- const os = require('node:os');
5
- const path = require('node:path');
6
- const { spawnSync } = require('node:child_process');
7
-
8
- const {
9
- copyHooks,
10
- copySkills,
11
- inspectPlugin,
12
- markManaged,
13
- publishManagedTrees,
14
- removeManaged,
15
- writePluginProvenance,
16
- } = require('./_shared/plugin-core.cjs');
17
- const {
18
- captureAbsent,
19
- ensureDir,
20
- isManaged,
21
- managedMetadata,
22
- pruneCreatedEmpty,
23
- removeTree,
24
- writeAtomic,
25
- } = require('./_shared/file-ops.cjs');
26
-
27
- const PLUGIN_NAME = 'ultra-builder-pro';
28
-
29
- function resolveTarget(ctx = {}) {
30
- if (ctx.configDir) return path.resolve(ctx.configDir);
31
- const configured = ctx.grokHome || ctx.grokEnv?.GROK_HOME || ctx.env?.GROK_HOME || process.env.GROK_HOME;
32
- return configured ? path.resolve(configured) : path.join(ctx.homeDir || os.homedir(), '.grok');
33
- }
34
-
35
- function resolveSourceRoot(ctx = {}) {
36
- return path.join(resolveTarget(ctx), '.ubp', 'plugin-sources', PLUGIN_NAME);
37
- }
38
-
39
- function resolvePluginRoot(ctx = {}) {
40
- return path.join(resolveTarget(ctx), 'plugins', PLUGIN_NAME);
41
- }
42
-
43
- function resolveRepoRoot(ctx = {}) {
44
- return ctx.repoRoot || path.resolve(__dirname, '..');
45
- }
46
-
47
- function assertPluginScope(ctx = {}) {
48
- if (ctx.scope === 'local' && !ctx.configDir) {
49
- throw new Error('Grok plugins are user-scoped; use global scope or an isolated configDir');
50
- }
51
- }
52
-
53
- function hookCommand(name) {
54
- return {
55
- type: 'command',
56
- command: `python3 "\${GROK_PLUGIN_ROOT}/hooks/adapters/grok.py" ${JSON.stringify(name)}`,
57
- timeout: 10,
58
- };
59
- }
60
-
61
- function buildHooksManifest() {
62
- return {
63
- description: 'Ultra file-first context sensors and narrow effect protection.',
64
- hooks: {
65
- SessionStart: [
66
- { matcher: 'startup|resume|clear', hooks: [hookCommand('session_context.py')] },
67
- { matcher: 'compact', hooks: [hookCommand('compact_context.py')] },
68
- ],
69
- PreToolUse: [
70
- { matcher: 'Write|Edit|Grep|apply_patch', hooks: [hookCommand('mid_workflow_recall.py')] },
71
- { matcher: 'Bash', hooks: [hookCommand('block_dangerous_commands.py')] },
72
- ],
73
- PostToolUse: [
74
- { matcher: 'Write|Edit|apply_patch', hooks: [hookCommand('post_edit_guard.py')] },
75
- ],
76
- PreCompact: [{ matcher: 'manual|auto', hooks: [hookCommand('compact_context.py')] }],
77
- },
78
- };
79
- }
80
-
81
- function buildStaging(repoRoot, staging, publishedRoot) {
82
- const skills = copySkills({ runtime: 'grok', repoRoot, skillRoot: path.join(staging, 'skills') });
83
- copyHooks({
84
- runtime: 'grok', repoRoot, hookRoot: path.join(staging, 'hooks'),
85
- hooksManifest: buildHooksManifest(),
86
- });
87
- const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
88
- writeAtomic(path.join(staging, 'plugin.json'), `${JSON.stringify({
89
- name: PLUGIN_NAME,
90
- version: pkg.version,
91
- description: 'File-first Ultra Builder Pro workflows for Grok Build.',
92
- author: { name: pkg.author },
93
- homepage: pkg.homepage,
94
- repository: pkg.repository?.url || pkg.repository,
95
- license: pkg.license,
96
- }, null, 2)}\n`);
97
- markManaged(staging, { adapter: 'grok', plugin: PLUGIN_NAME, version: pkg.version });
98
- writePluginProvenance({
99
- adapter: 'grok', repoRoot, stagingRoot: staging, publishedRoot,
100
- contracts: {
101
- plugin_manifest: { root: 'plugin', path: 'plugin.json' },
102
- hooks_manifest: { root: 'plugin', path: 'hooks/hooks.json' },
103
- hook_adapter: { root: 'plugin', path: 'hooks/adapters/grok.py' },
104
- },
105
- });
106
- return { skills };
107
- }
108
-
109
- function shouldRunHostCli(ctx = {}) {
110
- if (typeof ctx.runHostCli === 'boolean') return ctx.runHostCli;
111
- return ctx.scope === 'global' && !ctx.configDir;
112
- }
113
-
114
- function runGrok(ctx, args) {
115
- const result = spawnSync(ctx.grokBin || 'grok', args, {
116
- encoding: 'utf8', timeout: ctx.hostCliTimeoutMs || 30000,
117
- env: { ...process.env, GROK_HOME: resolveTarget(ctx) },
118
- });
119
- if (result.error) throw result.error;
120
- if (result.status !== 0) throw new Error((result.stderr || result.stdout || '').trim() || `grok ${args.join(' ')} failed`);
121
- return result.stdout;
122
- }
123
-
124
- function installedPlugin(ctx) {
125
- const value = JSON.parse(runGrok(ctx, ['plugin', 'list', '--json']));
126
- if (!Array.isArray(value)) throw new Error('grok plugin list --json must return an array');
127
- return value.find((entry) => entry?.name === PLUGIN_NAME) || null;
128
- }
129
-
130
- function install(ctx = {}) {
131
- assertPluginScope(ctx);
132
- const sourceRoot = resolveSourceRoot(ctx);
133
- const configRoot = resolveTarget(ctx);
134
- const repoRoot = resolveRepoRoot(ctx);
135
- const cleanupAbsent = managedMetadata(sourceRoot)?.cleanup_absent
136
- || captureAbsent(configRoot, ['.', '.ubp', path.join('.ubp', 'plugin-sources'), 'plugins']);
137
- ensureDir(path.dirname(sourceRoot));
138
- const staging = fs.mkdtempSync(path.join(path.dirname(sourceRoot), `.${PLUGIN_NAME}-staging-`));
139
- const recovery = fs.existsSync(sourceRoot)
140
- ? fs.mkdtempSync(path.join(path.dirname(sourceRoot), `.${PLUGIN_NAME}-recovery-`))
141
- : null;
142
- if (recovery) fs.cpSync(sourceRoot, recovery, { recursive: true });
143
- let previousRegistration = null;
144
- try {
145
- const copied = buildStaging(repoRoot, staging, sourceRoot);
146
- markManaged(staging, { cleanup_absent: cleanupAbsent });
147
- publishManagedTrees([{ source: staging, target: sourceRoot, label: 'Grok plugin source' }]);
148
- if (shouldRunHostCli(ctx)) {
149
- runGrok(ctx, ['plugin', 'validate', sourceRoot]);
150
- previousRegistration = installedPlugin(ctx);
151
- if (previousRegistration) runGrok(ctx, ['plugin', 'uninstall', PLUGIN_NAME, '--confirm', '--keep-data']);
152
- runGrok(ctx, ['plugin', 'install', sourceRoot, '--trust']);
153
- runGrok(ctx, ['plugin', 'enable', PLUGIN_NAME]);
154
- runGrok(ctx, ['plugin', 'details', PLUGIN_NAME]);
155
- }
156
- if (recovery) removeTree(recovery);
157
- return {
158
- target: sourceRoot,
159
- pluginRoot: sourceRoot,
160
- skillRoot: path.join(sourceRoot, 'skills'),
161
- hookRoot: path.join(sourceRoot, 'hooks'),
162
- copied,
163
- };
164
- } catch (error) {
165
- const rollback = [];
166
- try {
167
- if (fs.existsSync(sourceRoot)) removeTree(sourceRoot);
168
- if (recovery) fs.renameSync(recovery, sourceRoot);
169
- if (previousRegistration && shouldRunHostCli(ctx)) {
170
- try { runGrok(ctx, ['plugin', 'uninstall', PLUGIN_NAME, '--confirm', '--keep-data']); } catch {}
171
- runGrok(ctx, ['plugin', 'install', sourceRoot, '--trust']);
172
- if (previousRegistration.enabled !== false) runGrok(ctx, ['plugin', 'enable', PLUGIN_NAME]);
173
- }
174
- } catch (rollbackError) {
175
- rollback.push(rollbackError);
176
- }
177
- if (fs.existsSync(staging)) removeTree(staging);
178
- pruneCreatedEmpty(configRoot, cleanupAbsent);
179
- if (rollback.length) throw new AggregateError([error, ...rollback], 'Grok install and rollback failed');
180
- throw error;
181
- }
182
- }
183
-
184
- function doctor(ctx = {}) {
185
- assertPluginScope(ctx);
186
- const sourceRoot = resolveSourceRoot(ctx);
187
- const report = inspectPlugin({
188
- adapter: 'grok', repoRoot: resolveRepoRoot(ctx), pluginRoot: sourceRoot,
189
- skillRoot: path.join(sourceRoot, 'skills'), hookRoot: path.join(sourceRoot, 'hooks'),
190
- manifestFile: path.join(sourceRoot, 'plugin.json'),
191
- });
192
- if (shouldRunHostCli(ctx)) {
193
- let discovered = false;
194
- try {
195
- const plugin = installedPlugin(ctx);
196
- discovered = !!plugin && plugin.enabled !== false;
197
- if (discovered) runGrok(ctx, ['plugin', 'details', PLUGIN_NAME]);
198
- } catch {}
199
- report.checks.native_registry = { status: discovered ? 'pass' : 'fail' };
200
- if (!discovered) report.issues.push({ code: 'GROK_PLUGIN_NOT_REGISTERED' });
201
- }
202
- report.status = report.issues.length === 0 ? 'healthy' : 'degraded';
203
- return report;
204
- }
205
-
206
- function uninstall(ctx = {}) {
207
- assertPluginScope(ctx);
208
- const sourceRoot = resolveSourceRoot(ctx);
209
- const configRoot = resolveTarget(ctx);
210
- const cleanupAbsent = managedMetadata(sourceRoot)?.cleanup_absent || [];
211
- if (shouldRunHostCli(ctx)) {
212
- const plugin = installedPlugin(ctx);
213
- if (plugin) runGrok(ctx, ['plugin', 'uninstall', PLUGIN_NAME, '--confirm', '--keep-data']);
214
- }
215
- const legacy = resolvePluginRoot(ctx);
216
- const removedLegacy = fs.existsSync(legacy) && isManaged(legacy)
217
- ? removeManaged(legacy, 'legacy Grok plugin')
218
- : false;
219
- const removedSource = removeManaged(sourceRoot, 'Grok plugin source');
220
- const cleaned = pruneCreatedEmpty(configRoot, cleanupAbsent);
221
- return {
222
- target: sourceRoot,
223
- pluginRoot: sourceRoot,
224
- removed: {
225
- source: removedSource,
226
- legacy: removedLegacy,
227
- },
228
- cleaned,
229
- };
230
- }
231
-
232
- module.exports = {
233
- name: 'grok',
234
- PLUGIN_NAME,
235
- buildHooksManifest,
236
- resolveTarget,
237
- resolvePluginRoot,
238
- resolveSourceRoot,
239
- install,
240
- doctor,
241
- uninstall,
242
- };