• 设计见 docs/done/system-design/28-agent-registry-unification.md。
    
    改造前 Agent 本体散在三处(system/agents/ 11 个、system/templates/ 50 个、
    data/companies/{id}/agents/ 17 个),同一个 AgentScaffold 被三个 baseDir 实例化。
    后果是同一角色在 N 家公司下有 N 份互不相干的副本,模板更新不会同步;
    org-coder / org-planner 这类走 hireFromBaseMetaAgent 造出来的本体
    legacy_path 指回自己公司目录,永远无法被第二家公司复用。
    
    本次:
    - G1 单一注册表:system/templates/ 整体并入 system/agents/,base → _base。
      7 个同名 id 逐个裁决,被丢弃的一份归档到 docs/_archive/ 而非删除。
      source_kind(template/global_agent/company_hired) → origin(builtin/created)。
    - G2 运行态下沉:CLI 的 cwd 从本体根改为 system/agents/{aid}/{cid}/{taskId}/。
      memory / conversations 落公司态 {aid}/{cid}/,按公司隔离不串。
      sessionPool 的 key 含 (companyId, taskId),两家公司调同一 agent 不复用会话。
    - G2b 产物不下沉:交付物仍落 data/companies/{cid}/,system/agents/ 只留运行痕迹。
      写入边界按链路分叉——graph 节点走节点私有目录(被 indexNodeOutputs 索引),
      chat 走公司 workspace,同一提示词里不再出现两条互斥指令。
    - G3 公司只存引用:data/companies/{id}/agents/ 删除,新增 company_agents 关联表。
      不复用 org_graph_nodes——后者是执行流图,work 层本体被雇时不写它,天生覆盖不全。
    - G4 缺则创建:本体缺失时从 _base 复制骨架进 system/agents/{id}/,
      agent-creator 填 agent.md/soul.md 后才从 draft 转 active(哨兵判据,
      骨架未填时哨兵仍在,不许被 hire)。产物即刻是全系统可复用的本体。
    
    新增 server/services/agent-locator.js 收编原先散在 6 处的寻址逻辑。
    
    边界守卫(graph-engine)的豁免从「本体根上五个文件名」放宽为整棵 system/agents/:
    新本体的骨架本来就要进 git,gitignore 挡不住 ?? system/agents/{newId}/,
    旧判据会把一个真正成功的招聘节点判成 boundary_escape fail。
    
    存量迁移见 scripts/migrate-agent-registry.js(幂等,备份到 data/_migration-backup-*)。
    
    真 Claude CLI E2E 已验证:新建公司 → orggraph-planning 自动规划 →
    自动招聘 org-planner/org-coder/org-validator 三节点流水线;
    data/companies/{cid}/agents/ 不存在,company_agents 4 行,
    system_agents 56→56(零新建私有本体,纯复用),git status 零增量。
    
    Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
    yibo authored
     
    Browse File »

  • Implements the §P4 acceptance gate from plan-migration.md, with one
    scope adjustment confirmed up-front: full Vue Dashboard (~1650 lines)
    deferred to a future UI phase, replaced by extending the existing
    P3 static status page with Sign Off / Abandon / Feedback controls.
    All P4 backend acceptance criteria are scripted (phase4-verify.js).
    
    Project status FSM (project.json.status):
    - server/src/core/devloop/loop-controller.js
      * draft  →  running  →  shipped  →  shipped-final | abandoned
                    ↓             ↓
              l2_blocked    (feedback flips back to running)
              l2_exhausted
      * `_setProjectStatus` validates transitions via STATUS_TRANSITIONS,
        emits SSE `project.status`, writes timeline event.
      * createProject seeds status=draft; runDocsPhase end → running;
        runProject(shipped) → shipped; all dead-end branches (l2_blocked,
        l2_exhausted) also propagate to status via _safeSetStatus.
    
    L3 helpers:
    - signOff(pid, opts) — requires status=shipped → shipped-final; commits
      a `chore: sign-off` git entry; rejects other source states with
      InvalidProjectStatusTransition.
    - abandon(pid, opts) — any non-terminal → abandoned; commits + calls
      sseBroker.close(pid) to send SSE close frame to subscribers.
    - submitFeedback(pid, text, opts) — rejects in shipped-final/abandoned;
      invokes PM in incremental mode; on prd_rev bump writes
      changelog.ndjson prd_rev entry + emits prd.updated SSE; if prior
      status was shipped, flips back to running so next runProject can
      rebuild.
    
    PM incremental mock fixture:
    - fixtures/devloop-mock/devloop-pm.json — converted to sequence form:
      * sequence[0] (init) — original P1 fixture (PRD rev=1, 14 files).
      * sequence[1] (incremental) — appends a new section to
        prd/feature/feature-tree.html, bumps article data-rev to 2,
        writes history/prd-rev-002.html.
    
    Baseline happy-path Integrator:
    - fixtures/devloop-mock/devloop-integrator.json — single-shot pass.
      Makes vanilla runProject ship without a scenario override.
    
    P4 happy-path scenario:
    - fixtures/devloop-mock-scenarios/happy_path/devloop-architect.json —
      single-unit (todo-be only) Architect so end-to-end ship works with
      the baseline Coder/Tester (which only know todo-be paths).
    
    Routes:
    - server/routes/devloop.js:
      * POST /projects/:pid/sign-off — 400 InvalidProjectStatusTransition
        when status != 'shipped'; 200 returns { status }.
      * POST /projects/:pid/abandon  — body { by?, reason?, note? }; 400 on
        terminal state; 200 returns { status: 'abandoned' }.
      * POST /projects/:pid/feedback — body { text (req), by?,
        mockFixtureDir? }; 400 on missing text or shipped-final/abandoned;
        200 returns { prd_rev_before, prd_rev_after, status }.
      * POST /projects: now accepts optional `mockFixtureDir` so the same
        fixture dir threads through both the create call and later
        feedback (keeps mock-sequence counters aligned).
    
    Static status page (replaces full Vue Dashboard for P4):
    - server/public/devloop-status.html — adds:
      * Status badge in header (color-coded per status).
      * Sign Off / Abandon control buttons (disabled per current state).
      * Feedback textarea + Submit button → POST /feedback.
      * Buttons reflect FSM (signoff only when shipped; abandon/feedback
        locked at terminal states).
    
    Acceptance:
    - scripts/phase4-verify.js — 9 steps, full HTTP path:
      ① POST /projects → running
      ② POST /run → shipped
      ③ POST /feedback → PRD rev 1→2 + running (+ changelog entry)
      ④ POST /run again → shipped
      ⑤ POST /sign-off → shipped-final
      ⑥ POST /feedback (after sign-off) → 400
      ⑦ POST /sign-off (after sign-off) → 400
      ⑧ second project: POST /abandon → abandoned
      ⑨ POST /abandon (after abandon) → 400
    
    Tests (+19 cases):
    - server/tests/devloop/p4-l3-feedback.test.js
      * 14 FSM cases covering happy path + abandon path + signOff
        pre-conditions + empty feedback rejection.
      * 5 route cases via fetch on ephemeral express app.
    
    Results:
    - phase0-verify: 8/8
    - phase0-test-call: 7/7
    - phase1-verify: 7/7
    - phase2-verify: 6/6
    - phase3-verify: 9/9
    - phase4-verify: 9/9
    - vitest devloop+acp-core: 213/213 (was 194 → +19)
    
    Spec deviations explicit:
    - Full Vue DevLoopDashboard.vue + Ops 4 sub-pages NOT implemented;
      static status page handles the demoable surface area instead.
    - All backend endpoints from §P4 (sign-off, abandon, feedback) are
      complete and tested.
    
    Specs: docs/prd/newfunction/_spec/plan-migration.md · P4 L3 + UI
    
    Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
    yibo authored
     
    Browse File »