@frankzhang2026/opencode-android-orchestrator 0.1.0 → 0.3.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 (124) hide show
  1. package/CHANGELOG.md +92 -2
  2. package/LICENSE +21 -0
  3. package/README.md +402 -6
  4. package/THIRD_PARTY_NOTICES.md +119 -0
  5. package/dist/cli.js +360 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/compatibility/hooks.d.ts +23 -0
  8. package/dist/compatibility/hooks.d.ts.map +1 -0
  9. package/dist/compatibility/hooks.js +44 -0
  10. package/dist/compatibility/hooks.js.map +1 -0
  11. package/dist/compatibility/versions.d.ts +19 -0
  12. package/dist/compatibility/versions.d.ts.map +1 -1
  13. package/dist/compatibility/versions.js +116 -0
  14. package/dist/compatibility/versions.js.map +1 -1
  15. package/dist/doctor/index.d.ts +36 -0
  16. package/dist/doctor/index.d.ts.map +1 -0
  17. package/dist/doctor/index.js +289 -0
  18. package/dist/doctor/index.js.map +1 -0
  19. package/dist/doctor/installation.d.ts +4 -0
  20. package/dist/doctor/installation.d.ts.map +1 -0
  21. package/dist/doctor/installation.js +497 -0
  22. package/dist/doctor/installation.js.map +1 -0
  23. package/dist/index.d.ts +13 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +13 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/installer/adaptive-templates.d.ts +78 -0
  28. package/dist/installer/adaptive-templates.d.ts.map +1 -0
  29. package/dist/installer/adaptive-templates.js +233 -0
  30. package/dist/installer/adaptive-templates.js.map +1 -0
  31. package/dist/installer/agents-config.d.ts +19 -0
  32. package/dist/installer/agents-config.d.ts.map +1 -0
  33. package/dist/installer/agents-config.js +147 -0
  34. package/dist/installer/agents-config.js.map +1 -0
  35. package/dist/installer/android-project.d.ts +36 -0
  36. package/dist/installer/android-project.d.ts.map +1 -0
  37. package/dist/installer/android-project.js +418 -0
  38. package/dist/installer/android-project.js.map +1 -0
  39. package/dist/installer/index.d.ts +8 -0
  40. package/dist/installer/index.d.ts.map +1 -1
  41. package/dist/installer/index.js +8 -1
  42. package/dist/installer/index.js.map +1 -1
  43. package/dist/installer/init.d.ts +68 -0
  44. package/dist/installer/init.d.ts.map +1 -0
  45. package/dist/installer/init.js +398 -0
  46. package/dist/installer/init.js.map +1 -0
  47. package/dist/installer/install-manifest.d.ts +132 -0
  48. package/dist/installer/install-manifest.d.ts.map +1 -0
  49. package/dist/installer/install-manifest.js +1047 -0
  50. package/dist/installer/install-manifest.js.map +1 -0
  51. package/dist/installer/opencode-config.d.ts +32 -0
  52. package/dist/installer/opencode-config.d.ts.map +1 -0
  53. package/dist/installer/opencode-config.js +302 -0
  54. package/dist/installer/opencode-config.js.map +1 -0
  55. package/dist/installer/uninstall.d.ts +70 -0
  56. package/dist/installer/uninstall.d.ts.map +1 -0
  57. package/dist/installer/uninstall.js +770 -0
  58. package/dist/installer/uninstall.js.map +1 -0
  59. package/dist/installer/upgrade.d.ts +101 -0
  60. package/dist/installer/upgrade.d.ts.map +1 -0
  61. package/dist/installer/upgrade.js +1140 -0
  62. package/dist/installer/upgrade.js.map +1 -0
  63. package/dist/opencode-plugin.d.ts +2 -0
  64. package/dist/opencode-plugin.d.ts.map +1 -0
  65. package/dist/opencode-plugin.js +4 -0
  66. package/dist/opencode-plugin.js.map +1 -0
  67. package/dist/plugin/index.d.ts +7 -2
  68. package/dist/plugin/index.d.ts.map +1 -1
  69. package/dist/plugin/index.js +23 -6
  70. package/dist/plugin/index.js.map +1 -1
  71. package/dist/tools/index.d.ts +35 -1
  72. package/dist/tools/index.d.ts.map +1 -1
  73. package/dist/tools/index.js +197 -1
  74. package/dist/tools/index.js.map +1 -1
  75. package/docs/MIGRATION.md +184 -0
  76. package/docs/SECURITY.md +219 -0
  77. package/docs/TROUBLESHOOTING.md +171 -0
  78. package/package.json +23 -5
  79. package/templates/.opencode/agents/scheduled-coder.md +115 -0
  80. package/templates/.opencode/agents/scheduled-planner.md +166 -0
  81. package/templates/.opencode/agents/scheduled-reviewer.md +88 -0
  82. package/templates/.opencode/commands/abort-task.md +20 -0
  83. package/templates/.opencode/commands/acceptance.md +20 -0
  84. package/templates/.opencode/commands/change.md +23 -0
  85. package/templates/.opencode/commands/resume-review.md +19 -0
  86. package/templates/.opencode/skills/scheduled-quality-coder/SKILL.md +93 -0
  87. package/templates/.opencode/skills/scheduled-quality-orchestrator/SKILL.md +216 -0
  88. package/templates/.opencode/skills/scheduled-quality-reviewer/SKILL.md +68 -0
  89. package/templates/AGENTS.md.fragment +19 -0
  90. package/templates/README.md +55 -9
  91. package/templates/automation/config.json +67 -0
  92. package/templates/automation/config.schema.json +194 -0
  93. package/templates/automation/task-contract.schema.json +92 -0
  94. package/templates/automation/tasks/TASK-TEMPLATE.json.example +56 -0
  95. package/templates/docs/plans/README.md +26 -0
  96. package/templates/installation-manifest.schema.json +201 -0
  97. package/templates/scripts/automation/abort-task.sh +171 -0
  98. package/templates/scripts/automation/accept-and-integrate.sh +263 -0
  99. package/templates/scripts/automation/acceptance-report.sh +132 -0
  100. package/templates/scripts/automation/approve-and-run.sh +175 -0
  101. package/templates/scripts/automation/begin-review.sh +18 -0
  102. package/templates/scripts/automation/block-task.sh +26 -0
  103. package/templates/scripts/automation/claim-task.sh +74 -0
  104. package/templates/scripts/automation/integration-scope-gate.sh +103 -0
  105. package/templates/scripts/automation/lib.sh +815 -0
  106. package/templates/scripts/automation/orchestrate-task.sh +119 -0
  107. package/templates/scripts/automation/preflight.sh +206 -0
  108. package/templates/scripts/automation/prepare-contract-review.sh +101 -0
  109. package/templates/scripts/automation/quality-gate.sh +72 -0
  110. package/templates/scripts/automation/queue-task.sh +35 -0
  111. package/templates/scripts/automation/record-red.sh +55 -0
  112. package/templates/scripts/automation/resume-review-fix.sh +32 -0
  113. package/templates/scripts/automation/resume-review.sh +120 -0
  114. package/templates/scripts/automation/scope-gate.sh +110 -0
  115. package/templates/scripts/automation/select-task.sh +34 -0
  116. package/templates/scripts/automation/shadow-run.sh +24 -0
  117. package/templates/scripts/automation/show-acceptance-review.sh +111 -0
  118. package/templates/scripts/automation/status.sh +125 -0
  119. package/templates/scripts/automation/submit-review.sh +73 -0
  120. package/templates/scripts/automation/tests/run-tests.sh +716 -0
  121. package/templates/scripts/automation/transition-state.sh +21 -0
  122. package/templates/scripts/automation/validate-contract.sh +98 -0
  123. package/templates/scripts/automation/verify-integration.sh +38 -0
  124. package/templates/scripts/automation/verify-task.sh +39 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,95 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.3.0 - 2026-08-28
