@punks/cli 4.0.4 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/dist/BASELINE_CHANGELOG.md +20 -1
  2. package/dist/CHANGELOG.md +33 -0
  3. package/dist/baseline/scaffold-baseline/baseline.json +563 -5
  4. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/authoring.d.mts +23 -0
  5. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/authoring.mjs +84 -0
  6. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/authoring.test.ts +79 -0
  7. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/lint-feedback.test.ts +60 -28
  8. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.mjs +166 -3
  9. package/dist/baseline/scaffold-baseline/data/shared-agents.md +55 -0
  10. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +12 -0
  11. package/dist/baseline/scaffold-baseline/skills/agnostic/generic/handoff/SKILL.md +18 -5
  12. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +10 -2
  13. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/plan-schema.md +28 -8
  14. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/planner-task-graph.md +7 -3
  15. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-verification-skill/SKILL.md +66 -0
  16. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-verification-skill/references/upstream.md +20 -0
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/SKILL.md +16 -41
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +14 -0
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/lifecycle.md +47 -7
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +102 -134
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +77 -67
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/parallel.md +19 -39
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/implement-spec/references/runtime-product-validation.md +27 -0
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/swarm-planner/SKILL.md +27 -2
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/update-verification-skill/SKILL.md +81 -0
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/verify-behavior/SKILL.md +105 -65
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/SKILL.md +17 -4
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/autoreview/scripts/autoreview +102 -5
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/subagents/swarm-planner/SKILL.md +27 -2
  31. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +11 -13
  32. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/backlog.md +4 -0
  33. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/closeout.md +12 -4
  34. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/debug.md +11 -5
  35. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/docs-ingest.md +4 -0
  36. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/handback.md +6 -2
  37. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/implement.md +12 -7
  38. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/plan.md +7 -1
  39. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +61 -22
  40. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +45 -91
  41. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/spec.md +4 -0
  42. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/artifact-state.md +21 -9
  43. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/context-continuity.md +109 -0
  44. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/failure-continuity.md +27 -0
  45. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +32 -20
  46. package/dist/baseline/scaffold-baseline/skills/phases/docs-ingest-phase/SKILL.md +4 -0
  47. package/dist/baseline/scaffold-baseline/skills/phases/docs-ingest-phase/references/wiki-ingest.md +4 -0
  48. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +41 -8
  49. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/retain-report.md +13 -4
  50. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/router.md +1 -1
  51. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +24 -18
  52. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/durable-report.md +40 -6
  53. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/review-packet.md +72 -0
  54. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/runtime-handoff.md +3 -0
  55. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +51 -42
  56. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/scripts/review-contract.mjs +239 -4
  57. package/dist/baseline/scaffold-baseline.json +5 -5
  58. package/dist/baseline/scaffold-baseline.tgz +0 -0
  59. package/dist/data/scripts/harness-projection/authoring.d.mts +23 -0
  60. package/dist/data/scripts/harness-projection/authoring.mjs +84 -0
  61. package/dist/data/scripts/sync-subagents.mjs +129 -3
  62. package/dist/index.js +1412 -1396
  63. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +12 -0
  64. package/dist/skills/agnostic/generic/handoff/SKILL.md +18 -5
  65. package/dist/skills/agnostic/planning/create-plan/SKILL.md +10 -2
  66. package/dist/skills/agnostic/planning/create-plan/references/plan-schema.md +28 -8
  67. package/dist/skills/agnostic/planning/create-plan/references/planner-task-graph.md +7 -3
  68. package/dist/skills/agnostic/planning/create-verification-skill/SKILL.md +66 -0
  69. package/dist/skills/agnostic/planning/create-verification-skill/references/upstream.md +20 -0
  70. package/dist/skills/agnostic/planning/implement-spec/SKILL.md +16 -41
  71. package/dist/skills/agnostic/planning/implement-spec/assets/IMPLEMENTATION-NOTES-TEMPLATE.md +14 -0
  72. package/dist/skills/agnostic/planning/implement-spec/references/architecture-conformance.md +10 -6
  73. package/dist/skills/agnostic/planning/implement-spec/references/lifecycle.md +47 -7
  74. package/dist/skills/agnostic/planning/implement-spec/references/parallel-orchestration.md +102 -134
  75. package/dist/skills/agnostic/planning/implement-spec/references/parallel-worker-brief.md +77 -67
  76. package/dist/skills/agnostic/planning/implement-spec/references/parallel.md +19 -39
  77. package/dist/skills/agnostic/planning/implement-spec/references/runtime-product-validation.md +27 -0
  78. package/dist/skills/agnostic/planning/swarm-planner/SKILL.md +27 -2
  79. package/dist/skills/agnostic/planning/update-verification-skill/SKILL.md +81 -0
  80. package/dist/skills/agnostic/planning/verify-behavior/SKILL.md +105 -65
  81. package/dist/skills/agnostic/quality/autoreview/SKILL.md +17 -4
  82. package/dist/skills/agnostic/quality/autoreview/scripts/autoreview +102 -5
  83. package/dist/skills/agnostic/subagents/swarm-planner/SKILL.md +27 -2
  84. package/dist/skills/phases/delivery-phase/SKILL.md +11 -13
  85. package/dist/skills/phases/delivery-phase/phases/backlog.md +4 -0
  86. package/dist/skills/phases/delivery-phase/phases/closeout.md +12 -4
  87. package/dist/skills/phases/delivery-phase/phases/debug.md +11 -5
  88. package/dist/skills/phases/delivery-phase/phases/docs-ingest.md +4 -0
  89. package/dist/skills/phases/delivery-phase/phases/handback.md +6 -2
  90. package/dist/skills/phases/delivery-phase/phases/implement.md +12 -7
  91. package/dist/skills/phases/delivery-phase/phases/plan.md +7 -1
  92. package/dist/skills/phases/delivery-phase/phases/review.md +61 -22
  93. package/dist/skills/phases/delivery-phase/phases/router.md +45 -91
  94. package/dist/skills/phases/delivery-phase/phases/spec.md +4 -0
  95. package/dist/skills/phases/delivery-phase/references/artifact-state.md +21 -9
  96. package/dist/skills/phases/delivery-phase/references/context-continuity.md +109 -0
  97. package/dist/skills/phases/delivery-phase/references/failure-continuity.md +27 -0
  98. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +32 -20
  99. package/dist/skills/phases/docs-ingest-phase/SKILL.md +4 -0
  100. package/dist/skills/phases/docs-ingest-phase/references/wiki-ingest.md +4 -0
  101. package/dist/skills/phases/review-phase/phases/prepare-review.md +40 -8
  102. package/dist/skills/phases/review-phase/phases/retain-report.md +13 -4
  103. package/dist/skills/phases/review-phase/phases/router.md +1 -1
  104. package/dist/skills/phases/review-phase/phases/run-review.md +24 -18
  105. package/dist/skills/phases/review-phase/references/durable-report.md +40 -6
  106. package/dist/skills/phases/review-phase/references/review-packet.md +72 -0
  107. package/dist/skills/phases/review-phase/references/runtime-handoff.md +3 -0
  108. package/dist/skills/phases/review-phase/references/state-graph.md +21 -12
  109. package/dist/skills/phases/review-phase/scripts/review-contract.mjs +137 -4
  110. package/package.json +4 -1
