# Project Knowledge Graph Migration Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Migrate the reference project's knowledge graph, impact analysis, affected testing, documentation workflow, and guarded Live profiles into `regional-assistant`, adapted to its six real domains and existing test/upload boundaries.
**Architecture:** Copy the generic scanner/query contracts from fixed reference commit `e4fc97927e631208fb33af77ac47ea38892026fc`, then isolate all project-specific semantics in `domain-catalog.json`, affected-test roots, documentation, and Live profile definitions. Build graphs deterministically from the current worktree, keep generated artifacts under upload-excluded `docs/`, and conservatively escalate uncertain or shared changes to the full offline suite.
**Tech Stack:** Node.js 24, `node:test`, ECMAScript modules, `@babel/parser`, WeChat Mini Program `app.json`/WXML/component JSON, Markdown/JSON docs-as-code, PowerShell, Git.
- Source implementation is pinned to `dj-car-boutique-work-wechat` commit `e4fc97927e631208fb33af77ac47ea38892026fc`.
- Do not store either user-provided phone number, any verification code, session, signature, secret, or app key in code, tests, docs, manifests, generated artifacts, or logs.
-`regional-dev-login` is login-only and must never authorize business writes.
-`regional-test` writes require `RUN_ORDER_E2E=1`, an exact test URL allowlist, and `LIVE_ALLOW_WRITES=1`.
- Ordinary `npm test`, `test:affected`, and project-quality checks must skip Live tests by default.
- Generated knowledge files remain under upload-excluded `docs/`; `.agents/` must be added to the explicit upload exclusions.
- Do not modify Mini Program runtime behavior except the approved `filterOrderMerchantOptions` baseline fix.
- Build output is deterministic: no timestamps, Git SHA fields, source snippets, or credential values.
- Dynamic imports, routes, and endpoints are reported as `unresolved`; they are never guessed.
- All migration work must pass the manifest pre gate before runtime or migration script changes and the post gate after verification.
Create valid JSON with these exact fields. Use the design commit as the runtime baseline so the result is stable even though this plan is a later docs-only commit:
-[]**Step 4: Establish the full current baseline**
Run:
```powershell
npm run test:workOrder
```
Expected: migration, createOrder, order-lifecycle, and closure checks all pass; Live tests remain skipped unless their explicit environment flags are present.
- Consumes: `buildKnowledgeGraph({ rootDir: string }): Promise<Graph>` and `serializeGraph(graph): string` from the pinned reference.
- Produces: Graph schema version `1.0.0`, deterministic nodes/edges/unresolved/stats, and a self-contained fixture contract.
-[]**Step 1: Read the pinned source files**
Run these read-only commands and use their exact committed contents as the migration source:
```powershell
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:scripts/knowledge-graph/build-knowledge-graph.mjs
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:tests/knowledge-graph/buildKnowledgeGraph.test.mjs
Expected: the builder exports the two stated functions and the fixture list contains app/page/component/API/test/docs examples plus ignored tool/temp directories.
-[]**Step 2: Add the test and fixture before the builder**
Use `apply_patch` to add the pinned fixture and test files. Add two current-design regressions to `buildKnowledgeGraph.test.mjs`:
1. Create generated Markdown fixtures under `docs/generated/ignored.md` and `docs/COMPONENT-PAGE-INDEX.md`, then assert neither generated location becomes a document node.
2. Assert the component node for `components/card/card` contains both registration aliases `app-card` and `local-card`, so impact queries can start from the WXML/app.json tag name.
Expected: fail because `scripts/knowledge-graph/build-knowledge-graph.mjs` does not exist.
-[]**Step 4: Add and adapt the generic builder**
Use `apply_patch` to add the pinned builder. Preserve its public schema and parsing behavior. Add `docs/generated/` to `IGNORED_PATH_PREFIXES` so generated Markdown cannot become an input to the next graph build:
```js
constIGNORED_PATH_PREFIXES=[
'docs/COMPONENT-PAGE-INDEX.md',
'docs/generated/',
'tests/.migration-readiness-',
'tests/knowledge-graph/fixtures/'
]
```
In `registerComponents`, merge each JSON registration tag into the target component node's sorted `aliases` array before adding the `usesComponent` edge:
- Produces: `createKnowledgeArtifactContents`, `writeKnowledgeArtifacts`, `checkKnowledgeArtifacts`, `queryKnowledgeGraph`, and build/check/query CLIs.
-[]**Step 1: Add pinned RED tests**
Read the exact source with:
```powershell
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:tests/knowledge-graph/artifactsAndImpact.test.mjs
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:tests/knowledge-graph/cli.test.mjs
```
Add both files with `apply_patch` and retain assertions for generated paths, stable output, upstream/downstream results, cross-domain risks, tests, documents, and unsupported CLI arguments.
Expected: fail because the artifact/query modules do not exist.
-[]**Step 3: Add the four pinned modules**
Read the exact implementations with these commands, then use `apply_patch` to add them:
```powershell
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:scripts/knowledge-graph/knowledge-artifacts.mjs
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:scripts/knowledge-graph/knowledge-build.mjs
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:scripts/knowledge-graph/knowledge-check.mjs
git -C C:\Users\admin\Desktop\工作\dj-car-boutique-work-wechat show e4fc97927e631208fb33af77ac47ea38892026fc:scripts/knowledge-graph/query-knowledge-graph.mjs
```
Keep `--depth` limited to 0–3, directions limited to `both|upstream|downstream`, formats limited to `json|md`, and check mode read-only.
-[]**Step 4: Verify GREEN**
Run the Step 2 command.
Expected: all artifact, query, and CLI tests pass.
Real query cases must use these exact keywords and expectations:
-`createOrder`: direct matches include the createOrder page/module and return work-order tests/documents.
-`wx.$orderListRefresh`: result includes the write in `utils/util.js` and the read/reset in `pages/tabWorkOrder/pages/index/index.js`, while exposing related unresolved entries instead of guessing.
-`packageWorkspace`: direct matches include workspace pages/modules and domain `workspace`.
-`gl-cust-form`: results include the global component registration and packageWorkspace consumer evidence.
Preserve conservative full escalation for global entries, dependencies, shared runtime roots, cross-domain changes, unresolved changed paths, unclassified runtime/tooling, and missing test candidates.
-[]**Step 4: Add stable package commands**
Merge these scripts into the existing `scripts` object without removing any current command:
- Consumes: Stable commands and generated artifacts from Tasks 4–6.
- Produces: A project-local workflow that always uses DOMAIN-INDEX → knowledge check/query → semantic `rg` review → affected tests.
-[]**Step 1: Load the required skill-authoring guidance**
Before editing `.agents/skills/**`, read `superpowers:writing-skills` completely and follow its RED/GREEN verification workflow.
-[]**Step 2: Add failing governance tests**
Adapt the pinned `tests/project-governance/knowledgeWorkflow.test.mjs` to assert that:
- root README contains `knowledge:build`, `impact`, and `test:affected`;
- docs README describes generated artifacts, unresolved behavior, upload exclusion, and Live safety;
- DOMAIN-INDEX lists all six domains and links generated indexes;
- the Skill requires `knowledge:check`, `impact`, semantic `rg`, impact classification, and `test:affected`;
- none of the new profile/Skill/docs files contains an 11-digit mobile literal. The repository test must use only this generic pattern and must not contain either user-provided value:
- current docs paths under `docs/order-creation`, `docs/order-lifecycle`, and `docs/tabWorkOrder`.
Keep the rule that graph adjacency is evidence, not an automatic must-change list.
-[]**Step 5: Rewrite documentation entrypoints**
Replace the root README account-only content with a concise project setup and knowledge workflow. Extend `docs/README.md` with the complete build/query/affected/profile/maintenance guide. Expand `docs/DOMAIN-INDEX.md` from the current work-order-only table to the six-domain map while preserving all existing work-order links.
thrownewError('Approved Live profile is required')
}
if(profile.mode!=='functional'){
thrownewError(`${profile.name} does not allow Live writes`)
}
if(env.LIVE_ALLOW_WRITES!=='1'){
thrownewError('LIVE_ALLOW_WRITES=1 is required for Live write tests')
}
returntrue
}
```
-[]**Step 4: Keep order E2E test-only**
Update `loadE2EConfig` so `ORDER_E2E_PROFILE=regional-test` resolves the test profile and requires the independent write gate. Reject `regional-dev-login` before creating an ROP order harness. Preserve the existing legacy test-environment variables only as a compatibility path, also guarded by `LIVE_ALLOW_WRITES=1`.
Update `assertAllowedE2EEnvironment` to accept an explicit exact `allowedBases` list without weakening URL protocol, hostname, port, path, query, fragment, username, or password checks.
-[]**Step 5: Add login-only UI configuration**
Implement `loginSmokeConfig.mjs` with the same DevTools connection fields already used by `uiSmokeConfig.mjs`: `ORDER_UI_LAUNCH`, `ORDER_UI_CLI_PATH`, `ORDER_UI_PROJECT_PATH`, `ORDER_UI_PORT`, and `ORDER_UI_WS_ENDPOINT`. Its separate enable/profile fields are `RUN_LOGIN_UI_E2E` and `LOGIN_UI_PROFILE`.
`requireLoginSmokeConfig` must call `resolveLiveProfile`, require profile mode `login-only`, require `regional-dev-login`, validate port 1024–65535, require a loopback `ws:` endpoint, and require `ORDER_UI_CLI_PATH` only when launching DevTools. It returns the profile's runtime mobile/code together with the existing launcher fields.
-[]**Step 6: Add login-only UI smoke**
Implement `loginSmoke.live.test.mjs` with `miniprogram-automator`. It must:
- skip unless `RUN_LOGIN_UI_E2E=1`;
- require `LOGIN_UI_PROFILE=regional-dev-login`;
- resolve credentials at runtime;
- use `openMiniProgram(automator, config)` and always close the connection in `finally`;
- reLaunch `/pages/wxLogin/wxLogin`, set `loginType: 1`, accept the privacy checkbox, populate the two inputs, and tap `.login_btn`;
- wait for the exact page `pages/accountItems/accountItems`, read `loginUserInfoList`, and assert it is a non-empty array without serializing its contents;
- stop immediately after that assertion, before tapping any `.items` entry, selecting a park/store/scene, or opening an order page;
- never include credential values in assertion messages or diagnostics.
-[]**Step 7: Add best-effort order cleanup**
Add the pinned `liveCleanup.mjs` and adapt `orderLifecycle.live.test.mjs` with this exact cleanup mapping:
- cancel flow: track every created order and call cleanup in `catch`; the successful flow already revokes its own order;
- correction flow: track source and corrected orders and call cleanup in `finally`;
- no-construction flow: track the paid order and call cleanup in `finally`;
- construction flow: track the paid order and call cleanup in `finally` even when construction or rework fails;
- cleanup iterates tracked orders in reverse order, continues after a failed revoke, and emits only `orderCode`, role, and a normalized failure reason.
Expected: consecutive builds have identical hashes, check passes, and the displayed diff contains only expected Task 8 test/profile graph changes that will be committed as final evidence.
-[]**Step 3: Run the complete offline suite**
```powershell
npm test
```
Expected: all offline tests pass; every Live test is skipped by default.
-[]**Step 4: Exercise the public CLI contracts**
```powershell
npm run impact -- --keyword createOrder --depth 2 --direction both --format json
npm run impact -- --keyword packageWorkspace --depth 2 --direction both --format json
npm run test:affected -- --list --format json
```
Expected: both queries return non-empty evidence; affected output has mode, reasons, changedFiles, domains, tests, commands, and unresolved fields.
-[]**Step 5: Verify upload exclusions and tree hygiene**
Expected: docs/tests/scripts/.agents are excluded, upload guard passes, no whitespace errors, and status contains only final migration evidence updates.
-[]**Step 6: Update acceptance evidence**
Change every Post entry in `test-acceptance.md` to `pass` only when the corresponding command above has actually passed. Update manifest test entries and verification statuses to match the observed results; do not mark a blocked command as pass.
-[]**Step 7: Run the required post gate**
```powershell
npm run check:migration -- --manifest docs/migrations/project-knowledge-graph/manifest.json --phase post
```
Expected: `Migration readiness post check passed` and every non-blocked verification command is re-executed successfully by the gate.