4
4
 
5
- - Create the initial private TypeScript/npm plugin scaffold.
5
+ - Add `all` and `primary` module scopes and make all-module task contracts the
6
+ default for new installations. Multi-application projects no longer require
7
+ a primary selection; upgrades from configurations without the scope field
8
+ remain in `primary` mode unless explicitly widened.
9
+ - Add configurable Gradle verification task matrices to `init` and `upgrade`,
10
+ and bind focused-test contract entries to both an allowed Gradle task and a
11
+ test filter.
12
+ - Harden task-contract validation, source-scope enforcement, RED evidence,
13
+ verification output, and integration checks while preserving protected
14
+ Gradle and orchestration files.
15
+ - Retry OpenCode configuration discovery only for its known transient SQLite
16
+ checkpoint failure.
17
+ - Expand multi-module, lifecycle, CLI, schema, migration, and compatibility
18
+ coverage to 124 Node tests and the audited 38-case Shell suite.
19
+
20
+ ## 0.2.0 - 2026-08-26
21
+
22
+ - Add the complete MIT license, packaged third-party notices, public repository
23
+ metadata, draft release notes, and a fail-closed `0.2.0` authorization record.
24
+ - Keep the package root plugin-only for OpenCode's loader and expose lifecycle
25
+ and diagnostic APIs from the explicit `./api` subpath.
26
+ - Keep shadow-run diagnostics on stderr so stdout remains one strict JSON
27
+ document for installer verification and automation consumers.
28
+ - Restrict the plugin implementation to OpenCode APIs shared by `1.14.22` and
29
+ `1.15.13`.
30
+ - Add certified OpenCode version detection and a functional `doctor` command.
31
+ - Add Git, Android module, Gradle DSL, custom module directory, version catalog,
32
+ and Gradle Wrapper discovery.
33
+ - Add Kotlin DSL, Groovy DSL, compatibility, and doctor tests.
34
+ - Migrate the audited V3 agents, commands, and scheduled-quality skills as
35
+ project-independent installation templates.
36
+ - Migrate all 28 audited V3 automation Shell files while preserving their
37
+ executable modes and nested test-runner path.
38
+ - Migrate the remaining V3 configuration, Schemas, task example, and plan guide,
39
+ and add a bounded AGENTS managed-block template.
40
+ - Add a safe, idempotent OpenCode JSON/JSONC configuration merge planner that
41
+ retains comments, formatting, existing fields, plugin order, and options.
42
+ - Pin the installed Superpowers and orchestrator references, and reject
43
+ ambiguous files, symbolic links, malformed configuration, duplicates, and
44
+ managed-plugin version conflicts.
45
+ - Add a read-only adaptive template planner that derives the project name,
46
+ modules, namespaces/application IDs, protected Gradle files, source-set
47
+ paths, and focused-test placeholder without writing the target repository.
48
+ - Make agent permissions and deterministic scope gates work with detected
49
+ Android module directories, including custom `projectDir` mappings.
50
+ - Remove the legacy Scheduler dependency, project-specific identifiers, and
51
+ local absolute paths from all shipped templates.
52
+ - Treat absent legacy Scheduler tools as disabled during OpenCode discovery
53
+ while retaining explicit deny rules and rejecting any enabled tool.
54
+ - Add the installation transaction foundation with verified pre-install
55
+ backups, a portable versioned manifest Schema, per-file SHA-256/size/mode and
56
+ recovery metadata, fail-closed plan validation, integrity reporting,
57
+ installed-state completion, and guarded prepared-state rollback.
58
+ - Add read-only, structured managed-file conflict reporting and make
59
+ installation planning reject differing `copy`/`generate` content and all
60
+ requested changes to existing file modes before writing control state.
61
+ - Implement `init` with the complete 45-file project resource plan, adaptive
62
+ Kotlin/Groovy output, lossless OpenCode JSON/JSONC and bounded AGENTS merges,
63
+ executable-mode preservation, and unchanged-installation idempotence.
64
+ - Add pre-write OpenCode, Android, Gradle Wrapper, toolchain, Java, and SDK
65
+ gates, then require the 38 automation tests and a mutation-free shadow run
66
+ before completing the manifest; verification failures roll back originals.
67
+ - Complete the read-only installed-state `doctor` with command and SDK
68
+ discovery, exact manifest/package inventory validation, packaged-template
69
+ authentication, separate managed-content and permission checks, backup
70
+ integrity, semantic configuration checks, JSON output, and failure exit
71
+ codes.
72
+ - Implement `upgrade` with semantic-version and same-version guards, immutable
73
+ managed-file and original-backup checks, reconstruction of merged files from
74
+ first-install originals, immediate recovery snapshots, preserved recovery
75
+ lineage, obsolete-resource restoration, transactional manifest replacement,
76
+ upgrade history, idempotence, and automatic whole-version rollback when the
77
+ automation or shadow verification fails.
78
+ - Implement `uninstall` with read-only planning, exact content/size/mode guards,
79
+ verified restoration of first-install originals, removal of unchanged
80
+ plugin-created files, retention and reporting of user drift, cross-transaction
81
+ markers, recovery/history evidence, JSON output, and automatic pre-commit
82
+ rollback.
83
+ - Add project-bounded `android_orchestrator_status` and
84
+ `android_orchestrator_doctor` custom tools with strict task IDs, authenticated
85
+ fixed-script execution, bounded and validated JSON output, default-deny agent
86
+ permissions, and preflight discovery checks.
87
+ - Add packaged migration, troubleshooting, and security guides; expand the
88
+ README with fixed-version prerequisites, a post-release quick start, the
89
+ exact 45-resource installation inventory, workflow entry points, and links to
90
+ operational recovery guidance.
91
+
92
+ ## 0.1.0 - 2026-08-20
93
+
94
+ - Publish the initial TypeScript/npm scaffold. The lifecycle commands and V3
95
+ installation templates were not implemented in this release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 frankzhang2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,24 +2,420 @@
2
2
 