@@ -12,6 +12,7 @@ import { cursorAdapter } from "./harness-projection/adapters/cursor.mjs";
12
12
  import { openCodeAdapter } from "./harness-projection/adapters/opencode.mjs";
13
13
  import { applyProjection } from "./harness-projection/apply.mjs";
14
14
  import { project } from "./harness-projection/core.mjs";
15
+ import { assessScopedAuthoring, readScopedAuthoringProofs } from "./harness-projection/authoring.mjs";
15
16
 
16
17
  const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
17
18
  const sharedAgentsPath = path.join(repoRoot, ".agents/AGENTS.md");
@@ -2941,9 +2942,31 @@ const contributionIssue = (contribution) => {
2941
2942
  };
2942
2943
 
2943
2944
  const scopeIssue = (scope) => {
2944
- if (!exactKeys(scope, ["id", "packs", "contributions"]) || !isNonEmptyString(scope.id)) {
2945
+ const expectedKeys = scope?.authoring === undefined
2946
+ ? ["id", "packs", "contributions"]
2947
+ : ["id", "packs", "contributions", "authoring"];
2948
+ if (!exactKeys(scope, expectedKeys) || !isNonEmptyString(scope.id)) {
2945
2949
  return "Context scope fields are invalid";
2946
2950
  }
2951
+ if (scope.authoring !== undefined) {
2952
+ const identity = scope.authoring;
2953
+ if (
2954
+ !exactKeys(identity, ["path", "kind", "contracts", "missingContracts"]) ||
2955
+ !isNonEmptyString(identity.path) ||
2956
+ !isNonEmptyString(identity.kind) ||
2957
+ !Array.isArray(identity.contracts) ||
2958
+ !identity.contracts.every((contract) =>
2959
+ exactKeys(contract, ["id", "authoringRevision", "activationRevision"]) &&
2960
+ isNonEmptyString(contract.id) &&
2961
+ isNonEmptyString(contract.authoringRevision) &&
2962
+ isNonEmptyString(contract.activationRevision)
2963
+ ) ||
2964
+ !Array.isArray(identity.missingContracts) ||
2965
+ !identity.missingContracts.every(isNonEmptyString)
2966
+ ) {
2967
+ return `Context scope ${scope.id} authoring identity is invalid`;
2968
+ }
2969
+ }
2947
2970
  if (
2948
2971
  !Array.isArray(scope.packs) ||
2949
2972
  !scope.packs.every(
@@ -3018,13 +3041,68 @@ const contextPlanVersion = (contextPlan) =>
3018
3041
  ? contextPlan.version
3019
3042
  : "unknown";
3020
3043
 
3021
- async function main({ publicationLock } = {}) {
3044
+ const parseAuthoringCompletion = (args) => {
3045
+ if (args.length === 0) return undefined;
3046
+ if (args.length !== 3 || args[0] !== "--complete-authoring" || !/^[a-f0-9]{64}$/.test(args[2])) {
3047
+ throw new Error("Expected --complete-authoring <scope> <current input identity>.");
3048
+ }
3049
+ return { scopeId: args[1], inputIdentity: args[2] };
3050
+ };
3051
+
3052
+ async function readAuthoredScope(action) {
3053
+ const promptFile = action.allowedOutputs[0];
3054
+ const bytes = await readConfinedRegularFile(resolveActionPath(promptFile, "authored output"));
3055
+ if (bytes === null || bytes.toString("utf8").trim().length === 0) {
3056
+ throw new Error(`Authored output is missing or empty: ${promptFile}`);
3057
+ }
3058
+ return bytes;
3059
+ }
3060
+
3061
+ async function verifyAuthoredProjection(action, projections, application) {
3062
+ await readAuthoredScope(action);
3063
+ for (const projection of projections) {
3064
+ const relevant = (entry) => entry.trace?.scopeId === action.scopeId &&
3065
+ ["scoped-prompt", "subagent-template"].includes(entry.trace?.kind);
3066
+ if ([...projection.failures, ...projection.omissions].some(relevant)) {
3067
+ throw new Error(`Scoped authoring projection is incomplete: ${action.scopeId}`);
3068
+ }
3069
+ for (const mirror of projection.actions.filter((entry) => relevant(entry) && entry.operation === "mirror" && entry.source !== entry.target)) {
3070
+ const sourcePath = resolveActionPath(mirror.source, "source");
3071
+ const targetPath = resolveActionPath(mirror.target, "target");
3072
+ const stat = await lstat(targetPath);
3073
+ if (stat.isSymbolicLink()) {
3074
+ if ((await readlink(targetPath)) !== path.relative(path.dirname(targetPath), sourcePath)) {
3075
+ throw new Error(`Scoped authoring mirror diverges: ${mirror.target}`);
3076
+ }
3077
+ } else {
3078
+ const source = await readConfinedRegularFile(sourcePath);
3079
+ const target = await readConfinedRegularFile(targetPath);
3080
+ if (source === null || target === null || !source.equals(target)) {
3081
+ throw new Error(`Scoped authoring mirror diverges: ${mirror.target}`);
3082
+ }
3083
+ }
3084
+ }
3085
+ }
3086
+ for (const agentId of action.allowedAgentIds) {
3087
+ for (const [adapterId, surface] of Object.entries(harnessAgentSurface)) {
3088
+ const expected = application.rendered[adapterId]?.[agentId];
3089
+ const actual = await readConfinedRegularFile(path.join(surface.directory, `${agentId}.${surface.extension}`));
3090
+ if (typeof expected !== "string" || actual?.toString("utf8") !== expected) {
3091
+ throw new Error(`Scoped authoring native agent diverges: ${adapterId}:${agentId}`);
3092
+ }
3093
+ }
3094
+ }
3095
+ }
3096
+
3097
+ async function main({ publicationLock, authoringCompletion } = {}) {
3022
3098
  operationRepoRootIdentity = await captureRepoRootIdentity("synchronize scaffold output");
3023
3099
  const manifestPreflight = await preflightScaffoldManifest();
3024
3100
  await assertConfinedRegularFile(projectionReceiptPath);
3025
3101
  const previousReceiptBytes = await readConfinedRegularFile(projectionReceiptPath);
3102
+ let previousAuthoringProofs = [];
3026
3103
  try {
3027
3104
  const previousReceipt = JSON.parse(previousReceiptBytes?.toString("utf8") ?? "null");
3105
+ previousAuthoringProofs = readScopedAuthoringProofs(previousReceipt);
3028
3106
  previousCopyFallbacks = Array.isArray(previousReceipt.copyFallbacks)
3029
3107
  ? previousReceipt.copyFallbacks.filter(
3030
3108
  (copy) =>
@@ -3039,6 +3117,8 @@ async function main({ publicationLock } = {}) {
3039
3117
  }
3040
3118
  const loadedContextPlan = await readContextPlan();
3041
3119
  const loadedProjectionPlan = await readProjectionPlan();
3120
+ const authoringManifestPath = path.join(repoRoot, ".agents/subagents/manifest.mjs");
3121
+ const authoringManifestBytes = await readConfinedRegularFile(authoringManifestPath);
3042
3122
  const application = await prepareHarnessApplication();
3043
3123
  const renderedOutputSha256 = semanticJsonHash({
3044
3124
  availableHooks: application.availableHooks,
@@ -3048,10 +3128,27 @@ async function main({ publicationLock } = {}) {
3048
3128
  try {
3049
3129
  await assertScaffoldManifestPreflight(manifestPreflight);
3050
3130
  if (!loadedContextPlan.exists && !loadedProjectionPlan.exists) {
3131
+ if (authoringCompletion !== undefined) {
3132
+ throw new Error("Scoped authoring completion requires a canonical context plan.");
3133
+ }
3051
3134
  await materializeLegacyHarnesses(application);
3052
3135
  return;
3053
3136
  }
3054
3137
  const contextPlan = loadedContextPlan.value;
3138
+ const authoringActions = contextPlanIssue(contextPlan) === undefined
3139
+ ? assessScopedAuthoring({ contextPlan, proofs: [] })
3140
+ : [];
3141
+ const completionAction = authoringCompletion === undefined ? undefined : authoringActions.find(
3142
+ (action) => action.scopeId === authoringCompletion.scopeId && action.inputIdentity === authoringCompletion.inputIdentity,
3143
+ );
3144
+ if (authoringCompletion !== undefined) {
3145
+ if (completionAction === undefined || completionAction.trigger === "compatibility-unknown") {
3146
+ throw new Error("Scoped authoring completion does not match a supported current input.");
3147
+ }
3148
+ const issue = canonicalContextIssue(contextPlan);
3149
+ if (issue !== undefined) throw new Error(issue);
3150
+ await readAuthoredScope(completionAction);
3151
+ }
3055
3152
  const suppliedProjectionPlan = loadedProjectionPlan.exists
3056
3153
  ? validateProjectionPlan({ plan: loadedProjectionPlan.value, contextPlan })
3057
3154
  : undefined;
@@ -3099,12 +3196,41 @@ async function main({ publicationLock } = {}) {
3099
3196
  );
3100
3197
  }
3101
3198
 
3199
+ const scopedAuthoring = previousAuthoringProofs.filter((proof) =>
3200
+ !authoringActions.some((action) => action.scopeId === proof.scopeId &&
3201
+ (action === completionAction || action.inputIdentity === proof.inputIdentity)),
3202
+ );
3203
+ for (const action of authoringActions) {
3204
+ if (action.trigger === "compatibility-unknown") continue;
3205
+ const prior = previousAuthoringProofs.find((proof) => proof.scopeId === action.scopeId && proof.inputIdentity === action.inputIdentity);
3206
+ if (action !== completionAction && prior === undefined) continue;
3207
+ try {
3208
+ await verifyAuthoredProjection(action, applied, application);
3209
+ scopedAuthoring.push({ scopeId: action.scopeId, inputIdentity: action.inputIdentity, status: "verified" });
3210
+ } catch (error) {
3211
+ if (action === completionAction) throw error;
3212
+ }
3213
+ }
3214
+ if (scopedAuthoring.length > 0) {
3215
+ const currentApplication = await prepareHarnessApplication();
3216
+ const currentManifest = await readConfinedRegularFile(authoringManifestPath);
3217
+ if (authoringManifestBytes === null || currentManifest === null ||
3218
+ !authoringManifestBytes.equals(currentManifest) ||
3219
+ semanticJsonHash({ availableHooks: currentApplication.availableHooks, rendered: currentApplication.rendered }) !== renderedOutputSha256) {
3220
+ throw new Error("Scoped authoring inputs changed during projection; retry completion.");
3221
+ }
3222
+ }
3223
+ const currentContext = await readContextPlan();
3224
+ if (!currentContext.exists || semanticJsonHash(currentContext.value) !== semanticJsonHash(contextPlan)) {
3225
+ throw new Error("Scoped authoring inputs changed during projection; retry completion.");
3226
+ }
3102
3227
  const receipt = {
3103
3228
  version: "1",
3104
3229
  contextPlanVersion: contextPlanVersion(contextPlan),
3105
3230
  renderedOutputSha256,
3106
3231
  status: receiptStatus(applied),
3107
3232
  projections: applied,
3233
+ scopedAuthoring: scopedAuthoring.toSorted((left, right) => left.scopeId.localeCompare(right.scopeId)),
3108
3234
  copyFallbacks: [...currentCopyFallbacks.values()].toSorted((left, right) =>
3109
3235
  copyFallbackKey(left).localeCompare(copyFallbackKey(right)),
3110
3236
  ),
@@ -3126,7 +3252,7 @@ const modulePath = await realpath(fileURLToPath(import.meta.url));
3126
3252
 
3127
3253
  if (entrypointPath === modulePath) {
3128
3254
  try {
3129
- await main();
3255
+ await main({ authoringCompletion: parseAuthoringCompletion(process.argv.slice(2)) });
3130
3256
  } finally {
3131
3257
  await closeMutationWorkers();
3132
3258
  }