P1I.3 Existing Project Adoption extraction
Status: proposed. This document is the Design First review artifact for P1I.3. It does not implement the extraction or the import retarget. A maintainer must approve it before any production move. A green CI result is not approval.
Feasibility verdict: B. Leaf-owned adoption workflows, with one composition-root binding that passes syncProject into generated-file adoption. The Approved Apply import-only cycle is removed by retargeting two type imports. The Approved Apply engine keeps its value import of synchronizeGeneratedFiles.
1. Verified baseline
origin/main is da8d28e4ce33f24154fa69e1067a28fd54e5d04e. That commit is the merge of PR #619, a documentation record of the P1I.2 implementation. The production tree for this design is the parent, 1d8d55cbfd89792272d4d4c00512aa09465ed23d, which is the merge of PR #618. git diff --stat from that parent to origin/main touches only DUTY_WATCH.md, PROJECT_STATE.md, docs/README.md, and docs/architecture/PACKAGES_STABILIZATION_PLAN.md. packages/application/src/index.ts is unchanged between those commits.
The expected SHA in the task brief was the P1I.2 implementation merge. The actual origin/main is one documentation commit later. This branch was created from the actual origin/main. No earlier P1I.3 design exists under docs/designs/. No open pull request edits adoption extraction. Open pull requests at the start were Dependabot updates.
Verified before this design:
- PR #615, the P1I.1 System Design, is merged at
8bc9e07c74beb701adaae9e30dacb6aec252b58f. - PR #616, the P1I.1 implementation, is merged at
b9201e9d480b34e453d08e1803f94e734d1e3f1f. - PR #617, the P1I.2 System Design, is merged at
e3585e8eb5f4b58bb42482e249430654375dee5b. - PR #618, the P1I.2 implementation, is merged at
1d8d55cbfd89792272d4d4c00512aa09465ed23d. - PR #619 records that merge and does not change application source.
- P1I.1 and P1I.2 are complete. P1I.3 implementation has not started.
- P1J, Undo U4, and Desktop Undo U5 have not started.
Measured with measureProductionSource on this tree, packages/application/src/index.ts is 2,561 effective lines and 2,736 physical lines. applicationCycles from tests/application-source-cycles.ts returns import-only components of sizes 3 and 3, and re-export-inclusive components of sizes 4, 29, and 3. The membership arrays match the arrays locked in tests/project-lifecycle-p1i2-structure.test.ts.
Canonical guidance used for this design:
docs/architecture/ARCHITECTURE.md. Clients call@intentloom/application. Application code does not import the CLI, daemon, MCP server, or Desktop.docs/architecture/PACKAGES_STABILIZATION_PLAN.md, section P1I. This slice movesadoptProject,planProjectAdoption, andapplyProjectAdoption, and retargets the Approved Apply type imports that keepindex.tsin import cycle 1.docs/decisions/ADR-0003-non-destructive-project-adoption.md. Planning stays separate from applying. Project-owned files are not silently replaced.docs/decisions/ADR-0007-private-application-operation-boundary.md. The application package owns these operations.docs/decisions/ADR-0053-approved-apply-transaction-engine.md. Approved Apply is a separate gate. Ordinary adoption sync does not enter it.- The approved P1I.1 and P1I.2 designs. P1I.1 keeps
synchronizeGeneratedFileson the barrel. P1I.2 keepssyncProjecton the barrel and passes that dispatcher intoexecuteProjectSync. docs/governance/DESIGN_FIRST_POLICY.md,docs/governance/AI_AGENT_WORKFLOW.md,docs/governance/ENGINEERING_PRINCIPLES.md,docs/governance/CODE_QUALITY_STANDARDS.md, anddocs/governance/DOMAIN_MODELING.md.docs/governance/quality-exceptions.json. This design does not edit it. The grandfatheredindex.tsceiling stays 6,764 effective lines and 7,151 physical lines.
Task triage for this design-only change: blast radius 2, ambiguity 2, risk 2, verification 2, unknowns 2, total 10. The recommended role is frontier with highest effort. Harness: Cursor. This session cannot change its model. No subagents were used. The route from aif-task-router is plan. Risk 2 names the trust-boundary and rollback sections below. It does not authorize a behavior change. Ambiguity is 2 because direct extraction, composition-root binding, and leaf orchestration through index.ts are different architectures. This document is that decision record. Maintainer review of this pull request is the approval gate.
Stop condition: one design pull request, no production edit, no merge, and no start of the P1I.3 implementation, P1J, U4, or U5.
2. Problem statement
packages/application/src/index.ts still implements two different adoption workflows:
adoptProjectis 304 effective lines. It classifies an existing tree and may call ordinarysyncProject.planProjectAdoptionis 159 effective lines. It builds a coreAdoptionPlan.applyProjectAdoptionis 132 effective lines. It writes governance documents and a migration journal with best-effort rollback.
All three are over the 80-line function budget. Moving any of them unchanged into a new file would create a new function over that budget. The move has to decompose them. Their write paths, result types, and rollback mechanisms are not interchangeable.
The same barrel is still in the size-3 import cycle with approved-apply-baseline.ts and generated-file-sync-declared.ts. adoptProject calls syncProject, which stays on the barrel because it closes over synchronizeGeneratedFiles. A new adoption module that imports index.ts to reach that wrapper joins a cycle.
3. Goals and non-goals
Goals:
- Move both adoption workflows out of
index.tswithout combining their write paths, result contracts, or rollback implementations. - Decompose each moved function so every new function is at or below 80 effective lines, preferably 40, and every new file is at or below 250 effective lines.
- Keep the public signatures and the package-root entry point.
- Remove
index.tsfrom the import-only Approved Apply component by retargeting type imports only. - Keep the Neutron mutation component unchanged.
- Preserve ordinary sync from P1I.2 and the generated-file transaction from P1I.1.
- Preserve Approved Apply gating, baseline checks, and the engine's call to
synchronizeGeneratedFiles.
Non-goals:
- No production TypeScript edit in this pull request.
- No behavioral test edit in this pull request.
- No new adoption capability, metadata migration, or security behavior change.
- No Approved Apply engine rewrite.
- No move of
planPackUpdate,planFeature, or the workspace proposal helpers. - No move of the existing
existing-project-*prepared-plan files into a new directory. - No
project-adoption/index.ts, no new package, and no newpackage.jsonexport-map key. - No
utils.ts,helpers.ts,manager.ts, or service locator. - No new Entity, Aggregate, Repository, or Domain Event.
- No new quality-exception rule and no change to the grandfathered ceiling.
- No P1J, Undo U4, or Desktop Undo U5 work.
- No claim that the projected SCC membership has already been measured on an implementation.
4. Domain responsibility map
docs/governance/DOMAIN_MODELING.md already names Project Adoption as a context and AdoptionProposal and AdoptionPlan as different terms. This slice uses those words. It does not add a tactical DDD layer.
| Term | Owner | Meaning on this baseline |
|---|---|---|
| Generated-file project onboarding | project-adoption/ generated-file modules | adoptProject: profile detection, desired state, ownership, classification, then ordinary sync when the current guards allow it |
| Adoption proposal | generated-file-adoption-contracts.ts | AdoptionProposal, the result of onboarding. It extends Plan |
| Governance adoption planning | governance-adoption-plan.ts | planProjectAdoption: artifact scan and planGovernanceAdoption |
| Governance adoption apply | governance-adoption-apply.ts | applyProjectAdoption: hash check, governance document writes, journal, best-effort rollback |
| Adoption plan | @intentloom/core/adoption | AdoptionPlan, the governance result. It is not an AdoptionProposal |
| Prepared-plan pipeline | existing existing-project-adoption-* files | Preview, decisions, approval, and applyExistingProjectAdoptionPreparedPlan. It calls adoptProject. It is not applyProjectAdoption |
| Pack update planning | index.ts | planPackUpdate stays. It calls planProjectAdoption and then rewrites packVersion |
| Project lifecycle | project-lifecycle/ | desired, ownership, plan, and executeProjectSync. Unchanged |
| Generated-file transaction | generated-file/ | commitOwnedGeneratedFiles and declared-path sync. Unchanged |
| Approved Apply | approved-apply-gate.ts, approved-apply-engine.ts, approved-apply-baseline.ts | Gate, baseline, and engine. The engine still calls the barrel dispatcher |
Generated-file onboarding and governance adoption belong in one feature directory because both are Project Adoption application responsibilities. They belong in distinct modules because their contracts and write paths differ. The prepared-plan files stay where they are. Moving them would churn paths inside the re-export component without removing index.ts from it.
5. Declaration and size inventory
Lines and effective counts are measureProductionSource on the slices in packages/application/src/index.ts. Physical line numbers are the current file.
| Declaration | Lines | Effective / physical | Visibility | Decision | Reason |
|---|---|---|---|---|---|
AdoptionAction | 392–400 | part of the 51 / 53 type block | public type | Move, re-export | Used only by the proposal types and by callers of the package root |
AdoptionProposalItem | 402–421 | same block | public type | Move, re-export | Result item of generated-file onboarding |
AdoptionProposal | 423–435 | same block | public type | Move, re-export, local type import | Workspace proposal helpers in index.ts still name this type |
AdoptionTransactionOutcome | 436–444 | same block | public type | Move, re-export | Nested in AdoptionProposal |
unsupportedPath | 489–491 | 3 / 3 | private | Move | Only adoptProject calls it |
normalizeMappingPath | 493–500 | 8 / 8 | private | Move | Only adoptProject calls it |
adoptProject | 502–805 | 304 / 304 | public | Stay as a thin wrapper; move the body | The body calls syncProject. The wrapper keeps the three-parameter signature and passes syncProject in |
PlanProjectAdoptionOptions | 873–880 | inside 873–1201, 313 / 329 | public type | Move, re-export | Governance planning input. No other barrel function names it |
planProjectAdoption | 882–1046 | 159 / 165 | public | Move, local value import, re-export | planPackUpdate calls it |
ApplyProjectAdoptionOptions | 1048–1052 | inside the governance block | public type | Move, re-export | Governance apply input |
AdoptionApplyResult | 1054–1062 | inside the governance block | public type | Move, re-export | Governance apply result. Not an AdoptionProposal |
applyProjectAdoption | 1064–1201 | 132 / 138 | public | Move, re-export | No other declaration in index.ts calls it |
PlanPackUpdateOptions | 1203–1208 | inside 1203–1250, 44 / 48 | public type | Stay | Pack update is not this slice |
planPackUpdate | 1210–1250 | 38 / 41 | public | Stay | It calls planProjectAdoption and then returns a version-adjusted AdoptionPlan. Moving it is not required to break the cycle |
Shared declarations stay with their current owners. Adoption modules import those owners. They do not import index.ts.
| Shared declaration | Owner | Adoption use |
|---|---|---|
FileSystem, nodeFileSystem | host-file-system.ts | Both workflows |
InitOptions, configPath | project-lifecycle/project-lifecycle-contracts.ts | adoptProject |
desired | project-lifecycle/desired-generated-state.ts | Called once by onboarding, and again inside plan and syncProject |
ownership | project-lifecycle/ownership-state.ts | Onboarding |
plan | project-lifecycle/project-plan.ts | Onboarding calls it with dryRun: true and the default sync argument false |
executeProjectSync | project-lifecycle/project-sync.ts | Not called by the new leaf. syncProject calls it |
Plan | project-change.ts | AdoptionProposal extends it |
TransactionOptions, TransactionResult, TransactionStage | generated-file/transaction-contracts.ts | Onboarding outcome |
ProfileDetectionResult and detectProjectProfiles | project-profile-detection.ts | Onboarding |
documentConcept | document-concepts.ts | Onboarding classification |
instructionPath, adapterForKnownInstructionPath | instruction-file-taxonomy.ts | Onboarding classification |
inside, projectRelativePaths, secretLikePath | project-path.ts | Governance scan and path containment |
lockPath, sourceMapPath | generated-file/transaction-metadata.ts | Onboarding metadata completeness |
checksum, normalizeOutputPath | @intentloom/core | Hashes and mapping paths |
deterministicId, planGovernanceAdoption, core adoption types | @intentloom/core/adoption | Governance plan and journal |
planFeature, synchronizeGeneratedFiles, syncProject, and the workspace proposal functions stay in index.ts.
6. Complete call graph
Generated-file onboarding
adoptProject calls, in this order:
detectProjectProfiles(options.root, fs).desired(options)once.ownership(options.root, fs).fs.existsforconfigPath,lockPath, andsourceMapPath, throughPromise.all.plan({ ...options, dryRun: true }, fs). The third argument stays at its defaultfalse, so missing owned files are classifiedcreate, notmissing.normalizeMappingPathfor project-owned mappings, then for documentation mappings.documentConceptruns on documentation sources.- A second
documentConceptpass overscannedPathsfor duplicate concepts. - For each desired file:
fs.existswhen the path was not in the scan, thenadapterForKnownInstructionPath. - For each scanned path that is not a desired path:
unsupportedPath,documentConcept, andinstructionPath. - Sort items by
`${path}:${action}`withlocaleCompare. - Read
options.existingValidationResults. - Maybe
syncProject({ ...options, dryRun: false }, fs, transactionOptions).
plan calls desired again. On the write path, syncProject calls executeProjectSync, which calls plan and desired again. A dry run therefore evaluates desired twice. A write evaluates it four times. This design does not merge those calls.
syncProject calls executeProjectSync with synchronizeGeneratedFiles. That dispatcher calls synchronizeDeclaredProjectPaths only when isDeclaredPathsOnlySyncMode is true, and otherwise commitOwnedGeneratedFiles. Onboarding does not call the dispatcher itself.
Governance adoption
planProjectAdoption calls resolve, fs.isSymbolicLink, fs.list, projectRelativePaths, secretLikePath, inside, fs.read, checksum, and planGovernanceAdoption.
applyProjectAdoption calls resolve, fs.isSymbolicLink, inside, fs.exists, fs.read, checksum, fs.mkdir, fs.write, fs.remove, deterministicId, JSON.parse, JSON.stringify, and new Date().toISOString(). It does not call planGovernanceAdoption, syncProject, or synchronizeGeneratedFiles.
planPackUpdate calls planProjectAdoption and then either returns that plan or copies it with packVersion set to options.targetPackVersion ?? "1.1.0". The operation map returns every operation unchanged. That function stays in index.ts.
Callers that must keep compiling
| Caller | What it imports from the package root or index.ts |
|---|---|
packages/cli/src/adopt-command.ts | adoptProject, planProjectAdoption, applyProjectAdoption, AdoptionProposal |
packages/cli/src/update-command.ts | planPackUpdate, applyProjectAdoption |
packages/cli/src/formatters.ts | AdoptionProposal |
existing-project-adoption-plan.ts | adoptProject, inspectProject, ProjectMapping |
existing-project-adoption-apply.ts | adoptProject, syncProject, TransactionOptions |
existing-project-workspace.ts | planProjectAdoption, doctorProject, inspectProject |
promoteWorkspaceConversationToProposal, reviewWorkspaceProposal, applyWorkspaceProposal | local adoptProject and AdoptionProposal |
packages/daemon/src/existing-project-handlers.ts | prepareExistingProjectAdoptionPlan |
packages/daemon/src/existing-project-apply-handlers.ts | applyExistingProjectAdoptionPreparedPlan |
No MCP server file imports the three operations. Neutron read-only operations do not call them. Daemon and Desktop reach generated-file onboarding through the prepared-plan pipeline, which keeps importing adoptProject from index.ts. Those existing imports stay. Retargeting them is not required for the cycle proof, and this slice does not move those files.
7. Current architecture
flowchart TB
index["index.ts"]
adopt["adoptProject"]
planGov["planProjectAdoption"]
applyGov["applyProjectAdoption"]
pack["planPackUpdate"]
syncWrap["syncProject"]
dispatcher["synchronizeGeneratedFiles"]
declared["generated-file-sync-declared.ts"]
baseline["approved-apply-baseline.ts"]
engine["approved-apply-engine.ts"]
gate["approved-apply-gate.ts"]
lifecycle["project-lifecycle leaves"]
prepared["existing-project-adoption-plan.ts and apply.ts"]
workspace["existing-project-workspace.ts"]
index --> adopt
index --> planGov
index --> applyGov
index --> pack
index --> syncWrap
index --> dispatcher
adopt --> lifecycle
adopt --> syncWrap
pack --> planGov
syncWrap --> dispatcher
dispatcher --> declared
declared --> baseline
declared --> index
baseline --> index
index -.-> engine
engine --> index
engine --> gate
engine --> baseline
engine --> declared
engine --> dispatcher
prepared --> index
workspace --> indexEditable source: current-dependencies.mmd. The dotted edge is export * from "./approved-apply-engine.js". It is not a value import. The import-only cycle is the solid triangle index.ts to generated-file-sync-declared.ts to approved-apply-baseline.ts and back to index.ts.
approved-apply-baseline.ts imports type { FileSystem } from "./index.js". generated-file-sync-declared.ts imports FileSystem, Plan, PostWriteValidationResult, TransactionOptions, TransactionResult, and TransactionStage from ./index.js. The canonical owners already exist: host-file-system.ts, project-change.ts, and generated-file/transaction-contracts.ts.
approved-apply-engine.ts value-imports synchronizeGeneratedFiles and nodeFileSystem, plus the FileSystem and TransactionOptions types, from ./index.js. That edge is outside the import-only component because index.ts does not value-import the engine. It is inside the re-export component because the barrel re-exports the engine.
8. Proposed architecture
flowchart TB
index["index.ts composition root"]
wrapper["adoptProject wrapper"]
pack["planPackUpdate stays"]
syncWrap["syncProject stays"]
dispatcher["synchronizeGeneratedFiles stays"]
gen["project-adoption generated-file modules"]
govPlan["governance-adoption-plan.ts"]
govApply["governance-adoption-apply.ts"]
lifecycle["project-lifecycle leaves"]
declared["generated-file-sync-declared.ts"]
baseline["approved-apply-baseline.ts"]
host["host-file-system.ts"]
change["project-change.ts"]
tx["transaction-contracts.ts"]
engine["approved-apply-engine.ts"]
index --> wrapper
index --> pack
index --> syncWrap
index --> dispatcher
index --> gen
index --> govPlan
index --> govApply
wrapper --> gen
wrapper --> syncWrap
pack --> govPlan
gen --> lifecycle
syncWrap --> dispatcher
dispatcher --> declared
declared --> baseline
baseline --> host
declared --> host
declared --> change
declared --> tx
engine --> index
engine --> declared
engine --> baseline
gen --> host
govPlan --> host
govApply --> hostEditable source: proposed-dependencies.mmd.
New modules live under packages/application/src/project-adoption/. There is no project-adoption/index.ts. Generated-file modules do not import governance modules. Governance modules do not import generated-file modules. Neither family imports index.ts, approved-apply-engine.ts, approved-apply-baseline.ts, or generated-file-sync-declared.ts.
The public wrapper stays in index.ts:
export async function adoptProject(
options: InitOptions,
fs: FileSystem,
transactionOptions: TransactionOptions = {},
): Promise<AdoptionProposal> {
return adoptGeneratedFiles(options, fs, transactionOptions, syncProject);
}adoptGeneratedFiles is the internal orchestrator. It is not a package root export. Its fourth parameter is the current syncProject function. The public function still owns the default transactionOptions. Callers that omit the third argument still receive {}.
index.ts value-imports planProjectAdoption because planPackUpdate calls it, and re-exports it. applyProjectAdoption is a direct re-export. AdoptionProposal is a local type import because the workspace helpers still annotate it. The other moved public types are re-exported without a local binding.
9. Alternative comparison
A. Direct import of syncProject
Move adoptProject and import syncProject from index.ts.
The barrel must import the new module to re-export adoptProject. The new module would import the barrel. On the current graph, with the two type retargets applied, that pair is a new import-only component of size 2: index.ts and the adoption module. The re-export component grows by that module. The task forbids a new SCC. This alternative is rejected.
B. Composition-root binding
Keep the public three-parameter adoptProject in index.ts. Pass the existing syncProject function into adoptGeneratedFiles.
The leaf does not import index.ts. The public signature does not gain a parameter. The call inside the leaf stays syncProject({ ...options, dryRun: false }, fs, transactionOptions). Evaluation count, transaction options, and error propagation stay on the function callers already use. The fourth internal parameter matches the existing executeProjectSync shape and stays within the preference of four positional parameters. This is the selected binding.
C. Leaf calls executeProjectSync
The leaf could call executeProjectSync with synchronizeGeneratedFiles.
If it imports that dispatcher from index.ts, the cycle is the same as alternative A. If the wrapper injects the dispatcher instead, today's behavior matches because syncProject only forwards to executeProjectSync. That forwarding is the whole wrapper. Calling the leaf one level lower would duplicate it and would diverge if syncProject later gained a check. It also skips the named function onboarding calls today. This alternative is rejected in favor of B.
Calling commitOwnedGeneratedFiles directly would skip the declared-path branch of synchronizeGeneratedFiles. That changes behavior when transactionOptions.syncMode selects declared paths. It is rejected.
D. Inject the dispatcher into the Approved Apply engine
The engine could receive synchronizeGeneratedFiles from the barrel and stop importing index.ts. Together with the type retarget, that could remove index.ts from the re-export component as well as the import component.
That edit rewires the Approved Apply engine to delete an import edge. This milestone does not rewrite the engine. The required cycle result is the import-only component. Alternative D stays out of P1I.3. It is not required for this verdict.
10. Selected verdict
B. Generated-file onboarding and governance adoption move into project-adoption/ as separate module families. adoptProject remains the public wrapper and passes syncProject into adoptGeneratedFiles. planProjectAdoption and applyProjectAdoption move outright. planPackUpdate stays and calls the imported planner.
The import retarget is a second, smaller change. It is not an adoption behavior change. Section 21 splits it into its own implementation pull request so a cycle edit is not mixed into the move.
Direct extraction is not safe. The projected import-only graph has one component, the existing Neutron trio. No adoption leaf imports index.ts.
11. Module ownership matrix
| Module | Owns | Must not own |
|---|---|---|
generated-file-adoption-contracts.ts | AdoptionAction, AdoptionProposalItem, AdoptionProposal, AdoptionTransactionOutcome | Filesystem access, sync, governance types |
generated-file-adoption-mappings.ts | normalizeMappingPath, project-owned mapping diagnostics, documentation mapping diagnostics, duplicate-concept counts | Item classification, sync |
generated-file-adoption-classification.ts | unsupportedPath, desired-destination items, scanned-file items, deterministic item sort | Mapping diagnostics, transaction outcome |
generated-file-adoption-outcome.ts | Diagnostic token coercion, rollback-path normalization, and mapping a TransactionResult into the outcome value | Declaring AdoptionTransactionOutcome, and the decision to call sync |
generated-file-adoption.ts | adoptGeneratedFiles and the read/blocking helpers it needs to stay under 40 lines | synchronizeGeneratedFiles, Approved Apply |
governance-adoption-contracts.ts | PlanProjectAdoptionOptions, ApplyProjectAdoptionOptions, AdoptionApplyResult | Scan or write logic |
governance-adoption-artifacts.ts | Ownership class and role-candidate detection, concatenated in today's order | Journal writes |
governance-adoption-plan.ts | planProjectAdoption | Apply, sync, AdoptionProposal |
governance-adoption-apply.ts | applyProjectAdoption, hash verification, create writes, journal append, best-effort rollback | The generated-file transaction engine |
index.ts | Public adoptProject wrapper, planPackUpdate, syncProject, synchronizeGeneratedFiles, re-exports | The moved rule bodies |
Contingency: if governance-adoption-apply.ts measures above 250 effective lines, move journal append and rollback into governance-adoption-journal.ts. Do not start that file above the preference, and do not put both workflows in it.
AdoptionTransactionOutcome is declared only in generated-file-adoption-contracts.ts. generated-file-adoption-outcome.ts imports that type and constructs the value. It does not declare a second type.
Do not add existing-project-adoption-apply.ts beside the existing file of that name. The public function is applyProjectAdoption. The existing function applyExistingProjectAdoptionPreparedPlan stays in existing-project-adoption-apply.ts.
12. Public contracts
The package root remains packages/application/src/index.ts. The twelve package.json export-map keys stay:
../model-adapter./ollama-model-adapter./neutron-runtime./neutron-n2./neutron-context-assembly./neutron-n4./neutron-scheduler./neutron-graph-mutation./neutron-session./engineering-assessment./engineering-quality
No deep import of project-adoption/ is added.
Signatures that must remain source-identical:
export async function adoptProject(
options: InitOptions,
fs: FileSystem,
transactionOptions: TransactionOptions = {},
): Promise<AdoptionProposal>;
export async function planProjectAdoption(
options: PlanProjectAdoptionOptions,
fs: FileSystem = nodeFileSystem,
): Promise<AdoptionPlan>;
export async function applyProjectAdoption(
options: ApplyProjectAdoptionOptions,
fs: FileSystem = nodeFileSystem,
): Promise<AdoptionApplyResult>;planPackUpdate(options: PlanPackUpdateOptions, fs?: FileSystem) stays as it is, including the default nodeFileSystem and the return type AdoptionPlan.
AdoptionAction, AdoptionProposalItem, AdoptionProposal, AdoptionTransactionOutcome, PlanProjectAdoptionOptions, ApplyProjectAdoptionOptions, and AdoptionApplyResult stay exported from the package root. Their members stay as written in section 5's source lines. AdoptionProposal still extends Plan.
ApplyBlockedBeforeWrite stays constructed in approved-apply-baseline.ts. This slice does not introduce an error class. Governance failures that throw today throw Error. Onboarding failures that return a proposal today still return a proposal. Callees that throw, including inside on path traversal and desired on validation failure, still throw.
adoptGeneratedFiles must not appear on the package root namespace. That is the same rule P1I.2 used for executeProjectSync.
13. Adoption workflow separation
Generated-file onboarding and governance adoption are both Project Adoption. They are not one workflow.
| Question | Generated-file onboarding | Governance adoption |
|---|---|---|
| Public operations | adoptProject | planProjectAdoption, applyProjectAdoption |
| Result | AdoptionProposal | AdoptionPlan, then AdoptionApplyResult |
| Planner | application plan, after desired | core planGovernanceAdoption |
| Confirmation | profileConfirmed and manual-decision items | The caller supplies an AdoptionPlan |
| Approved Apply | Not entered | Not entered |
| Write | syncProject, which uses the generated-file transaction | Direct FileSystem writes of governance documents and the journal |
| Rollback | Transaction rollback from P1I.1 | In-memory backup and best-effort restore. Not atomic |
| Overwrite of project-owned files | Classified and not selected by writeEligible. The sync engine still applies its own conflict rules | A create operation writes op.path even when a file is already there, after an in-memory backup |
writeEligible does not filter the sync payload. When onboarding is not blocked, it calls syncProject for the project. It does not apply proposal items one by one.
planPackUpdate is governance planning plus a pack version assignment. It stays next to the barrel because its only barrel dependency is the planner, and the barrel can import that planner without a cycle. It does not pass projectId, packId, or packVersion, so the planner's defaults project, duty-watch, and 1.0.0 still apply before the version rewrite.
14. Approval and authorization boundaries
flowchart TB
subgraph readOnly ["Read-only inspection"]
inspect["inspectProject and doctorProject"]
end
subgraph onboarding ["1 Generated-file onboarding"]
adopt["adoptProject"]
sync["syncProject"]
adopt --> sync
end
subgraph prepared ["2 Prepared-plan adoption"]
preview["prepareExistingProjectAdoptionPlan"]
preparedApply["applyExistingProjectAdoptionPreparedPlan"]
preview --> preparedApply
preparedApply --> adopt
preparedApply --> sync
end
subgraph governance ["3 Governance adoption"]
planGov["planProjectAdoption"]
govApply["applyProjectAdoption direct filesystem writes"]
planGov --> govApply
end
subgraph approved ["4 Approved Apply"]
engine["executeApprovedApplyPlan"]
gate["evaluateApprovedApplyPlan"]
checks["path-scope and baseline checks"]
dispatcher["synchronizeGeneratedFiles"]
engine --> gate
gate --> checks
checks --> dispatcher
endEditable source: trust-boundaries.mmd. executeApprovedApplyPlan calls the gate, then the scope and baseline checks, then synchronizeGeneratedFiles. It does not call syncProject. The four write paths do not share an approval or rollback implementation.
These are different authorization flows.
planProjectAdoptionis read-only aside from throwing when the root is a symbolic link. It does not require approval.adoptProjectwrites only by callingsyncProjectafter the blocking rules in section 16. Profile confirmation isoptions.profileConfirmed. It does not callevaluateApprovedApplyPlan.applyExistingProjectAdoptionPreparedPlanhas its own gates, digest, and approval record. It callsadoptProjectandsyncProject. This slice does not change that file.applyProjectAdoptionwrites when the plan schema is 1, the root is not a symbolic link, hashes match, anddryRunis false. It has no Approved Apply request and no profile confirmation flag.- Approved Apply enters at
executeApprovedApplyPlan. That function callsevaluateApprovedApplyPlan, then the declared-path scope check and the baseline check, and thensynchronizeGeneratedFiles. It does not callsyncProject. A rejected gate returnsapplied: falsewithout a transaction. Onboarding does not enter that path.
Ownership metadata proves generated-file ownership through ownership and the source map. Governance planning assigns an ownership class from the path prefix. Those classifiers are not the same rule. Governance apply does not read the source map.
Stale checks differ. Onboarding uses the generated-file transaction and, on the prepared-plan path, that path's own revalidation. Governance apply compares checksum(content) with op.expectedCurrentHash. Approved Apply compares the captured baseline before synchronizeGeneratedFiles. Retargeting a type import does not change any of those checks.
15. Filesystem reads and writes
Generated-file onboarding
Reads: profile scan inside detectProjectProfiles, desired catalog reads, ownership and source-map reads, three metadata exists checks, plan reads, and exists for desired paths missing from the scan. Writes: none in the classifier. The only write is the syncProject call when section 16 says to make it. Dry-run sets dryRun: true on the planning plan call and does not call syncProject.
completeMetadata is true only when all three metadata paths exist and the ownership map is non-empty. A null ownership result is an empty map for lookups and invalidOwnershipMetadata for the source-map item. Malformed source-map behavior stays that split. It is not a throw in adoptProject. plan may still return its invalid source-map plan, and the source-map item becomes conflict.
Mapping paths that normalizeOutputPath rejects or rewrites, mappings whose source and destination differ, destinations missing from the scan, documentation paths with no concept, and duplicate concepts without an explicit mapping stay diagnostic strings. They block apply.
Governance planning
The root is resolve(options.root). A symbolic link throws Error("adoption planning requires a non-symbolic explicit project root"). fs defaults to nodeFileSystem. fs.list runs once. Paths then pass through projectRelativePaths in that list order. There is no extra sort.
For each relative path, secretLikePath skips the file before a read. A read that throws is skipped. A successful read is hashed with checksum. The ownership class is intentloom-managed for .aif/ and catalog/, provider-derivative for .claude/, CLAUDE.md, .cursor/, .cursorrules, and any path containing copilot-instructions.md, and project-owned otherwise.
Role candidates are pushed in this order, and a path may receive more than one:
docs/product/CURRENT_STATE.mdorCURRENT_STATE.md:operational-project-stateat confidence 1.PROJECT_STATE.md:operational-project-stateat confidence 1.AGENT_START_HERE.md:agent-entrypointat confidence 1.DUTY_WATCH.md:duty-watch-logat confidence 1.AGENTS.md:working-agreementat confidence 0.9.ROADMAP.md:roadmapat confidence 1.CHANGELOG.md:changelogat confidence 1.SECURITY.md:security-policyat confidence 1.docs/governance/ENGINEERING_PRINCIPLES.mdor a path ending inENGINEERING_PRINCIPLES.md:validation-policyat confidence 0.9.- A path starting with
.claude, orCLAUDE.md:provider-instructions:claudeat confidence 1. - A path starting with
.cursor, or.cursorrules:provider-instructions:cursorat confidence 1. - A path containing
copilot-instructions.md:provider-instructions:copilotat confidence 1. docs/decisions/:durable-project-contextat confidence 0.8.docs/specs/:durable-project-contextat confidence 0.8.
Evidence strings stay the current filename, provider, and directory text. Defaults passed to planGovernanceAdoption stay project, duty-watch, and 1.0.0 when the options omit them. validations and exceptions are forwarded only when the option is present.
Governance apply
The root check throws Error("adoption apply requires a non-symbolic explicit project root"). schemaVersion !== 1 throws Error("unsupported adoption plan schema version").
Before dry-run and before writes, every operation with both path and expectedCurrentHash is read when the file exists. A read error returns stale-hash with Unable to read target file for hash verification: ${op.path}. A checksum mismatch returns stale-hash with Stale content hash for ${op.path}. A missing file is not a hash failure. appliedOperations, createdFiles, and updatedFiles are empty on both stale results.
Dry-run then returns no-op, with appliedOperations set to every operation id, and empty created and updated lists. It does not write.
A create operation with a path reads the existing file into an in-memory backup map when that path is not already backed up, creates the parent directory, and writes one of two bodies. The agent-entrypoint body is exactly:
# Agent Entrypoint
Start here for repository instructions and workflows.Every other create body is `# Intentloom Governance ${op.role ?? op.path}\n`. A missing file is recorded in createdFiles. An existing file is recorded in updatedFiles. The operation id is appended to appliedOperations. Any other operation kind appends the id and does not touch the filesystem.
The journal path is .aif/migration-journal.json. An existing file is parsed as MigrationJournalEntry[]. Parse failure uses an empty array. The entry id is deterministicId("journal", { planId, timestamp }) where timestamp is appliedOperations.join(","), not the clock. The entry's own timestamp is new Date().toISOString(). The entry status is applied. The file is written with JSON.stringify(entries, null, 2). Success returns success, the three arrays, and journalEntryId.
inside still throws path traversal for a path that escapes the root. That throw is unchanged.
16. Error and rollback flows
flowchart TB
subgraph generated ["Generated-file adoption"]
gChoice{"dry-run or blocked"}
gNoSync["return AdoptionProposal, no syncProject"]
gSync["syncProject"]
gOk["success: applied true"]
gRestored["failed and rollback completed: failed-restored"]
gIncomplete["failed and rollback incomplete: failed-incomplete"]
gChoice -->|yes| gNoSync
gChoice -->|no| gSync
gSync -->|status success| gOk
gSync -->|rollbackCompleted| gRestored
gSync -->|rollback not completed| gIncomplete
end
subgraph governance ["Governance apply"]
gRoot{"symbolic root or schema"}
gThrow["throw Error, no write"]
gHash{"expected current hash"}
gStale["stale-hash, no write"]
gDry{"dryRun"}
gNoop["no-op, no write"]
gWrite["in-memory backup, then create writes"]
gJournal["append migration journal"]
gSuccess["status success"]
gCatch["create or journal throws"]
gRestore["best-effort file restore, journal not guaranteed restored"]
gRolled["status rolled-back, empty applied lists"]
gRoot -->|invalid| gThrow
gRoot -->|accepted| gHash
gHash -->|mismatch or unreadable| gStale
gHash -->|matches| gDry
gDry -->|true| gNoop
gDry -->|false| gWrite
gWrite -->|creates succeed| gJournal
gJournal -->|write succeeds| gSuccess
gWrite -->|throws| gCatch
gJournal -->|throws| gCatch
gCatch --> gRestore
gRestore --> gRolled
end
subgraph approved ["Approved Apply"]
engine["executeApprovedApplyPlan"]
gate{"evaluateApprovedApplyPlan"}
gateFail["applied false, no write, no transaction rollback"]
scope{"declared-paths scope"}
scopeFail["path-scope-mismatch, no write"]
base{"supplied baseline"}
blocked["throw ApplyBlockedBeforeWrite before the transaction"]
tx["synchronizeGeneratedFiles"]
txFail["transaction failed: existing rollback, applied false"]
txOk["transaction success: applied true"]
engine --> gate
gate -->|not passed| gateFail
gate -->|passed| scope
scope -->|paths differ| scopeFail
scope -->|not declared-paths, or paths match| base
base -->|stale| blocked
base -->|current, or no supplied baseline| tx
tx -->|status failed| txFail
tx -->|status success| txOk
endEditable source: failure-rollback-comparison.mmd.
Onboarding blocking is exactly:
const profileConfirmationRequired =
profileDetection.manualConfirmationRequired && !options.profileConfirmed;
const blocked =
profileConfirmationRequired ||
mappingDiagnostics.length > 0 ||
validationDiagnostics.length > 0 ||
items.some(
(item) =>
item.manualDecisionRequired ||
(item.action === "conflict" && options.profileConfirmed !== true),
);manualDecisionRequired is projectOwned || metadataConflict for a desired destination, and duplicate && mappedDocument === undefined for a scanned file. A conflict that is not a manual decision blocks only when profileConfirmed is not strictly true.
applicationStatus starts as not-requested when options.dryRun is true, blocked when blocked, and applied otherwise. Sync runs only when options.dryRun is false and blocked is false. When the sync result has no dryRun property and status is success, applied becomes true. Otherwise applicationStatus becomes failed-restored when rollbackCompleted is true and failed-incomplete when it is not. A result that still has dryRun leaves applied false and leaves the status at its initial value. The implementation must not "correct" that branch.
Transaction diagnostics are coerced. A diagnostic matching /^[a-z0-9][a-z0-9:-]*$/u is kept. Any other diagnostic becomes transaction-failed. The set is sorted. errorCode is null on success. On failure it is the post-write validation code when that validation is invalid, otherwise the first safe diagnostic that is not transaction-rollback-incomplete, otherwise transaction-failed. Rollback failure paths pass through normalizeOutputPath. A path that throws is dropped. The remaining paths are sorted.
Proposal diagnostics are the profile confirmation string, mapping diagnostics, validation codes, and `${path}: manual decision required`, then sorted. Items are sorted before that diagnostic list is built.
Governance apply has no transaction object. On a thrown write error it walks the backup map. null means fs.remove. A string means fs.write of the original content. A restore error is swallowed. The returned status is rolled-back, with error set to the caught message, and the three arrays empty. The journal is not in the backup map unless an operation path happened to be the journal path. A journal failure after creates therefore restores the created files and does not claim to restore a partially written journal. This is best-effort. It is not the generated-file transaction, and it does not have atomicity.
Recorded risks, not changes:
- Governance
createoverwrites an existing file without reading ownership metadata. - Non-create operations are marked applied even though nothing was written, and a later rollback still returns empty
appliedOperations. - Malformed journal JSON is replaced by a new one-entry array when the write succeeds.
- The journal id input named
timestampis the joined operation ids. The entry clock is a separatenew Date().toISOString(). - Restore errors are discarded.
- Secret-like filtering applies to planning, not to apply.
- Unreadable files are skipped during planning and returned as
stale-hashduring apply.
The extraction must keep each of those behaviors.
17. Approved Apply cycle-retarget analysis
Import edges were read from source and checked with applicationCycles(false) and applicationCycles(true).
| Module | Current edges that matter | Reaches index.ts today | index.ts reaches it today |
|---|---|---|---|
approved-apply-baseline.ts | type FileSystem from index.ts only, inside the application graph | import yes, re-export yes | import yes, through declared; re-export yes, through the engine |
generated-file-sync-declared.ts | value ApplyBlockedBeforeWrite from baseline; type imports from index.ts; destination-collisions.ts; generated-file/sync-mode.ts | import yes, re-export yes | import yes, re-export yes |
approved-apply-engine.ts | value synchronizeGeneratedFiles and nodeFileSystem, plus FileSystem and TransactionOptions, from index.ts; baseline; gate; declared | import yes, re-export yes | import no; re-export yes, because of export * |
approved-apply-gate.ts | protocol and validator only | no | import no; re-export yes, through export * |
index.ts | value-imports synchronizeDeclaredProjectPaths; re-exports the engine | the component | the component |
destination-collisions.ts imports only @intentloom/core. generated-file/sync-mode.ts has no imports. approved-apply-gate.ts does not import the application barrel.
Retarget only the baseline FileSystem import to host-file-system.ts. Declared still imports index.ts, and index.ts still imports declared. The import-only component shrinks to { generated-file-sync-declared.ts, index.ts } and the Neutron trio. index.ts remains in an SCC. This is not sufficient.
Retarget only the declared type imports. The baseline still imports index.ts. index.ts still imports declared, and declared still imports the baseline. The import-only component stays { approved-apply-baseline.ts, generated-file-sync-declared.ts, index.ts }. The re-export component stays 29 files. This is not sufficient.
Retarget both:
approved-apply-baseline.tsimportsFileSystemfrom./host-file-system.js.generated-file-sync-declared.tsimportsFileSystemfrom./host-file-system.js,Planfrom./project-change.js, andPostWriteValidationResult,TransactionOptions,TransactionResult, andTransactionStagefrom./generated-file/transaction-contracts.js.
After both edits, neither file has a path back to index.ts. index.ts still imports declared, and declared still imports baseline. Those edges are one-way. The engine still imports index.ts. That remaining edge is a value dependency on synchronizeGeneratedFiles. It is not the type-only cycle. The engine file is not edited.
Approved Apply behavior that must stay on the current engine path:
executeApprovedApplyPlancallsevaluateApprovedApplyPlan. The gate does not call the engine, and the engine does not callsyncProject.- A failed gate still returns
applied: falseand does not write. It does not start transaction rollback. - Declared-path mode still rejects a path-set mismatch with
path-scope-mismatchbefore baseline capture. captureApprovedApplyBaselineandassertApprovedApplyBaselineCurrentstay inapproved-apply-baseline.ts.- A supplied baseline still uses
filesystemGuardingBaseline. ApplyBlockedBeforeWritekeeps its class,name, andfailureCodevaluesproject-staleandrestoration-snapshot-failed.- The engine still calls
synchronizeGeneratedFilesfromindex.ts, which still branches to declared-path sync orcommitOwnedGeneratedFiles. - Transaction options, post-write validation, rollback fields, and execution-result diagnostics stay on that result.
sequenceDiagram
participant Caller
participant Engine as executeApprovedApplyPlan
participant Gate as evaluateApprovedApplyPlan
participant Baseline as approved-apply-baseline
participant Sync as synchronizeGeneratedFiles
participant Declared as synchronizeDeclaredProjectPaths
participant Commit as commitOwnedGeneratedFiles
Caller->>Engine: request, files, options
Engine->>Gate: request
alt gate rejected
Gate-->>Engine: passed false
Engine-->>Caller: applied false
else declared path set mismatch
Engine-->>Caller: path-scope-mismatch
else gate passed
Engine->>Baseline: capture or assert current baseline
alt supplied baseline is stale
Baseline-->>Engine: ApplyBlockedBeforeWrite
else baseline current
Engine->>Sync: root, files, guarded fs, transaction options
alt declared-paths mode
Sync->>Declared: same arguments
else ordinary mode
Sync->>Commit: same arguments
end
Sync-->>Engine: TransactionResult
Engine-->>Caller: ApprovedApplyExecutionResult
end
endEditable source: approved-apply-sequence.mmd.
18. Current and projected SCC memberships
Current import-only components, confirmed with applicationCycles(false):
approved-apply-baseline.ts,generated-file-sync-declared.ts,index.tsneutron/mutation/apply/neutron-mutation-apply-durable-record.ts,neutron/mutation/apply/neutron-mutation-apply-store.ts,neutron/mutation/verification/neutron-mutation-verification-retry-eligibility.ts
Current re-export-inclusive components, confirmed with applicationCycles(true):
apply-extension-update.ts,discover-and-apply-extension-update.ts,extension-update-files.ts,propose-and-apply-extension-adoption.ts- The 29 files locked in
tests/project-lifecycle-p1i2-structure.test.ts:approved-apply-baseline.ts,approved-apply-engine.ts,bounded-execution-apply.ts,bounded-execution-w11.ts,bounded-execution-workspace-cli.ts,bounded-execution-workspace.ts,engineering-quality-entry.ts,engineering-quality/cli-specialized-packs-external.ts,engineering-quality/index.ts,engineering-quality/specialized-pack-external-apply.ts,engineering-quality/specialized-pack-external-viewmodel.ts,existing-project-adoption-apply-gates.ts,existing-project-adoption-apply-health.ts,existing-project-adoption-apply.ts,existing-project-adoption-approval.ts,existing-project-adoption-decisions.ts,existing-project-adoption-plan.ts,existing-project-adoption-prepared-plan-revalidate.ts,existing-project-adoption-prepared-plan.ts,existing-project-w9.ts,existing-project-workspace-cli.ts,existing-project-workspace.ts,foundation-flow.ts,generated-file-sync-declared.ts,harness/harness-benchmark-sample.ts,harness/harness-benchmark.ts,harness/harness.ts,inception-flow.ts,index.ts - The same Neutron mutation trio.
The projection uses the same import and re-export split as tests/application-source-cycles.ts. The current components produced by that projection matched the locked arrays before any edge was removed. The predicted graph deletes only the two index.ts type edges named in section 17 and adds one-way imports from index.ts to the new project-adoption/ modules. Those modules do not import index.ts. This is a prediction. The implementation test is the measurement.
Predicted import-only components after both the extraction and the retarget:
- The Neutron mutation trio, unchanged.
index.ts is in no import-only component. The baseline and declared modules are in no import-only component. No new component appears.
Predicted re-export-inclusive components:
- The extension-update quartet, unchanged.
- The previous 29 files without
approved-apply-baseline.tsand withoutgenerated-file-sync-declared.ts. Size 27.index.tsandapproved-apply-engine.tsremain. The other 25 members of that previous list remain. - The Neutron mutation trio, unchanged.
The size-27 component remains because the barrel re-exports approved-apply-engine.ts and the engine imports synchronizeGeneratedFiles from the barrel. Eliminating the size-3 import component does not eliminate that re-export component. The new adoption modules are absent from every component. Adding an import from any of them back to index.ts creates a new size-2 import component. That is why alternative A is rejected.
flowchart TB
subgraph importNow ["Import-only now: sizes 3 and 3"]
baselineNow["approved-apply-baseline.ts"]
declaredNow["generated-file-sync-declared.ts"]
indexNow["index.ts"]
neutronNow["neutron mutation trio"]
end
subgraph importNext ["Import-only predicted: size 3 only"]
neutronNext["neutron mutation trio unchanged"]
end
subgraph reexportNow ["Re-export now: sizes 4, 29, and 3"]
extNow["extension update quartet"]
barrelNow["29 files including index, baseline, declared, and engine"]
neutronReNow["neutron mutation trio"]
end
subgraph reexportNext ["Re-export predicted: sizes 4, 27, and 3"]
extNext["extension update quartet unchanged"]
barrelNext["27 files: index and engine remain; baseline and declared leave"]
neutronReNext["neutron mutation trio unchanged"]
end
baselineNow --> indexNow
declaredNow --> baselineNow
declaredNow --> indexNow
indexNow --> declaredNowEditable source: scc-impact.mmd.
Between the two implementation pull requests, after extraction and before the retarget, the prediction is the current membership: import sizes 3 and 3, re-export sizes 4, 29, and 3. The new files are outside every component. The retarget pull request is what changes 3 and 3 into one Neutron component, and 29 into 27.
19. Source-size and function budgets
Moved regions measure:
| Region | Effective | Physical |
|---|---|---|
| Proposal types, lines 392–444 | 51 | 53 |
unsupportedPath, normalizeMappingPath, and adoptProject | 315 | 317 |
| Governance options, planner, and apply, lines 873–1201 | 313 | 329 |
| Total leaving the barrel before glue | 679 | 699 |
The barrel adds back the adoptProject wrapper, the planProjectAdoption import, and the re-export lines. A planning allowance for that glue is about 30 to 40 effective lines. The estimate for index.ts after the extraction is about 1,910 effective lines and about 2,080 physical lines, down from 2,561 and 2,736. That is an estimate, not an implementation measurement. The implementation prints measureProductionSource again and pins that measurement. The file must be smaller than the baseline on both counts. It will remain above the 400-line preference and under the grandfathered ceiling. This design does not add an exception and does not change 6,764 / 7,151.
New files, planning targets, not measurements:
| File | Expected content | Target |
|---|---|---|
generated-file-adoption-contracts.ts | the 51-line type block plus imports | under 80 |
generated-file-adoption-mappings.ts | path normalization and both mapping loops | under 120 |
generated-file-adoption-classification.ts | the two item builders, split into predicates | under 220 |
generated-file-adoption-outcome.ts | token coercion and outcome mapping | under 80 |
generated-file-adoption.ts | context read, blocking, and adoptGeneratedFiles | under 160 |
governance-adoption-contracts.ts | three public types | under 80 |
governance-adoption-artifacts.ts | ownership class and the 14 role checks, split | under 180 |
governance-adoption-plan.ts | scan loop and planGovernanceAdoption call | under 120 |
governance-adoption-apply.ts | hash check, creates, journal, rollback | under 250, or split the journal |
Every new production file must measure at or below 250 effective lines and 700 physical lines, and must not exceed 400 effective lines. Every new function must measure at or below 80 effective lines. The orchestrators and the role-candidate combiner should be at or below 40. adoptGeneratedFiles has four positional parameters and must not gain a fifth. The public wrappers keep the signatures in section 12.
adoptProject at 304, planProjectAdoption at 159, and applyProjectAdoption at 132 must not be moved as single functions. The desired-destination item literal is about 58 physical lines and the scanned-file item literal is about 56. Each must be split into named predicates so the function that assembles the item stays at or below 80. The role-candidate chain is about 105 physical lines and must be split into ordered groups whose concatenation preserves the order in section 15.
No function body is copied into a file that already exceeds 400 effective lines. generated-file-sync-declared.ts is 302 effective lines and 314 physical lines. This slice changes its imports only. It must not gain a new rule. approved-apply-baseline.ts is 184 / 210 and approved-apply-engine.ts is 146 / 160. The engine is not edited. The baseline file changes one import line.
20. Regression-test matrix
This pull request does not modify tests. The implementation must keep every behavioral assertion below and may change only the structure assertions named here.
| Behavior | Existing test files |
|---|---|
| Generated-file adoption proposal and apply | tests/adoption-proposal.test.ts, tests/adoption-apply.test.ts, tests/adoption-fixtures.test.ts, tests/adoption-profile.test.ts, tests/adoption-contracts.test.ts |
| Documentation concepts and Nx profile fixtures | tests/existing-project-documentation-concepts.test.ts, tests/existing-project-nx-dogfood.test.ts, tests/instruction-file-taxonomy.test.ts |
| Prepared plan, decisions, approval, health, rollback | tests/existing-project-adoption-plan.test.ts, tests/existing-project-adoption-decisions.test.ts, tests/existing-project-adoption-approval.test.ts, tests/existing-project-adoption-prepared-plan.test.ts, tests/existing-project-adoption-apply.test.ts, tests/existing-project-adoption-apply-rollback.test.ts, tests/existing-project-adoption-apply-immediate-stale.test.ts, tests/existing-project-adoption-apply-lock.test.ts, tests/existing-project-adoption-post-apply-consistency.test.ts |
| CLI adopt and update | tests/cli-adopt.test.ts, tests/cli-adopt-plan.test.ts, tests/cli-adopt-apply.test.ts, tests/cli-update.test.ts, tests/cli-pack-update.test.ts |
| Daemon and Desktop prepared-plan surfaces | tests/daemon-adoption-plan.test.ts, tests/daemon-adoption-apply.test.ts, tests/daemon-existing-project.test.ts, tests/desktop-adoption-preview.test.ts, tests/desktop-adoption-apply.test.ts, and the other tests/desktop-adoption-* and tests/daemon-adoption-* files |
| Governance success, dry-run, stale hash, journal | tests/cli-adopt-apply.test.ts, tests/cli-pack-update.test.ts |
| Approved Apply gate and engine | tests/approved-apply-gate.test.ts, tests/approved-apply-engine.test.ts, tests/desktop-legacy-approved-apply-isolation.test.ts |
| Declared paths, symlink safety, stored paths | tests/generated-file-transaction-p1i1-structure.test.ts, tests/generated-file-symlink-safety.test.ts, tests/generated-file-ownership-classification.test.ts, tests/stored-path.test.ts, tests/application-project-path.test.ts |
| SCC membership and barrel size | The structure tests listed below |
tests/cli-adopt-apply.test.ts locks governance success, dry-run no-op, stale-hash, and the migration journal through the CLI. No current test was found that calls applyProjectAdoption directly for the symbolic-root throw, the schema-version throw, or the swallowed rollback error. The extraction must not change those paths. The implementation may add a regression that locks the current catch behavior, including an empty result after a swallowed restore error. It must not replace that catch with the generated-file transaction.
Structure assertions that pin the current barrel size, 2,561 effective and 2,736 physical, and therefore change when the extraction lands:
tests/generated-file-transaction-p1i1-structure.test.tstests/project-lifecycle-p1i2-structure.test.tstests/security-audit-structure-p1h6.test.tstests/workspace-read-model-p1h7-structure.test.ts
They should pin the new measured size. They should not be widened to a ceiling that allows the barrel to grow.
Assertions that pin import sizes [3, 3], re-export sizes [4, 29, 3], or the three-file import membership change only in the retarget pull request:
tests/generated-file-transaction-p1i1-structure.test.tstests/project-lifecycle-p1i2-structure.test.tstests/application-foundation-scaffold-cycle.test.tstests/application-inception-cycle.test.tstests/security-audit-structure-p1h6.test.tstests/workspace-read-model-p1h7-structure.test.tstests/sarif-security-import-p1h4b.test.tstests/security-finding-store-p1h4a.test.tstests/security-policy-baseline-p1h5a.test.tstests/security-sandbox-evaluation-p1h5b.test.tstests/skill-catalog-read-p1h3a.test.tstests/skill-procedural-memory-p1h3c.test.tstests/skill-proposal-evaluation-p1h3b.test.ts
The new expected import membership is the Neutron trio only. The new expected re-export index component is the 27 files in section 18. The extension quartet and the Neutron trio stay. Behavioral assertions in those files stay.
The extraction pull request adds tests/project-adoption-p1i3-structure.test.ts. It asserts:
- The nine module paths exist, and
project-adoption/index.tsdoes not. - No file under
project-adoption/contains a relative import ofindex.ts. adoptGeneratedFilesis not a package-root export, andadoptProject,planProjectAdoption, andapplyProjectAdoptionare.- The public
adoptProjectsource still shows the three-parameter signature, the default{}, and the call that passessyncProject. planPackUpdateremains inindex.tsand callsplanProjectAdoption.- The twelve export-map keys are unchanged.
quality-exceptions.jsonstill contains the grandfathered 6,764 and 7,151 ceilings and does not nameproject-adoption.- New files are at or below 250 effective lines unless the contingency journal split was used, in which case both files are still at or below 250. New functions are at or below 80.
- Before the retarget, SCC membership is unchanged and the new files are absent from every component.
- The retarget commit updates this test, and the baseline and declared modules, so their
FileSystem,Plan, and transaction types are imported from the canonical leaves. The engine still importssynchronizeGeneratedFilesfromindex.ts.
Do not loosen an assertion that checks a proposal item, a hash, a journal body, a rollback status, or an Approved Apply failure code.
21. Implementation order
Two implementation pull requests follow maintainer approval of this design. They are not started here.
Pull request A, extraction
- Add the contract modules and re-export the public types.
- Extract generated-file mapping, classification, outcome, and
adoptGeneratedFiles. BindadoptProjectinindex.ts. - Extract governance artifact detection and
planProjectAdoption. Import it inindex.tsforplanPackUpdate. - Extract
applyProjectAdoptionand re-export it. - Add the P1I.3 structure test with the current SCC arrays.
- Run the adoption, Approved Apply, CLI, daemon, and structure suites. Update only the barrel-size pins.
Intermediate SCC expectation: import components stay the current two of size 3. Re-export components stay sizes 4, 29, and 3. New files are outside every component. index.ts is smaller. Approved Apply imports are still the old index.ts type imports.
Pull request B, type-import retarget
- Retarget
approved-apply-baseline.ts. - Retarget
generated-file-sync-declared.ts. - Update the structure tests listed in section 20 to the predicted membership.
- Run
applicationCyclesand the Approved Apply suites. Do not edit the engine.
Intermediate SCC expectation after this pull request: one import component, the Neutron trio. Re-export components of sizes 4, 27, and 3. No new component. If the measured membership differs from section 18, stop and update this design before widening a test.
A single implementation pull request would reach the same final graph. It is not the selected sequence, because the move is behavior-sensitive and the retarget is graph-sensitive. Each pull request needs its own maintainer review. Neither pull request starts P1J, U4, or U5.
22. Migration and rollback
There is no data migration. The public import path stays @intentloom/application. Callers do not change imports.
Rollback of pull request A is reverting that pull request. The barrel returns to the measured 2,561 / 2,736 body, and the SCC arrays in the structure tests return with it. Rollback of pull request B is reverting the two import edits and the SCC assertion updates. Neither revert depends on a journal or a schema change.
Do not ship the retarget inside a commit that also changes an adoption rule. Do not change quality-exceptions.json in either pull request. The review trigger that mentions extracting adoptProject can be rewritten only in a later documentation change that a maintainer authorizes. This design leaves that sentence in place.
23. Risks and unresolved decisions
Risks:
- The barrel-size estimate can miss formatting. The structure test pins the measured value, not the estimate.
- Splitting the item literals can change field order or the
profileConfirmed !== truecheck. The orchestrator tests are the guard. The source order in sections 6 and 16 is the specification. - Four
desiredevaluations on the write path are easy to "clean up". That cleanup is forbidden here. - Governance apply's overwrite and swallowed rollback look like defects. They are recorded above so the move does not silently fix them.
- The size-27 prediction is a graph prediction. Section 21 says to stop if the measured component differs.
generated-file-sync-declared.tsis already over the 250 preference. An import-only edit must not add lines of logic.
Unresolved, and not a blocker for this verdict:
- Whether a later milestone injects
synchronizeGeneratedFilesinto the Approved Apply engine soindex.tscan leave the re-export component. Alternative D is out of P1I.3. - Whether the prepared-plan files should eventually move into
project-adoption/after the barrel no longer needs them on the re-export cycle. Not this slice.
No new ADR is required. ADR-0003 and ADR-0053 already separate non-destructive adoption from Approved Apply. This design does not change either decision.
24. Acceptance criteria
- This pull request contains the design, the eight Mermaid sources, and the minimal project-state updates. It contains no production TypeScript change, no test change, no lockfile change, and no
quality-exceptions.jsonchange. - A maintainer approves this document before implementation.
- Pull request A preserves the signatures in section 12, the operation order in sections 6 and 16, and the two workflow boundaries.
- No new adoption file imports
index.ts. No new function exceeds 80 effective lines. No new file exceeds 250 effective lines without the named journal split, and none exceeds 400. index.tsmeasures smaller than 2,561 effective and 2,736 physical.- Pull request B retargets only the two type imports in section 17. The engine still imports
synchronizeGeneratedFilesfromindex.ts. - The measured import-only components are the Neutron trio only. The measured re-export components are sizes 4, 27, and 3, with the members in section 18. The Neutron trio is unchanged. No new component exists.
ApplyBlockedBeforeWriteidentity, Approved Apply failure codes, and ordinary sync behavior are unchanged.- P1J, Undo U4, and Desktop Undo U5 remain unstarted.
- The SCC numbers in the project-state files stay labeled as predictions until the implementation measures them.
25. Diagram index
| Diagram | Source | What it shows |
|---|---|---|
| Current dependencies | current-dependencies.mmd | Barrel-owned operations and the import triangle |
| Proposed dependencies | proposed-dependencies.mmd | Leaf workflows and the one-way sync binding |
| SCC impact | scc-impact.mmd | Current and predicted import and re-export components |
| Generated-file sequence | generated-file-adoption-sequence.mmd | Onboarding order, including repeated desired |
| Governance sequence | governance-adoption-sequence.mmd | Plan, hash check, dry-run, and journal write |
| Approved Apply sequence | approved-apply-sequence.mmd | Gate, baseline, and the existing dispatcher |
| Trust boundaries | trust-boundaries.mmd | Separate authorization flows |
| Failure and rollback | failure-rollback-comparison.mmd | Transaction rollback versus best-effort restore |
sequenceDiagram
participant Caller
participant Wrapper as adoptProject
participant Leaf as adoptGeneratedFiles
participant Profile as detectProjectProfiles
participant Desired as desired
participant Own as ownership
participant Plan as plan
participant Sync as syncProject
Caller->>Wrapper: options, fs, transactionOptions
Wrapper->>Leaf: options, fs, transactionOptions, syncProject
Leaf->>Profile: root, fs
Profile-->>Leaf: scannedPaths and profileDetection
Leaf->>Desired: options
Desired-->>Leaf: desiredFiles
Leaf->>Own: root, fs
Own-->>Leaf: ownership map or null
Leaf->>Plan: options with dryRun true, fs
Note over Plan,Desired: plan calls desired again
Plan-->>Leaf: change plan
Leaf->>Leaf: mappings, classification, blocking
alt dry-run or blocked
Leaf-->>Wrapper: AdoptionProposal without sync
else write permitted
Leaf->>Sync: options with dryRun false, fs, transactionOptions
Note over Sync,Desired: sync calls plan and desired again
Sync-->>Leaf: TransactionResult
Leaf-->>Wrapper: AdoptionProposal with transactionOutcome
end
Wrapper-->>Caller: AdoptionProposalEditable source: generated-file-adoption-sequence.mmd.
sequenceDiagram
participant Caller
participant Plan as planProjectAdoption
participant Core as planGovernanceAdoption
participant Apply as applyProjectAdoption
participant Fs as FileSystem
Caller->>Plan: options, fs or nodeFileSystem
Plan->>Fs: isSymbolicLink, list, read
Plan->>Core: artifacts, ids, validations, exceptions
Core-->>Plan: AdoptionPlan
Plan-->>Caller: AdoptionPlan
Caller->>Apply: root, plan, dryRun, fs
Apply->>Fs: isSymbolicLink, exists, read
alt schema invalid or symbolic root
Apply-->>Caller: throw Error
else expected hash mismatch
Apply-->>Caller: status stale-hash
else dry-run
Apply-->>Caller: status no-op
else write
Apply->>Fs: mkdir, write created governance files
Apply->>Fs: write .aif/migration-journal.json
Apply-->>Caller: status success
endEditable source: governance-adoption-sequence.mmd.