3
3
  Reusable OpenCode orchestration for macOS Android projects.
4
4
 
5
+ Version `0.2.0` is the first published lifecycle release. Version `0.3.0` adds
6
+ default all-module orchestration, configurable Gradle verification tasks, and
7
+ stricter contract/evidence validation while retaining the same certified
8
+ OpenCode compatibility range.
9
+
10
+ ## Documentation
11
+
12
+ - [Migration guide](docs/MIGRATION.md) — choose the correct path for the
13
+ `0.1.0` scaffold, a manually copied V3 setup, or a manifest-managed install.
14
+ - [Troubleshooting](docs/TROUBLESHOOTING.md) — diagnose CLI failures, resource
15
+ drift, OpenCode discovery, blocked tasks, and recovery evidence.
16
+ - [Security model](docs/SECURITY.md) — trust boundaries, approval guarantees,
17
+ file/Git protections, retained evidence, and residual risks.
18
+ - [Third-party notices](THIRD_PARTY_NOTICES.md) — runtime, peer, external
19
+ companion, and development-only dependency relationships and licenses.
20
+
21
+ ## Requirements
22
+
23
+ - macOS with Node.js/npm for `npx` or the packaged CLI;
24
+ - OpenCode `1.14.22` or `1.15.13` for a certified configuration (the declared
25
+ compatibility range is `>=1.14.22 <1.16.0`);
26
+ - a Git-backed Android Gradle project with `settings.gradle[.kts]` and an
27
+ executable `gradlew`;
28
+ - `git`, `jq`, `rg`, `shasum`, and Java on `PATH`;
29
+ - an Android SDK resolved from `ANDROID_HOME`, `ANDROID_SDK_ROOT`, or
30
+ `local.properties` `sdk.dir`.
31
+
32
+ Run lifecycle commands from the project root or a directory below it. Use a
33
+ clean branch and preserve an independent backup before the first installation,
34
+ even though the installer maintains its own verified recovery data.
35
+
36
+ ## Quick start
37
+
38
+ ```sh
39
+ npx @frankzhang2026/opencode-android-orchestrator@0.3.0 init .
40
+ npx @frankzhang2026/opencode-android-orchestrator@0.3.0 doctor .
41
+ opencode --agent scheduled-planner .
42
+ ```
43
+
44
+ New installations use all-module scope by default. Every detected Android
45
+ module's `src/main`, `src/test`, and `src/androidTest` trees can be included in
46
+ a task contract without selecting a primary module. To intentionally restrict
47
+ generated contracts to one module, opt into primary-module scope:
48
+
49
+ ```sh
50
+ npx @frankzhang2026/opencode-android-orchestrator@0.3.0 init . \
51
+ --module-scope primary \
52
+ --primary-module :mobile
53
+ ```
54
+
55
+ In all-module scope, `--primary-module` is optional and only chooses the
56
+ default module used by the focused-test placeholder; it does not narrow which
57
+ detected modules may be modified.
58
+
59
+ The install transaction manages 45 project-local paths:
60
+
61
+ | Resource group | Count | Installation behavior |
62
+ | --- | ---: | --- |
63
+ | Scheduled agents, commands, and skills | 10 | Copy exact audited templates. |
64
+ | Deterministic automation Shell files | 28 | Copy exact templates with `0755` modes. |
65
+ | Schemas and plan authoring guide | 3 | Copy fixed supporting resources. |
66
+ | Android automation config and task example | 2 | Generate from detected modules. |
67
+ | `AGENTS.md` and OpenCode JSON/JSONC | 2 | Merge bounded content without replacing unrelated settings. |
68
+
69
+ After installation, start the `scheduled-planner` and use its interactive flow.
70
+ The `/acceptance <TASK-ID>`, `/resume-review <TASK-ID>`, and
71
+ `/abort-task <TASK-ID>` commands are recovery/re-entry points; they do not
72
+ replace the required fresh approval controls. The workflow never pushes and
73
+ does not register Scheduler or launchd jobs.
74
+
5
75
  ## Status
