@elvis1513/auto-coding-skill 2.2.1 → 3.0.1

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.
package/cli/src/index.js CHANGED
@@ -2,6 +2,8 @@
2
2
  import fs from "node:fs";
3
3
  import path from "node:path";
4
4
  import os from "node:os";
5
+ import crypto from "node:crypto";
6
+ import { execFileSync } from "node:child_process";
5
7
  import { fileURLToPath } from "node:url";
6
8
 
7
9
  function die(msg){
@@ -25,6 +27,7 @@ function parseArgs(argv){
25
27
  dryRun: false,
26
28
  json: false,
27
29
  resetAgentModels: false,
30
+ components: "all",
28
31
  projects: [],
29
32
  provided: new Set(),
30
33
  };
@@ -64,6 +67,11 @@ function parseArgs(argv){
64
67
  args.resetAgentModels = true;
65
68
  args.provided.add("resetAgentModels");
66
69
  }
70
+ else if (a === "--components") {
71
+ args.components = takeValue(rest, i, a).trim().toLowerCase();
72
+ args.provided.add("components");
73
+ i += 1;
74
+ }
67
75
  else if (a === "--force") {
68
76
  args.force = true;
69
77
  args.provided.add("force");
@@ -86,13 +94,14 @@ const ARG_FLAGS = {
86
94
  dryRun: "--dry-run",
87
95
  json: "--json",
88
96
  resetAgentModels: "--reset-agent-models",
97
+ components: "--components",
89
98
  projects: "--projects/positional project",
90
99
  };
91
100
 
92
101
  const COMMAND_ARGS = {
93
102
  init: new Set(["ai", "mode", "dest", "force", "resetAgentModels"]),
94
103
  status: new Set(["projects", "json"]),
95
- sync: new Set(["projects", "dryRun", "json", "resetAgentModels"]),
104
+ sync: new Set(["projects", "dryRun", "json", "resetAgentModels", "components"]),
96
105
  };
97
106
 
98
107
  function validateCommandArgs(args){
@@ -102,6 +111,12 @@ function validateCommandArgs(args){
102
111
  if (invalid.length) {
103
112
  die(`${invalid.map(name => ARG_FLAGS[name] || name).join(", ")} not valid for '${args.cmd}'`);
104
113
  }
114
+ if (args.cmd === "sync" && !["all", "skill"].includes(args.components)) {
115
+ die("--components must be 'all' or 'skill'");
116
+ }
117
+ if (args.cmd === "sync" && args.components === "skill" && args.resetAgentModels) {
118
+ die("--reset-agent-models cannot be used with --components skill");
119
+ }
105
120
  }
106
121
 
107
122
  function exists(p){ try { fs.accessSync(p); return true; } catch { return false; } }
@@ -364,19 +379,9 @@ function inferredGateCommands(project){
364
379
  const parsed = JSON.parse(fs.readFileSync(pkg, "utf8"));
365
380
  const scripts = parsed?.scripts;
366
381
  if (!scripts || typeof scripts !== "object") return {};
367
- const inferred = {};
368
- if (typeof scripts.test === "string" && scripts.test.trim()) {
369
- inferred.gate_changed = typeof scripts["test:changed"] === "string" && scripts["test:changed"].trim()
370
- ? "npm run test:changed"
371
- : "npm test";
372
- inferred.gate_standard = typeof scripts["test:standard"] === "string" && scripts["test:standard"].trim()
373
- ? "npm run test:standard"
374
- : "npm test";
375
- }
376
- if (typeof scripts["test:full"] === "string" && scripts["test:full"].trim()) {
377
- inferred.gate_full = "npm run test:full";
378
- }
379
- return inferred;
382
+ return typeof scripts["test:changed"] === "string" && scripts["test:changed"].trim()
383
+ ? { gate_changed: "npm run test:changed" }
384
+ : {};
380
385
  } catch {
381
386
  return {};
382
387
  }
@@ -388,11 +393,179 @@ function renderEngineeringTemplate(templateText, project){
388
393
  `project:\n name: ${JSON.stringify(path.basename(path.resolve(project)))}`,
389
394
  );
390
395
  for (const [key, gate] of Object.entries(inferredGateCommands(project))) {
391
- rendered = rendered.replace(` ${key}: ""`, ` ${key}: ${JSON.stringify(gate)}`);
396
+ rendered = rendered.replace(` ${key}: "git diff --check"`, ` ${key}: ${JSON.stringify(gate)}`);
392
397
  }
393
398
  return rendered;
394
399
  }
395
400
 
401
+ const MANAGED_WORKFLOW_START_TOKEN = "auto-coding-skill:managed-workflow:start";
402
+ const MANAGED_WORKFLOW_END_TOKEN = "auto-coding-skill:managed-workflow:end";
403
+ const MANAGED_WORKFLOW_START_RE = /<!--\s*auto-coding-skill:managed-workflow:start\s+version=([0-9]+\.[0-9]+\.[0-9]+)\s*-->/g;
404
+ const MANAGED_WORKFLOW_END_RE = /<!--\s*auto-coding-skill:managed-workflow:end\s*-->/g;
405
+ const KNOWN_OFFICIAL_LEGACY_BODY_HASHES = new Set([
406
+ // v2.2.0, v3.0.0, and origin/dev@c532734 respectively. Frontmatter is excluded.
407
+ "d1306cc626e8baf8c83c953b760fd771066de2bf125168eca3a7b7d6ff2b87a2",
408
+ "305931c6edef770033a4f1970b00e5fb1c1728351856a173dbfa497daf563021",
409
+ "198d675361337bc272880154266b3eb1f50e3f82f3c6ab04b2e559cd18d8c7b4",
410
+ ]);
411
+
412
+ function tokenCount(text, token){
413
+ return text.split(token).length - 1;
414
+ }
415
+
416
+ function inspectManagedWorkflow(text){
417
+ const rawStarts = tokenCount(text, MANAGED_WORKFLOW_START_TOKEN);
418
+ const rawEnds = tokenCount(text, MANAGED_WORKFLOW_END_TOKEN);
419
+ if (rawStarts === 0 && rawEnds === 0) return { state: "absent" };
420
+
421
+ const starts = [...text.matchAll(MANAGED_WORKFLOW_START_RE)];
422
+ const ends = [...text.matchAll(MANAGED_WORKFLOW_END_RE)];
423
+ if (rawStarts !== starts.length || rawEnds !== ends.length) {
424
+ return { state: "invalid", detail: "managed workflow marker is malformed" };
425
+ }
426
+ if (starts.length !== 1 || ends.length !== 1) {
427
+ return { state: "invalid", detail: "managed workflow markers must contain exactly one start/end pair" };
428
+ }
429
+ const start = starts[0].index;
430
+ const end = ends[0].index;
431
+ if (start >= end) {
432
+ return { state: "invalid", detail: "managed workflow markers are out of order or nested" };
433
+ }
434
+ const endExclusive = end + ends[0][0].length;
435
+ return {
436
+ state: "present",
437
+ version: starts[0][1],
438
+ start,
439
+ endExclusive,
440
+ block: text.slice(start, endExclusive),
441
+ };
442
+ }
443
+
444
+ function splitEngineeringDocument(text){
445
+ const frontmatter = text.match(/^---\r?\n[\s\S]*?\r?\n---(?:\r?\n|$)/);
446
+ const bodyStart = frontmatter ? frontmatter[0].length : 0;
447
+ return { frontmatter: text.slice(0, bodyStart), body: text.slice(bodyStart) };
448
+ }
449
+
450
+ function engineeringBodyHash(body){
451
+ return crypto.createHash("sha256").update(body.replace(/\r\n/g, "\n")).digest("hex");
452
+ }
453
+
454
+ function insertManagedWorkflow(text, block){
455
+ const { frontmatter } = splitEngineeringDocument(text);
456
+ const bodyStart = frontmatter.length;
457
+ const body = text.slice(bodyStart);
458
+ const heading = /^# Engineering Workflow[^\r\n]*(?:\r?\n|$)/m.exec(body);
459
+ const insertion = heading ? bodyStart + heading.index + heading[0].length : bodyStart;
460
+ const before = text.slice(0, insertion);
461
+ const after = text.slice(insertion);
462
+ return `${before}${block}${after}`;
463
+ }
464
+
465
+ function planEngineeringSync(project, assetSkill){
466
+ const root = path.resolve(project);
467
+ const engineering = path.join(root, "docs", "ENGINEERING.md");
468
+ const templatePath = path.join(assetSkill, "data", "templates", "ENGINEERING.md");
469
+ const renderedTemplate = renderEngineeringTemplate(fs.readFileSync(templatePath, "utf8"), root);
470
+ const templateRegion = inspectManagedWorkflow(renderedTemplate);
471
+ if (templateRegion.state !== "present") {
472
+ return { state: "invalid", detail: `packaged ENGINEERING template: ${templateRegion.detail || "managed workflow markers are missing"}` };
473
+ }
474
+ if (!exists(engineering)) {
475
+ return { state: "missing", version: templateRegion.version, output: renderedTemplate, engineering };
476
+ }
477
+
478
+ const current = fs.readFileSync(engineering, "utf8");
479
+ const currentRegion = inspectManagedWorkflow(current);
480
+ if (currentRegion.state === "invalid") return { ...currentRegion, engineering };
481
+ if (currentRegion.state === "absent") {
482
+ const currentParts = splitEngineeringDocument(current);
483
+ const templateParts = splitEngineeringDocument(renderedTemplate);
484
+ const legacyHash = engineeringBodyHash(currentParts.body);
485
+ if (KNOWN_OFFICIAL_LEGACY_BODY_HASHES.has(legacyHash)) {
486
+ return {
487
+ state: "legacy-official",
488
+ version: templateRegion.version,
489
+ previousBodyHash: legacyHash,
490
+ output: `${currentParts.frontmatter}${templateParts.body}`,
491
+ engineering,
492
+ };
493
+ }
494
+ return {
495
+ state: "legacy-custom",
496
+ version: templateRegion.version,
497
+ preservedCustom: true,
498
+ output: insertManagedWorkflow(current, templateRegion.block),
499
+ engineering,
500
+ };
501
+ }
502
+ if (currentRegion.block === templateRegion.block) {
503
+ return { state: "current", version: templateRegion.version, output: current, engineering };
504
+ }
505
+ return {
506
+ state: "stale",
507
+ version: templateRegion.version,
508
+ previousVersion: currentRegion.version,
509
+ output: `${current.slice(0, currentRegion.start)}${templateRegion.block}${current.slice(currentRegion.endExclusive)}`,
510
+ engineering,
511
+ };
512
+ }
513
+
514
+ function publicEngineeringPlan(plan){
515
+ return {
516
+ state: plan.state,
517
+ version: plan.version || "unknown",
518
+ ...(plan.previousVersion ? { previousVersion: plan.previousVersion } : {}),
519
+ ...(plan.previousBodyHash ? { previousBodyHash: plan.previousBodyHash } : {}),
520
+ ...(plan.preservedCustom ? { preservedCustom: true } : {}),
521
+ ...(plan.detail ? { detail: plan.detail } : {}),
522
+ };
523
+ }
524
+
525
+ function registeredLegacyTasks(project){
526
+ const root = path.resolve(project);
527
+ let commonDir;
528
+ try {
529
+ const raw = execFileSync("git", ["-C", root, "rev-parse", "--git-common-dir"], {
530
+ encoding: "utf8",
531
+ stdio: ["ignore", "pipe", "ignore"],
532
+ }).trim();
533
+ commonDir = path.resolve(root, raw);
534
+ } catch {
535
+ return [];
536
+ }
537
+ const tasksDir = path.join(commonDir, "auto-coding-skill", "tasks");
538
+ if (!exists(tasksDir)) return [];
539
+ const legacy = [];
540
+ for (const entry of fs.readdirSync(tasksDir, { withFileTypes: true })) {
541
+ if (!entry.isFile() || !entry.name.endsWith(".json")) continue;
542
+ const manifestPath = path.join(tasksDir, entry.name);
543
+ let manifest;
544
+ try {
545
+ manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
546
+ } catch {
547
+ legacy.push({ project: root, manifest: entry.name, schema: "invalid" });
548
+ continue;
549
+ }
550
+ const schema = Number(manifest?.schema ?? 0);
551
+ if (!Number.isFinite(schema) || schema < 2) {
552
+ legacy.push({ project: root, manifest: entry.name, schema: Number.isFinite(schema) ? schema : "invalid" });
553
+ }
554
+ }
555
+ return legacy;
556
+ }
557
+
558
+ function assertNoLegacyRegisteredTasks(projects){
559
+ const legacy = projects.flatMap(project => registeredLegacyTasks(project));
560
+ if (!legacy.length) return;
561
+ const locations = legacy.map(item => `${item.project}:${item.manifest}(schema=${item.schema})`).join(", ");
562
+ die(
563
+ "refusing the entire sync batch because registered auto-coding tasks use schema < 2: "
564
+ + `${locations}\nFinish, integrate, and clean these tasks with the currently installed 3.0.0 runtime before upgrading. `
565
+ + "sync will not infer or auto-claim owned paths for legacy tasks.",
566
+ );
567
+ }
568
+
396
569
  function readPackageVersion(){
397
570
  const here = path.dirname(fileURLToPath(import.meta.url));
398
571
  const pkgPath = path.resolve(here, "..", "..", "package.json");
@@ -408,14 +581,14 @@ function extractFrontmatter(text){
408
581
  return match ? match[1] : "";
409
582
  }
410
583
 
411
- function frontmatterHasPath(text, keyPath){
584
+ function frontmatterPathState(text, keyPath){
412
585
  const frontmatter = extractFrontmatter(text);
413
- if (!frontmatter) return false;
586
+ if (!frontmatter) return { present: false, value: "" };
414
587
 
415
588
  const stack = [];
416
589
  for (const rawLine of frontmatter.split(/\r?\n/)) {
417
590
  if (!rawLine.trim() || rawLine.trim().startsWith("#")) continue;
418
- const match = rawLine.match(/^(\s*)(["']?[^:"']+["']?)\s*:/);
591
+ const match = rawLine.match(/^(\s*)(["']?[^:"']+["']?)\s*:(.*)$/);
419
592
  if (!match) continue;
420
593
 
421
594
  const indent = match[1].replace(/\t/g, " ").length;
@@ -423,11 +596,97 @@ function frontmatterHasPath(text, keyPath){
423
596
  while (stack.length && stack[stack.length - 1].indent >= indent) stack.pop();
424
597
  const currentPath = [...stack.map(item => item.key), key];
425
598
  if (currentPath.length === keyPath.length && currentPath.every((part, index) => part === keyPath[index])) {
426
- return true;
599
+ return { present: true, value: match[3].trim() };
427
600
  }
428
601
  stack.push({ indent, key });
429
602
  }
430
- return false;
603
+ return { present: false, value: "" };
604
+ }
605
+
606
+ function frontmatterValueIsFilled(raw){
607
+ const source = String(raw || "");
608
+ let quote = "";
609
+ let escaped = false;
610
+ let commentAt = -1;
611
+ for (let index = 0; index < source.length; index += 1) {
612
+ const char = source[index];
613
+ if (quote === '"' && char === "\\" && !escaped) {
614
+ escaped = true;
615
+ continue;
616
+ }
617
+ if ((char === '"' || char === "'") && !escaped) {
618
+ quote = quote === char ? "" : (quote || char);
619
+ } else if (char === "#" && !quote && (index === 0 || /\s/.test(source[index - 1]))) {
620
+ commentAt = index;
621
+ break;
622
+ }
623
+ escaped = false;
624
+ }
625
+ const value = (commentAt >= 0 ? source.slice(0, commentAt) : source).trim();
626
+ if (!value || value.startsWith("#")) return false;
627
+ const quoted = (
628
+ (value.startsWith('"') && value.endsWith('"'))
629
+ || (value.startsWith("'") && value.endsWith("'"))
630
+ );
631
+ const unquoted = quoted ? value.slice(1, -1).trim() : value;
632
+ let semanticValue = unquoted;
633
+ if (value.startsWith('"') && value.endsWith('"')) {
634
+ try {
635
+ semanticValue = JSON.parse(value).trim();
636
+ } catch {
637
+ // Be conservative for YAML-only escape sequences that this fast parser
638
+ // cannot decode consistently with PyYAML. Single quotes remain available
639
+ // for literal backslashes.
640
+ return false;
641
+ }
642
+ } else if (value.startsWith("'") && value.endsWith("'")) {
643
+ semanticValue = unquoted.replace(/''/g, "'").trim();
644
+ }
645
+ if (!semanticValue) return false;
646
+ if (!quoted && (
647
+ /^(?:null|true|false|yes|no|on|off|~)$/i.test(semanticValue)
648
+ || /^(?:\[|\{|\||>|&|\*|!)/.test(semanticValue)
649
+ || /^[+-]?(?:0b[01_]+|0o[0-7_]+|0x[\da-f_]+|\d[\d_]*(?:\.\d*)?(?:e[+-]?\d+)?|\.\d+(?:e[+-]?\d+)?|\.inf|\.nan)$/i.test(semanticValue)
650
+ || /^\d{4}-\d{1,2}-\d{1,2}(?:[Tt ]|$)/.test(semanticValue)
651
+ || /^\d+(?::\d+)+(?:\.\d+)?$/.test(semanticValue)
652
+ )) return false;
653
+ const upper = semanticValue.toUpperCase();
654
+ return ![
655
+ "N/A", "TODO", "TBD", "CHANGEME", "CHANGE_ME", "FILL_ME", "FILL-ME",
656
+ "PLACEHOLDER", "XXX", "NULL", "~",
657
+ ].includes(upper)
658
+ && !(semanticValue.startsWith("<") && semanticValue.endsWith(">"))
659
+ && !upper.startsWith("REPLACE_")
660
+ && !upper.startsWith("YOUR_");
661
+ }
662
+
663
+ function frontmatterScalarValue(raw){
664
+ const source = String(raw || "");
665
+ let quote = "";
666
+ let escaped = false;
667
+ let commentAt = -1;
668
+ for (let index = 0; index < source.length; index += 1) {
669
+ const char = source[index];
670
+ if (quote === '"' && char === "\\" && !escaped) {
671
+ escaped = true;
672
+ continue;
673
+ }
674
+ if ((char === '"' || char === "'") && !escaped) {
675
+ quote = quote === char ? "" : (quote || char);
676
+ } else if (char === "#" && !quote && (index === 0 || /\s/.test(source[index - 1]))) {
677
+ commentAt = index;
678
+ break;
679
+ }
680
+ escaped = false;
681
+ }
682
+ const value = (commentAt >= 0 ? source.slice(0, commentAt) : source).trim();
683
+ if (value.startsWith('"') && value.endsWith('"')) {
684
+ try { return JSON.parse(value).trim(); } catch { return ""; }
685
+ }
686
+ if (value.startsWith("'") && value.endsWith("'")) {
687
+ return value.slice(1, -1).replace(/''/g, "'").trim();
688
+ }
689
+ return value;
431
690
  }
432
691
 
433
692
  function projectStatus(project, assetSkill, assetAgents){
@@ -437,21 +696,61 @@ function projectStatus(project, assetSkill, assetAgents){
437
696
  const toolDir = path.join(root, "docs", "tools", "autopipeline");
438
697
  const engineering = path.join(root, "docs", "ENGINEERING.md");
439
698
  const engineeringMissing = !exists(engineering);
699
+ const engineeringPlan = planEngineeringSync(root, assetSkill);
700
+ const managedWorkflow = publicEngineeringPlan(engineeringPlan);
440
701
  const requiredConfigPaths = [
441
702
  { label: "workflow.mode", path: ["workflow", "mode"] },
442
- { label: "project.name", path: ["project", "name"] },
443
- { label: "verification.target_env_required", path: ["verification", "target_env_required"] },
444
- { label: "verification.jenkins_required", path: ["verification", "jenkins_required"] },
703
+ { label: "workflow.profile", path: ["workflow", "profile"] },
704
+ { label: "workflow.completion", path: ["workflow", "completion"] },
705
+ { label: "concurrency.isolation", path: ["concurrency", "isolation"] },
706
+ { label: "concurrency.base_ref", path: ["concurrency", "base_ref"] },
707
+ { label: "concurrency.target_branch", path: ["concurrency", "target_branch"] },
708
+ { label: "concurrency.branch_prefix", path: ["concurrency", "branch_prefix"] },
709
+ { label: "concurrency.worktree_root", path: ["concurrency", "worktree_root"] },
710
+ { label: "concurrency.cleanup_merged", path: ["concurrency", "cleanup_merged"] },
711
+ { label: "concurrency.delete_remote_branch", path: ["concurrency", "delete_remote_branch"] },
712
+ { label: "concurrency.disposable_ignored", path: ["concurrency", "disposable_ignored"] },
713
+ { label: "project.name", path: ["project", "name"], filled: true },
714
+ { label: "access.project.frontend.url", path: ["access", "project", "frontend", "url"], filled: true },
715
+ { label: "access.project.frontend.username", path: ["access", "project", "frontend", "username"], filled: true },
716
+ { label: "access.project.frontend.password", path: ["access", "project", "frontend", "password"], filled: true },
717
+ { label: "access.project.backend.url", path: ["access", "project", "backend", "url"], filled: true },
718
+ { label: "access.project.backend.username", path: ["access", "project", "backend", "username"], filled: true },
719
+ { label: "access.project.backend.password", path: ["access", "project", "backend", "password"], filled: true },
720
+ { label: "access.jenkins.frontend.url", path: ["access", "jenkins", "frontend", "url"], filled: true },
721
+ { label: "access.jenkins.frontend.username", path: ["access", "jenkins", "frontend", "username"], filled: true },
722
+ { label: "access.jenkins.frontend.password", path: ["access", "jenkins", "frontend", "password"], filled: true },
723
+ { label: "access.jenkins.backend.url", path: ["access", "jenkins", "backend", "url"], filled: true },
724
+ { label: "access.jenkins.backend.username", path: ["access", "jenkins", "backend", "username"], filled: true },
725
+ { label: "access.jenkins.backend.password", path: ["access", "jenkins", "backend", "password"], filled: true },
726
+ { label: "access.gitlab.url", path: ["access", "gitlab", "url"], filled: true },
727
+ { label: "access.gitlab.username", path: ["access", "gitlab", "username"], filled: true },
728
+ { label: "access.gitlab.password", path: ["access", "gitlab", "password"], filled: true },
729
+ { label: "access.nexus.frontend.url", path: ["access", "nexus", "frontend", "url"], filled: true },
730
+ { label: "access.nexus.frontend.username", path: ["access", "nexus", "frontend", "username"], filled: true },
731
+ { label: "access.nexus.frontend.password", path: ["access", "nexus", "frontend", "password"], filled: true },
445
732
  { label: "docs.taskbook", path: ["docs", "taskbook"] },
446
733
  { label: "docs.closure_log", path: ["docs", "closure_log"] },
734
+ { label: "docs.active_task_dir", path: ["docs", "active_task_dir"] },
735
+ { label: "docs.task_closure_dir", path: ["docs", "task_closure_dir"] },
736
+ { label: "docs.task_evidence_dir", path: ["docs", "task_evidence_dir"] },
447
737
  ];
448
- let missingConfigTokens = requiredConfigPaths.map(item => item.label);
738
+ let missingConfigPaths = requiredConfigPaths.map(item => item.label);
739
+ let unfilledConfigTokens = [];
740
+ let invalidConfigTokens = [];
449
741
  if (!engineeringMissing) {
450
742
  const text = fs.readFileSync(engineering, "utf8");
451
- missingConfigTokens = requiredConfigPaths
452
- .filter(item => !frontmatterHasPath(text, item.path))
453
- .map(item => item.label);
743
+ const states = requiredConfigPaths.map(item => ({ item, state: frontmatterPathState(text, item.path) }));
744
+ missingConfigPaths = states.filter(({ state }) => !state.present).map(({ item }) => item.label);
745
+ unfilledConfigTokens = states
746
+ .filter(({ item, state }) => state.present && item.filled === true && !frontmatterValueIsFilled(state.value))
747
+ .map(({ item }) => item.label);
748
+ const isolationState = frontmatterPathState(text, ["concurrency", "isolation"]);
749
+ if (isolationState.present && frontmatterScalarValue(isolationState.value).toLowerCase() !== "worktree") {
750
+ invalidConfigTokens = ["concurrency.isolation (must be worktree)"];
751
+ }
454
752
  }
753
+ const missingConfigTokens = [...missingConfigPaths, ...unfilledConfigTokens, ...invalidConfigTokens];
455
754
  const scriptDiffs = [];
456
755
  const launcherSrc = path.join(assetSkill, "data", "templates", "tools", "ap.py");
457
756
  const launcherDst = path.join(toolDir, "ap.py");
@@ -469,16 +768,20 @@ function projectStatus(project, assetSkill, assetAgents){
469
768
  ? compareManagedAgents(assetAgents, agentsDir)
470
769
  : { diffs: [{ path: ".agents/agents", status: "missing" }], bindings: [] };
471
770
  const agentDiffs = agentStatus.diffs;
472
- const ok = skillDiffs.length === 0 && agentDiffs.length === 0 && scriptDiffs.length === 0 && missingDocs.length === 0 && missingConfigTokens.length === 0;
771
+ const ok = skillDiffs.length === 0 && agentDiffs.length === 0 && scriptDiffs.length === 0 && missingDocs.length === 0 && missingConfigTokens.length === 0 && managedWorkflow.state === "current";
473
772
  let next = "";
474
773
  if (!exists(skillDir) || !exists(agentsDir)) {
475
774
  next = "run autocoding init --force";
476
775
  } else if (skillDiffs.length || agentDiffs.length) {
477
776
  next = "run autocoding sync --projects <repo>";
478
- } else if (engineeringMissing || scriptDiffs.length || missingDocs.length) {
777
+ } else if (engineeringMissing || managedWorkflow.state !== "current" || scriptDiffs.length || missingDocs.length) {
479
778
  next = "run autocoding sync --projects <repo> or python3 .agents/skills/auto-coding-skill/scripts/ap.py --repo . install";
480
- } else if (missingConfigTokens.length) {
481
- next = "run project-local ap.py upgrade --write to merge docs/ENGINEERING.md safely";
779
+ } else if (missingConfigPaths.length) {
780
+ next = "run project-local ap.py upgrade --write to merge missing paths, fill every required value in docs/ENGINEERING.md, then run doctor";
781
+ } else if (invalidConfigTokens.length) {
782
+ next = "run project-local ap.py upgrade --write to migrate concurrency.isolation to worktree, then run doctor";
783
+ } else if (unfilledConfigTokens.length) {
784
+ next = "fill every required value in docs/ENGINEERING.md, then run project-local ap.py doctor";
482
785
  }
483
786
  return {
484
787
  project: root,
@@ -489,6 +792,10 @@ function projectStatus(project, assetSkill, assetAgents){
489
792
  scriptDiffs,
490
793
  missingDocs,
491
794
  missingConfigTokens,
795
+ missingConfigPaths,
796
+ unfilledConfigTokens,
797
+ invalidConfigTokens,
798
+ managedWorkflow,
492
799
  next,
493
800
  };
494
801
  }
@@ -504,44 +811,64 @@ function printProjectStatus(result){
504
811
  }
505
812
  for (const item of result.missingDocs) console.log(`[autocoding] doc missing: ${item}`);
506
813
  for (const item of result.missingConfigTokens) console.log(`[autocoding] config missing path: ${item}`);
814
+ if (result.managedWorkflow?.state !== "current") {
815
+ const detail = result.managedWorkflow?.detail ? ` - ${result.managedWorkflow.detail}` : "";
816
+ console.log(`[autocoding] engineering managed-workflow: ${result.managedWorkflow?.state || "unknown"} target=${result.managedWorkflow?.version || "unknown"}${detail}`);
817
+ }
507
818
  for (const item of result.agentBindings || []) console.log(`[autocoding] agent model: ${item.agent} -> ${item.model}`);
508
819
  if (result.next) console.log(`[autocoding] next: ${result.next}`);
509
820
  }
510
821
 
511
- function syncProject(project, assetSkill, assetAgents, dryRun, resetAgentModels = false){
822
+ function engineeringPlanDetail(plan){
823
+ if (plan.state === "legacy-custom") return `managed workflow preserved-custom -> ${plan.version}`;
824
+ if (plan.state === "legacy-official") return `managed workflow official-legacy -> ${plan.version}`;
825
+ return `managed workflow ${plan.state} -> ${plan.version}`;
826
+ }
827
+
828
+ function syncProject(project, assetSkill, assetAgents, dryRun, resetAgentModels = false, components = "all", engineeringPlan = null){
512
829
  const root = path.resolve(project);
513
830
  const actions = [];
514
831
  const skillDir = path.join(root, ".agents", "skills", "auto-coding-skill");
832
+ const skillOnly = components === "skill";
833
+ actions.push({ action: dryRun ? "would-sync" : "sync", path: path.relative(root, skillDir) });
834
+ if (!dryRun) {
835
+ rmrf(skillDir);
836
+ copyDir(assetSkill, skillDir);
837
+ }
838
+ if (skillOnly) return { project: root, dryRun, components, actions };
839
+
515
840
  const agentsDir = path.join(root, ".agents", "agents");
516
841
  const toolDir = path.join(root, "docs", "tools", "autopipeline");
517
- const engineering = path.join(root, "docs", "ENGINEERING.md");
518
- const engineeringWasMissing = !exists(engineering);
519
- const templateEngineering = path.join(assetSkill, "data", "templates", "ENGINEERING.md");
520
- actions.push({ action: dryRun ? "would-sync" : "sync", path: path.relative(root, skillDir) });
842
+ const plan = engineeringPlan || planEngineeringSync(root, assetSkill);
521
843
  actions.push({ action: dryRun ? "would-sync" : "sync", path: path.relative(root, agentsDir) });
522
844
  actions.push({ action: dryRun ? "would-sync" : "sync", path: "docs/tools/autopipeline/ap.py" });
523
845
  if (!dryRun) {
524
- rmrf(skillDir);
525
- copyDir(assetSkill, skillDir);
526
846
  syncManagedAgents(assetAgents, agentsDir, { resetModel: resetAgentModels });
527
847
  fs.mkdirSync(toolDir, { recursive: true });
528
848
  fs.copyFileSync(path.join(assetSkill, "data", "templates", "tools", "ap.py"), path.join(toolDir, "ap.py"));
529
849
  for (const copied of copyMissingDocs(assetSkill, root)) actions.push({ action: "create", path: copied });
530
- if (engineeringWasMissing) {
531
- fs.mkdirSync(path.dirname(engineering), { recursive: true });
532
- fs.writeFileSync(engineering, renderEngineeringTemplate(fs.readFileSync(templateEngineering, "utf8"), root));
533
- actions.push({ action: "create", path: path.join("docs", "ENGINEERING.md") });
850
+ if (plan.state !== "current") {
851
+ fs.mkdirSync(path.dirname(plan.engineering), { recursive: true });
852
+ fs.writeFileSync(plan.engineering, plan.output);
853
+ actions.push({
854
+ action: plan.state === "missing" ? "create" : "update",
855
+ path: path.join("docs", "ENGINEERING.md"),
856
+ detail: engineeringPlanDetail(plan),
857
+ });
534
858
  }
535
859
  } else {
536
860
  for (const rel of CORE_DOCS) {
537
861
  if (!exists(path.join(root, "docs", rel))) actions.push({ action: "would-create", path: path.join("docs", rel) });
538
862
  }
539
- if (engineeringWasMissing) actions.push({ action: "would-create", path: path.join("docs", "ENGINEERING.md") });
540
- }
541
- if (!engineeringWasMissing) {
542
- actions.push({ action: "manual", path: "docs/ENGINEERING.md", detail: "merge existing files with ap.py upgrade --write" });
863
+ if (plan.state !== "current") {
864
+ actions.push({
865
+ action: plan.state === "missing" ? "would-create" : "would-update",
866
+ path: path.join("docs", "ENGINEERING.md"),
867
+ detail: engineeringPlanDetail(plan),
868
+ });
869
+ }
543
870
  }
544
- return { project: root, dryRun, actions };
871
+ return { project: root, dryRun, components, managedWorkflow: publicEngineeringPlan(plan), actions };
545
872
  }
546
873
 
547
874
  function projectRoot(){ return process.cwd(); }
@@ -600,12 +927,13 @@ autocoding - install auto-coding-skill into generic .agents paths
600
927
  Usage:
601
928
  autocoding init [--mode project|global] [--dest <repo-root|.agents-dir|skill-dir>] [--force] [--reset-agent-models]
602
929
  autocoding status --projects <path[,path...]> [--json]
603
- autocoding sync --projects <path[,path...]> [--dry-run] [--json] [--reset-agent-models]
930
+ autocoding sync --projects <path[,path...]> [--components all|skill] [--dry-run] [--json] [--reset-agent-models]
604
931
 
605
932
  Examples:
606
933
  autocoding init
607
934
  autocoding status --projects /Users/elvis/Product/xjmate,/Users/elvis/Product/geesight
608
935
  autocoding sync --projects /Users/elvis/Product/xjmate --dry-run
936
+ autocoding sync --projects /Users/elvis/Product/geesight --components skill
609
937
 
610
938
  Compatibility:
611
939
  --ai <value> is accepted for old scripts and ignored.
@@ -617,8 +945,13 @@ Compatibility:
617
945
  validateCommandArgs(args);
618
946
 
619
947
  const here = path.dirname(fileURLToPath(import.meta.url));
620
- const assetSkill = path.resolve(here, "..", "assets", "skill");
621
- const assetAgents = path.resolve(here, "..", "assets", "agents");
948
+ const packagedAssetSkill = path.resolve(here, "..", "assets", "skill");
949
+ const packagedAssetAgents = path.resolve(here, "..", "assets", "agents");
950
+ const sourceAssetSkill = path.resolve(here, "..", "..", "src", "auto-coding-skill");
951
+ const sourceAssetAgents = path.resolve(here, "..", "..", "src", "agents");
952
+ const useSourceAssets = exists(sourceAssetSkill) && exists(sourceAssetAgents);
953
+ const assetSkill = useSourceAssets ? sourceAssetSkill : packagedAssetSkill;
954
+ const assetAgents = useSourceAssets ? sourceAssetAgents : packagedAssetAgents;
622
955
  if (!exists(assetSkill)) die(`missing assets at ${assetSkill}`);
623
956
  if (!exists(assetAgents)) die(`missing assets at ${assetAgents}`);
624
957
 
@@ -635,13 +968,37 @@ Compatibility:
635
968
 
636
969
  if (args.cmd === "sync") {
637
970
  const projects = args.projects.length ? args.projects : [projectRoot()];
638
- const results = projects.map(project => syncProject(project, assetSkill, assetAgents, args.dryRun, args.resetAgentModels));
971
+ assertNoLegacyRegisteredTasks(projects);
972
+ const engineeringPlans = new Map();
973
+ if (args.components === "all") {
974
+ for (const project of projects) {
975
+ const root = path.resolve(project);
976
+ const plan = planEngineeringSync(root, assetSkill);
977
+ if (plan.state === "invalid") {
978
+ die(`refusing to sync ${root}: ${plan.detail}`);
979
+ }
980
+ engineeringPlans.set(root, plan);
981
+ }
982
+ }
983
+ const results = projects.map(project => {
984
+ const root = path.resolve(project);
985
+ return syncProject(
986
+ root,
987
+ assetSkill,
988
+ assetAgents,
989
+ args.dryRun,
990
+ args.resetAgentModels,
991
+ args.components,
992
+ engineeringPlans.get(root) || null,
993
+ );
994
+ });
639
995
  if (args.json) console.log(JSON.stringify({ version: readPackageVersion(), results }, null, 2));
640
996
  else {
641
997
  console.log(`[autocoding] version=${readPackageVersion()}`);
642
998
  for (const result of results) {
643
999
  console.log(`[autocoding] project=${result.project}`);
644
1000
  console.log(`[autocoding] dryRun=${result.dryRun}`);
1001
+ console.log(`[autocoding] components=${result.components}`);
645
1002
  for (const item of result.actions) {
646
1003
  const detail = item.detail ? ` - ${item.detail}` : "";
647
1004
  console.log(`[autocoding] ${item.action}: ${item.path}${detail}`);
@@ -669,6 +1026,9 @@ Compatibility:
669
1026
  syncManagedAgents(assetAgents, agentsDir, { resetModel: args.resetAgentModels });
670
1027
  console.log(`[autocoding] installed agents to: ${agentsDir}`);
671
1028
 
1029
+ if (args.mode === "project") {
1030
+ console.log("[autocoding] next: run autocoding sync --projects ., fill every access.* field in docs/ENGINEERING.md, then run doctor.");
1031
+ }
672
1032
  console.log("[autocoding] done.");
673
1033
  }
674
1034