6
76
 
7
- This repository currently contains only the TypeScript/npm scaffold. The
8
- installer lifecycle and the verified Android orchestration V3 templates have
9
- not been migrated yet. The package metadata is configured for public
10
- publication under the `@frankzhang2026` npm scope.
77
+ Version `0.1.0` was an early scaffold without a working installer. Version
78
+ `0.2.0` introduced the complete managed lifecycle; version `0.3.0` builds on
79
+ that release with all-module defaults and stronger verification contracts.
80
+
81
+ The cross-version plugin entry, OpenCode version doctor, Android/Gradle project
82
+ discovery, audited V3 resources, and all deterministic V3 Shell transactions
83
+ are implemented. Read-only planning now renders project-relative automation
84
+ configuration and a focused task example from the detected Android modules.
85
+ Safe, comment-preserving OpenCode JSON/JSONC merge planning is also implemented.
86
+ The installation transaction foundation now creates verified pre-install
87
+ backups and a versioned SHA-256 manifest. Read-only conflict analysis and the
88
+ installation-plan conflict gate are also implemented. The `init` command now
89
+ installs and verifies the complete project-local resource set. The read-only
90
+ `doctor` command now verifies the installed toolchain, manifest, resources,
91
+ permissions, backups, and configuration. The `upgrade` command now replaces
92
+ only unchanged managed resources, carries original pre-install backups
93
+ forward, and restores the complete previous installation if verification
94
+ fails. The `uninstall` command now restores unchanged original files, removes
95
+ unchanged plugin-created files, and retains any content, permission, or
96
+ deletion drift for manual review.
11
97
 
12
- ## Planned usage
98
+ Implemented checks include:
99
+
100
+ - OpenCode `1.14.22` and `1.15.13` certification, with guarded support for
101
+ versions in the declared `>=1.14.22 <1.16.0` range
102
+ - Git root and Gradle settings discovery from the project root or a module
103
+ directory
104
+ - project name, Kotlin/Groovy DSL, Android namespace/application ID,
105
+ multi-module, custom `projectDir`, version-catalog plugin aliases, and Gradle
106
+ Wrapper detection
107
+ - a plugin compatibility boundary restricted to API fields and hooks shared
108
+ by both certified OpenCode versions
109
+ - project-independent templates for the three V3 agents, four commands, and
110
+ three scheduled-quality skills
111
+ - all 28 automation Bash files with their `0755` modes; scope and test-change
112
+ gates consume detected source-set paths instead of a fixed module name
113
+ - a portable automation configuration source, both Schemas, contract example,
114
+ plan guide, and bounded AGENTS managed block
115
+ - adaptive configuration for every detected Android module, default
116
+ all-module task paths, opt-in primary-module restriction, exact protected
117
+ build files, production/test source sets, and a namespace-aware focused-test
118
+ placeholder
119
+ - removal of the legacy Scheduler dependency and all local absolute paths from
120
+ shipped templates
121
+ - read-only `opencode.json`/`opencode.jsonc` merge planning that preserves
122
+ existing fields, comments, plugin order, and plugin options while adding
123
+ fixed Superpowers and orchestrator references
124
+ - conflict guards for malformed or ambiguous configuration, duplicate plugin
125
+ packages, different managed-plugin references, and symbolic links
126
+ - a fail-closed installation preparation transaction that records package
127
+ version, source, strategy, desired SHA-256/size/mode, and original-file
128
+ backup metadata in `.automation-plugin/manifest.json`
129
+ - backup-before-manifest publication, stale/tampered plan rejection, backup and
130
+ installed-file integrity reporting, installed-state completion, and guarded
131
+ rollback of a prepared transaction
132
+ - read-only conflict reports with existing and desired hashes, sizes, modes,
133
+ source, and strategy; installation planning fails closed before any write
134
+ when `copy`/`generate` content or an existing file mode would be changed
135
+ - a write-capable `init` transaction that installs 45 managed files, preserves
136
+ Shell executable modes, merges OpenCode JSON/JSONC and one bounded AGENTS
137
+ block, and is byte-idempotent for an unchanged installed version
138
+ - write-before-complete verification using the 38-case automation suite and a
139
+ read-only shadow run; any failure restores original files before reporting
140
+ the error
141
+ - an installation-aware, read-only doctor that authenticates the 45-file
142
+ inventory against packaged templates, separates content and permission
143
+ drift, verifies original-file backups, and semantically checks the OpenCode,
144
+ AGENTS, adaptive Android, and task-example configuration
145
+ - a fail-closed `upgrade` transaction that rejects managed-file or original
146
+ backup drift, preserves the first installation's recovery state, records an
147
+ immediate pre-upgrade snapshot and history, restores obsolete user files,
148
+ reruns both post-write verifiers, and rolls the whole old version back on
149
+ failure
150
+ - a transactional `uninstall` that validates the installed manifest, restores
151
+ verified first-install originals, removes only exact managed-file matches,
152
+ retains content, permission, and deletion drift, records recovery/history
153
+ evidence, and automatically restores the installed state on pre-commit
154
+ failure
155
+
156
+ The planners deliberately avoid filesystem writes. The adaptive planner blocks
157
+ ambiguous primary-module selections only in `primary` scope, as well as paths
158
+ outside the Git root and nested Gradle roots that the current root-relative
159
+ transaction scripts cannot safely run.
160
+ The transaction layer writes only installer control state and recovery
161
+ evidence until `init`, `upgrade`, or `uninstall` explicitly applies a validated
162
+ plan.
163
+
164
+ ## Adaptive template planning
165
+
166
+ ```js
167
+ import {
168
+ planAdaptiveProjectTemplates,
169
+ } from "@frankzhang2026/opencode-android-orchestrator";
170
+
171
+ const plan = planAdaptiveProjectTemplates("/path/to/android-project", {
172
+ moduleScope: "all", // optional; this is the default
173
+ primaryModule: ":mobile", // optional focused-test default in all mode
174
+ });
175
+
176
+ console.log(plan.automationConfigContent);
177
+ console.log(plan.taskContractExampleContent);
178
+ ```
179
+
180
+ The returned JSON contains repository-relative paths only. This API plans
181
+ content in memory; it does not create or modify target-project files.
182
+
183
+ ## Conflict policy
184
+
185
+ `detectInstallationConflicts` is read-only and returns conflicts sorted by
186
+ target path. Missing files and files whose content and effective mode already
187
+ match are safe. Existing `copy`/`generate` files with different content are
188
+ conflicts, as is any requested mode change. `planInstallationPreparation`
189
+ enforces the same policy and throws `FILE_CONFLICT` before creating installer
190
+ control state; there is no silent-overwrite option.
191
+
192
+ The `merge` strategy permits a content difference only when the caller has
193
+ already produced the desired content with a structure-aware merge planner,
194
+ such as the OpenCode JSON/JSONC merger. It preserves the existing mode by
195
+ default, and an explicit mode change still conflicts. Backup preparation then
196
+ rechecks the planned original hash, size, and mode to close the gap between
197
+ conflict analysis and the first write.
198
+
199
+ ## Installation preparation transaction
200
+
201
+ `planInstallationPreparation` snapshots every managed path in memory.
202
+ `prepareInstallationBackup` then verifies that the plan is unchanged, writes
203
+ original files below `.automation-plugin/backups/<installation-id>/`, verifies
204
+ their hashes and modes, and only then publishes a `prepared` manifest. A caller
205
+ may mark it `installed` only after every desired file matches the manifest.
206
+ `rollbackPreparedInstallation` restores originals and removes newly created
207
+ files only when their hashes still match a safe prepared state.
208
+
209
+ This API is the transaction foundation used by `init`. Callers must not treat
210
+ preparation alone as resource installation;
211
+ `applyInstallationPlan` performs the guarded write and completion transaction.
212
+
213
+ ## Init
13
214
 
14
215
  ```sh
15
- npx @frankzhang2026/opencode-android-orchestrator@0.1.0 init .
216
+ npx @frankzhang2026/opencode-android-orchestrator@0.3.0 init .
16
217
  opencode --agent scheduled-planner .
17
218
  ```
18
219
 
220
+ All detected modules are enabled by default, including multi-application
221
+ projects. Use the restrictive mode only when a task contract must stay within
222
+ one module:
223
+
224
+ ```sh
225
+ opencode-android-orchestrator init . \
226
+ --module-scope primary \
227
+ --primary-module :mobile
228
+ ```
229
+
230
+ Before writing, `init` requires a compatible OpenCode version, a Git-backed
231
+ Android Gradle project, an executable Gradle Wrapper, `git`, `jq`, `rg`,
232
+ `shasum`, Java, and an Android SDK directory from `ANDROID_HOME` or
233
+ `ANDROID_SDK_ROOT`. It then:
234
+
235
+ 1. renders project-specific configuration and plans both safe merges;
236
+ 2. rejects all unresolved content or mode conflicts;
237
+ 3. backs up every existing managed path and publishes a `prepared` manifest;
238
+ 4. writes missing or approved merged files with verified hashes and modes;
239
+ 5. runs the 38 automation tests and `shadow-run.sh`;
240
+ 6. marks the manifest `installed` only after both checks pass.
241
+
242
+ Verification failure automatically restores originals and records rollback
243
+ history; recovery backups remain below `.automation-plugin/backups/`. Repeating
244
+ `init` on an unchanged, healthy installation performs no managed-file writes.
245
+
246
+ Pin the exact package version in long-lived repositories and review the
247
+ generated installation diff before starting the scheduled planner.
248
+
249
+ ## Doctor
250
+
251
+ ```sh
252
+ opencode-android-orchestrator doctor /path/to/android-project
253
+ opencode-android-orchestrator doctor /path/to/android-project --json
254
+ ```
255
+
256
+ The command exits unsuccessfully when OpenCode is missing or incompatible,
257
+ the target is not a Git Android project, the Gradle Wrapper or a required
258
+ command is unavailable, the SDK cannot be resolved, or any installed state is
259
+ unhealthy. SDK lookup uses an explicit API option, `ANDROID_HOME`,
260
+ `ANDROID_SDK_ROOT`, then `local.properties` `sdk.dir`; an existing SDK root
261
+ without detectable `platforms` or `build-tools` is reported as a warning.
262
+
263
+ Installation checks are deliberately read-only and cover:
264
+
265
+ - manifest schema, installed state, fixed package version, `0600` mode, exact
266
+ 45-file inventory, sources, strategies, and packaged-template hashes;
267
+ - each managed file's SHA-256, size, and mode, including all 28 executable
268
+ automation scripts;
269
+ - every original-file backup required for future recovery;
270
+ - pinned OpenCode and Superpowers references, the exact bounded AGENTS block,
271
+ and adaptive automation/task configuration against the currently detected
272
+ Android modules.
273
+
274
+ Human output and `--json` expose the same checks. Exit code `0` means there are
275
+ no failures (`warn` is allowed), `1` means at least one check failed, and `2`
276
+ means the CLI arguments were invalid. Doctor reports drift but never repairs or
277
+ rewrites the project.
278
+
279
+ ## Read-only OpenCode tools
280
+
281
+ Loading the plugin registers two project-scoped custom tools:
282
+
283
+ - `android_orchestrator_status` accepts one required `taskId` matching
284
+ `TASK-[A-Z0-9-]+` and returns the task contract, runtime state, and evidence
285
+ as JSON;
286
+ - `android_orchestrator_doctor` accepts no arguments and returns the complete
287
+ project, dependency, SDK, and installation report as JSON.
288
+
289
+ Both tools reject a call whose runtime context is outside the worktree that
290
+ loaded the plugin. Before `status` invokes anything, it authenticates the
291
+ installed manifest, managed-resource hashes, and executable modes against the
292
+ packaged version. It then invokes only the fixed
293
+ `scripts/automation/status.sh` path, passes the validated task ID as a separate
294
+ shell expression, bounds the output to 1 MiB, and verifies that the returned
295
+ contract ID matches the request. Neither tool asks for permission or writes
296
+ project state. The installed planner, coder, and reviewer agents explicitly
297
+ allow these two tool names while retaining their default-deny policy; source
298
+ preflight verifies both resolved permissions and tool discovery.
299
+
300
+ ### Phase 2 mutating-tool decision
301
+
302
+ The 2026-08-25 evaluation remains **NO-GO for mutating custom tools in
303
+ `0.3.0`**.
304
+ The fixed Shell allowlist remains the only entry point for state transitions,
305
+ Git mutations, and agent launches. OpenCode custom tools provide typed arguments
306
+ and workspace context, but a normal permission prompt is not the workflow's
307
+ fresh semantic approval: permission requests can be approved for the rest of a
308
+ session and can be auto-approved unless explicitly denied. In addition, the
309
+ certified SDK declarations disagree on `ToolContext.ask` (`Effect.Effect<void>`
310
+ in `1.14.22`, `Promise<void>` in `1.15.13`), so it is not part of this plugin's
311
+ two-version common execution surface. See the OpenCode documentation for
312
+ [custom-tool context](https://opencode.ai/docs/custom-tools) and
313
+ [permission behavior](https://opencode.ai/docs/permissions/).
314
+
315
+ | Existing entry point | Material effects | Decision before a later phase |
316
+ | --- | --- | --- |
317
+ | `prepare-contract-review.sh` | Writes approval/origin evidence and initializes `CONTRACT_REVIEW` | Defer until a fresh proposal selection can produce a one-use receipt. |
318
+ | `approve-and-run.sh` | Acquires a repository lease, creates or switches a task branch/worktree, and launches agents | Do not wrap without a contract-approval receipt and cancellable long-running execution. |
319
+ | `show-acceptance-review.sh` | Reads sealed evidence but may regenerate `acceptance-report.json` | First split out a genuinely read-only, in-memory preview; that preview is the earliest suitable candidate. |
320
+ | `resume-review.sh` | Records a bounded resumption, changes `BLOCKED` to `REVIEWING`, and launches Reviewer | Consider only after command-bound authorization and subprocess cancellation are proven on both versions. |
321
+ | `accept-and-integrate.sh` | Creates the combined commit, fast-forwards the original branch, removes a worktree, and deletes the task branch | Do not wrap until final acceptance is bound to task ID, sealed diff, branch, session, and a consumed nonce. |
322
+ | `abort-task.sh` | Archives work, may create a recovery commit, switches/removes worktrees, and releases the lease | Do not wrap until an equally bound, one-use abort receipt exists. |
323
+
324
+ A future mutating tool must never accept an approval phrase as a model-provided
325
+ argument. It must atomically consume a machine-verifiable receipt created from
326
+ the immediately preceding `question` result and bind at least the approval
327
+ kind, task ID, session, message, relevant sealed SHA/branch, timestamp, and
328
+ nonce. It must also retain fixed-script authentication, strict state
329
+ preconditions, project/worktree bounds, abort propagation that terminates child
330
+ processes, bounded structured output, exact per-agent permissions, the 38-case
331
+ transaction suite, and real `1.14.22`/`1.15.13` integration tests. Internal
332
+ Coder/Reviewer transition scripts remain private orchestration details rather
333
+ than public tools.
334
+
335
+ ## Upgrade
336
+
337
+ ```sh
338
+ opencode-android-orchestrator upgrade /path/to/android-project
339
+ opencode-android-orchestrator upgrade . --module-scope all --json
340
+ ```
341
+
342
+ `upgrade` accepts either the Git root or a directory below it. It first validates
343
+ the installed manifest, every managed file, and every original-file backup. It
344
+ refuses downgrades, user-modified managed resources, damaged backups, ambiguous
345
+ Android modules in restrictive `primary` scope, same-version resource rewrites,
346
+ and an unfinished upgrade marker before creating recovery state.
347
+
348
+ Upgrade preserves the installed module scope. Installations created before the
349
+ scope field existed are interpreted as `primary` so an upgrade cannot silently
350
+ widen write access; pass `--module-scope all` during a real version upgrade to
351
+ opt in explicitly.
352
+
353
+ For an older healthy installation, the command:
354
+
355
+ 1. reconstructs merged AGENTS and OpenCode configuration from the original
356
+ pre-install files rather than layering new output over an older merge;
357
+ 2. saves the exact old manifest and immediate pre-upgrade file snapshots below
358
+ `.automation-plugin/upgrades/<upgrade-id>/`;
359
+ 3. carries the first installation's original backups into a new verified
360
+ backup set;
361
+ 4. writes only changed managed resources and restores or removes resources no
362
+ longer managed by the new version;
363
+ 5. runs the 38 automation tests and a mutation-free shadow run before swapping
364
+ the active manifest;
365
+ 6. records upgrade history below `.automation-plugin/history/`.
366
+
367
+ A verification failure automatically restores the old manifest and all old
368
+ managed resources. Recovery evidence remains available for inspection. Running
369
+ the command again on the current, unchanged version is byte-idempotent: it
370
+ rechecks prerequisites and post-install verification without creating upgrade
371
+ history or recovery state.
372
+
373
+ ## Uninstall
374
+
375
+ ```sh
376
+ opencode-android-orchestrator uninstall /path/to/android-project
377
+ opencode-android-orchestrator uninstall . --json
378
+ ```
379
+
380
+ `uninstall` accepts the project root or a directory below it and does not
381
+ require the Android toolchain to remain healthy. It validates the installed
382
+ manifest and refuses another active upgrade or uninstall transaction before
383
+ creating recovery state. For every managed path it then applies one of these
384
+ rules:
385
+
386
+ 1. if the content, size, and mode still match the installed manifest, restore
387
+ the verified pre-install file or remove a plugin-created file;
388
+ 2. if the path already matches its original state or is already absent when no
389
+ original existed, leave it untouched;
390
+ 3. if content, permissions, or existence drifted, retain the current state and
391
+ list the path for manual review.
392
+
393
+ Before changing a file, the command records the active manifest and every
394
+ affected installed file below `.automation-plugin/uninstalls/<uninstall-id>/`
395
+ and publishes an uninstall marker. It verifies all final paths before removing
396
+ the active manifest and records completion below `.automation-plugin/history/`.
397
+ Any failure before that commit restores the complete installed state. Original
398
+ installation backups and uninstall evidence are intentionally retained for
399
+ audit and manual recovery; user-created or pre-existing empty directories are
400
+ never guessed at or recursively removed.
401
+
19
402
  ## Development
20
403
 
404
+ The package root exports only the default OpenCode plugin factory because the
405
+ OpenCode loader treats each root export as a plugin. Programmatic lifecycle and
406
+ diagnostic APIs are available from
407
+ `@frankzhang2026/opencode-android-orchestrator/api`.
408
+
21
409
  ```sh
22
410
  npm run typecheck
23
411
  npm test
24
412
  npm run pack:check
25
413
  ```
414
+
415
+ ## License
416
+
417
+ This project is available under the [MIT License](LICENSE). Third-party
418
+ software is licensed by its respective owners; see
419
+ [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) for dependency scope,
420
+ copyright notices, and license texts. Superpowers is referenced as a pinned
421
+ external plugin and is not bundled into this package.
@@ -0,0 +1,119 @@
1
+ # Third-Party Notices
2
+
3
+ Last reviewed for `0.3.0` on 2026-08-28.
4
+
5
+ The published package does not vendor `node_modules`, third-party binaries, or
6
+ third-party Skill source. Its compiled JavaScript imports the direct runtime
7
+ dependency below, declares the OpenCode plugin API as a peer dependency, and
8
+ installs a pinned external Superpowers reference into the target project's
9
+ OpenCode configuration. Those relationships and their upstream notices are
10
+ recorded here.
11
+
12
+ ## jsonc-parser 3.3.1
13
+
14
+ - Relationship: direct runtime dependency installed separately by npm; its
15
+ source is not bundled into this package tarball.
16
+ - Source: <https://github.com/microsoft/node-jsonc-parser/tree/v3.3.1>
17
+ - License: MIT
18
+ - Copyright: Microsoft
19
+
20
+ ```text
21
+ The MIT License (MIT)
22
+
23
+ Copyright (c) Microsoft
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining a copy
26
+ of this software and associated documentation files (the "Software"), to deal
27
+ in the Software without restriction, including without limitation the rights
28
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
29
+ copies of the Software, and to permit persons to whom the Software is
30
+ furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all
33
+ copies or substantial portions of the Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41
+ SOFTWARE.
42
+ ```
43
+
44
+ ## @opencode-ai/plugin
45
+
46
+ - Relationship: peer dependency `>=1.14.22 <1.16.0` and development API
47
+ baseline `1.14.22`; it is not bundled into this package tarball.
48
+ - Source: <https://github.com/anomalyco/opencode>
49
+ - License: MIT
50
+ - Copyright: 2025 opencode
51
+
52
+ ```text
53
+ MIT License
54
+
55
+ Copyright (c) 2025 opencode
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ of this software and associated documentation files (the "Software"), to deal
59
+ in the Software without restriction, including without limitation the rights
60
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ copies of the Software, and to permit persons to whom the Software is
62
+ furnished to do so, subject to the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be included in all
65
+ copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
73
+ SOFTWARE.
74
+ ```
75
+
76
+ ## Superpowers v6.2.0
77
+
78
+ - Relationship: external companion plugin pinned as
79
+ `superpowers@git+https://github.com/obra/superpowers.git#v6.2.0`. The
80
+ initializer writes only this reference; Superpowers files are fetched and
81
+ managed by OpenCode and are not copied into this package tarball.
82
+ - Source: <https://github.com/obra/superpowers/tree/v6.2.0>
83
+ - License: MIT
84
+ - Copyright: 2025 Jesse Vincent
85
+
86
+ ```text
87
+ MIT License
88
+
89
+ Copyright (c) 2025 Jesse Vincent
90
+
91
+ Permission is hereby granted, free of charge, to any person obtaining a copy
92
+ of this software and associated documentation files (the "Software"), to deal
93
+ in the Software without restriction, including without limitation the rights
94
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
95
+ copies of the Software, and to permit persons to whom the Software is
96
+ furnished to do so, subject to the following conditions:
97
+
98
+ The above copyright notice and this permission notice shall be included in all
99
+ copies or substantial portions of the Software.
100
+
101
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
102
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
103
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
104
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
105
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
107
+ SOFTWARE.
108
+ ```
109
+
110
+ ## Development-only dependencies
111
+
112
+ The source repository also directly uses TypeScript `5.8.2` (Apache-2.0) and
113
+ `@types/node` `22.13.9` (MIT) to build and type-check the project. They and the
114
+ transitive development dependency tree are excluded from this package tarball;
115
+ their installed packages retain their own upstream license files.
116
+
117
+ Command-line programs required by an initialized Android project, including
118
+ Git, `jq`, ripgrep, Java, Gradle, and the Android SDK, are discovered on the
119
+ host. This package neither distributes nor installs those programs.