@aviaratech/ai-delivery 0.3.35 → 0.3.37
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/CONTRIBUTING.md +12 -206
- package/README.md +56 -554
- package/dist/agent.d.ts +1 -3
- package/dist/agent.js +74 -16
- package/dist/agent.js.map +7 -1
- package/dist/agentReadiness.test.js +73 -67
- package/dist/agentReadiness.test.js.map +7 -1
- package/dist/boardReconcile.test.js +1651 -1590
- package/dist/boardReconcile.test.js.map +7 -1
- package/dist/build.test.js +130 -0
- package/dist/build.test.js.map +7 -0
- package/dist/callerErrors.test.js +91 -0
- package/dist/callerErrors.test.js.map +7 -0
- package/dist/cli.js +389 -517
- package/dist/cli.js.map +7 -1
- package/dist/cliResult.d.ts +2 -2
- package/dist/cliResult.js +42 -45
- package/dist/cliResult.js.map +7 -1
- package/dist/cliResult.test.js +424 -369
- package/dist/cliResult.test.js.map +7 -1
- package/dist/config/deliveryConfig.d.ts +288 -14
- package/dist/config/deliveryConfig.js +472 -390
- package/dist/config/deliveryConfig.js.map +7 -1
- package/dist/config/deliveryConfig.test.js +773 -649
- package/dist/config/deliveryConfig.test.js.map +7 -1
- package/dist/contributorChecks.test.js +1694 -916
- package/dist/contributorChecks.test.js.map +7 -1
- package/dist/currentConsumer.test.js +819 -737
- package/dist/currentConsumer.test.js.map +7 -1
- package/dist/currentTrackingScenario.test.js +499 -479
- package/dist/currentTrackingScenario.test.js.map +7 -1
- package/dist/delivery/common.js +160 -172
- package/dist/delivery/common.js.map +7 -1
- package/dist/delivery/delivery.test.js +509 -431
- package/dist/delivery/delivery.test.js.map +7 -1
- package/dist/delivery/evidence.d.ts +2 -2
- package/dist/delivery/evidence.js +133 -120
- package/dist/delivery/evidence.js.map +7 -1
- package/dist/delivery/index.js +7 -2
- package/dist/delivery/index.js.map +7 -1
- package/dist/delivery/legacy.js +65 -5
- package/dist/delivery/legacy.js.map +7 -1
- package/dist/delivery/policy.d.ts +10 -10
- package/dist/delivery/policy.js +211 -238
- package/dist/delivery/policy.js.map +7 -1
- package/dist/delivery/stage.d.ts +18 -18
- package/dist/delivery/stage.js +220 -235
- package/dist/delivery/stage.js.map +7 -1
- package/dist/deliveryBoard.d.ts +74 -0
- package/dist/deliveryBoard.js +644 -0
- package/dist/deliveryBoard.js.map +7 -0
- package/dist/deliveryBoard.test.js +649 -0
- package/dist/deliveryBoard.test.js.map +7 -0
- package/dist/deliveryHealth.test.js +179 -155
- package/dist/deliveryHealth.test.js.map +7 -1
- package/dist/dependencyCompatibility.test.js +154 -140
- package/dist/dependencyCompatibility.test.js.map +7 -1
- package/dist/directoryIndependent.test.js +417 -383
- package/dist/directoryIndependent.test.js.map +7 -1
- package/dist/dispatch.d.ts +16 -11
- package/dist/dispatch.js +316 -354
- package/dist/dispatch.js.map +7 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.js +103 -96
- package/dist/errors.js.map +7 -1
- package/dist/fixtures/deliveryBoardReplay.d.ts +56 -0
- package/dist/fixtures/deliveryBoardReplay.js +617 -0
- package/dist/fixtures/deliveryBoardReplay.js.map +7 -0
- package/dist/fixtures/discovery.d.ts +63 -23
- package/dist/fixtures/discovery.js +96 -90
- package/dist/fixtures/discovery.js.map +7 -1
- package/dist/fixtures/inertEntrypointChild.js +57 -56
- package/dist/fixtures/inertEntrypointChild.js.map +7 -1
- package/dist/fixtures/inertEntrypoints.d.ts +1 -1
- package/dist/fixtures/inertEntrypoints.js +321 -276
- package/dist/fixtures/inertEntrypoints.js.map +7 -1
- package/dist/fixtures/inertTarget.d.ts +78 -7
- package/dist/fixtures/inertTarget.js +769 -691
- package/dist/fixtures/inertTarget.js.map +7 -1
- package/dist/fixtures/issue63.d.ts +4 -3
- package/dist/fixtures/issue63.js +260 -274
- package/dist/fixtures/issue63.js.map +7 -1
- package/dist/fixtures/issueProjectItems.d.ts +20 -0
- package/dist/fixtures/issueProjectItems.js +15 -0
- package/dist/fixtures/issueProjectItems.js.map +7 -0
- package/dist/fixtures/readView.d.ts +120 -0
- package/dist/fixtures/readView.js +172 -0
- package/dist/fixtures/readView.js.map +7 -0
- package/dist/fixtures/recordedGitHubFlows.d.ts +120 -0
- package/dist/fixtures/recordedGitHubFlows.js +109 -0
- package/dist/fixtures/recordedGitHubFlows.js.map +7 -0
- package/dist/genericCompatibility.test.js +64 -55
- package/dist/genericCompatibility.test.js.map +7 -1
- package/dist/git.d.ts +0 -3
- package/dist/git.js +59 -76
- package/dist/git.js.map +7 -1
- package/dist/gitProcess.d.ts +1 -1
- package/dist/gitProcess.js +58 -53
- package/dist/gitProcess.js.map +7 -1
- package/dist/github/client.d.ts +2 -2
- package/dist/github/client.js +484 -379
- package/dist/github/client.js.map +7 -1
- package/dist/github/commandIdentityPolicy.js +42 -52
- package/dist/github/commandIdentityPolicy.js.map +7 -1
- package/dist/github/discovery.d.ts +1 -0
- package/dist/github/discovery.js +197 -215
- package/dist/github/discovery.js.map +7 -1
- package/dist/github/discovery.test.js +223 -177
- package/dist/github/discovery.test.js.map +7 -1
- package/dist/github/issueHistory.d.ts +2 -2
- package/dist/github/issueHistory.js +117 -125
- package/dist/github/issueHistory.js.map +7 -1
- package/dist/github/machineAuth.d.ts +1 -1
- package/dist/github/machineAuth.js +126 -117
- package/dist/github/machineAuth.js.map +7 -1
- package/dist/github/machineAuth.test.js +755 -639
- package/dist/github/machineAuth.test.js.map +7 -1
- package/dist/github/nativeIssueMetadata.js +286 -273
- package/dist/github/nativeIssueMetadata.js.map +7 -1
- package/dist/github/projectDelivery.d.ts +18 -2
- package/dist/github/projectDelivery.js +615 -557
- package/dist/github/projectDelivery.js.map +7 -1
- package/dist/github/relationships.js +433 -389
- package/dist/github/relationships.js.map +7 -1
- package/dist/github/repo.d.ts +1 -0
- package/dist/github/repo.js +123 -96
- package/dist/github/repo.js.map +7 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +7 -1
- package/dist/issue.d.ts +40 -9
- package/dist/issue.js +2102 -1742
- package/dist/issue.js.map +7 -1
- package/dist/issue63History.test.js +40 -42
- package/dist/issue63History.test.js.map +7 -1
- package/dist/issue63Routes.test.js +154 -143
- package/dist/issue63Routes.test.js.map +7 -1
- package/dist/issueBatchUpdate.test.js +989 -885
- package/dist/issueBatchUpdate.test.js.map +7 -1
- package/dist/issueBlockerGuard.test.js +262 -226
- package/dist/issueBlockerGuard.test.js.map +7 -1
- package/dist/issueContract.d.ts +23 -4
- package/dist/issueContract.js +416 -395
- package/dist/issueContract.js.map +7 -1
- package/dist/issueContract.test.d.ts +4 -3
- package/dist/issueContract.test.js +358 -321
- package/dist/issueContract.test.js.map +7 -1
- package/dist/issueDates.test.js +235 -233
- package/dist/issueDates.test.js.map +7 -1
- package/dist/issueInfoReadback.test.js +304 -190
- package/dist/issueInfoReadback.test.js.map +7 -1
- package/dist/issueIntake.test.js +1938 -1732
- package/dist/issueIntake.test.js.map +7 -1
- package/dist/issueJournal.d.ts +40 -19
- package/dist/issueJournal.js +229 -138
- package/dist/issueJournal.js.map +7 -1
- package/dist/issueJournal.test.js +605 -422
- package/dist/issueJournal.test.js.map +7 -1
- package/dist/issueRollup.test.d.ts +1 -0
- package/dist/issueRollup.test.js +476 -0
- package/dist/issueRollup.test.js.map +7 -0
- package/dist/issueTracking.test.js +1059 -989
- package/dist/issueTracking.test.js.map +7 -1
- package/dist/issueWriteRecovery.test.d.ts +1 -0
- package/dist/issueWriteRecovery.test.js +260 -0
- package/dist/issueWriteRecovery.test.js.map +7 -0
- package/dist/lifecycle.test.js +112 -441
- package/dist/lifecycle.test.js.map +7 -1
- package/dist/logger.js +80 -74
- package/dist/logger.js.map +7 -1
- package/dist/mcp/index.js +116 -94
- package/dist/mcp/index.js.map +7 -1
- package/dist/mcp/tools.d.ts +252 -310
- package/dist/mcp/tools.js +235 -342
- package/dist/mcp/tools.js.map +7 -1
- package/dist/pluginAuthProbe.js +63 -52
- package/dist/pluginAuthProbe.js.map +7 -1
- package/dist/pluginAuthProbe.test.js +85 -62
- package/dist/pluginAuthProbe.test.js.map +7 -1
- package/dist/pluginCredentials.test.js +282 -259
- package/dist/pluginCredentials.test.js.map +7 -1
- package/dist/pluginDoctor.test.js +653 -588
- package/dist/pluginDoctor.test.js.map +7 -1
- package/dist/pluginInstaller.d.ts +7 -5
- package/dist/pluginInstaller.js +1173 -1229
- package/dist/pluginInstaller.js.map +7 -1
- package/dist/pluginInstaller.test.js +1842 -1423
- package/dist/pluginInstaller.test.js.map +7 -1
- package/dist/pluginPackaging.test.js +417 -413
- package/dist/pluginPackaging.test.js.map +7 -1
- package/dist/pr.d.ts +114 -131
- package/dist/pr.js +1314 -1327
- package/dist/pr.js.map +7 -1
- package/dist/pr.test.js +967 -653
- package/dist/pr.test.js.map +7 -1
- package/dist/prAssociation.test.js +2419 -1788
- package/dist/prAssociation.test.js.map +7 -1
- package/dist/prDispatch.test.js +123 -89
- package/dist/prDispatch.test.js.map +7 -1
- package/dist/readView.d.ts +184 -0
- package/dist/readView.js +218 -0
- package/dist/readView.js.map +7 -0
- package/dist/readView.test.d.ts +1 -0
- package/dist/readView.test.js +146 -0
- package/dist/readView.test.js.map +7 -0
- package/dist/releaseReconciliation.test.js +267 -288
- package/dist/releaseReconciliation.test.js.map +7 -1
- package/dist/releaseWorkflow.test.js +2493 -422
- package/dist/releaseWorkflow.test.js.map +7 -1
- package/dist/review.d.ts +738 -2
- package/dist/review.js +601 -348
- package/dist/review.js.map +7 -1
- package/dist/review.test.js +1218 -812
- package/dist/review.test.js.map +7 -1
- package/dist/reviewSubmit.test.d.ts +1 -0
- package/dist/reviewSubmit.test.js +747 -0
- package/dist/reviewSubmit.test.js.map +7 -0
- package/dist/services/agentReadinessService.js +42 -37
- package/dist/services/agentReadinessService.js.map +7 -1
- package/dist/services/blockerGuardService.js +188 -188
- package/dist/services/blockerGuardService.js.map +7 -1
- package/dist/services/boardReconcileService.d.ts +125 -125
- package/dist/services/boardReconcileService.js +1295 -1421
- package/dist/services/boardReconcileService.js.map +7 -1
- package/dist/services/deliveryHealthService.js +197 -199
- package/dist/services/deliveryHealthService.js.map +7 -1
- package/dist/services/legacyIssueMigration.js +263 -277
- package/dist/services/legacyIssueMigration.js.map +7 -1
- package/dist/stagedChecks.test.js +396 -194
- package/dist/stagedChecks.test.js.map +7 -1
- package/dist/start.test.js +99 -95
- package/dist/start.test.js.map +7 -1
- package/dist/stdoutRegression.test.js +321 -358
- package/dist/stdoutRegression.test.js.map +7 -1
- package/dist/targetPolicyDiscovery.test.js +141 -143
- package/dist/targetPolicyDiscovery.test.js.map +7 -1
- package/dist/targetPolicyEntrypoints.test.js +308 -269
- package/dist/targetPolicyEntrypoints.test.js.map +7 -1
- package/dist/targetPolicyLocal.test.js +580 -1051
- package/dist/targetPolicyLocal.test.js.map +7 -1
- package/dist/targetPolicyRoutes.test.js +274 -281
- package/dist/targetPolicyRoutes.test.js.map +7 -1
- package/dist/targetRepositoryExecution.test.d.ts +1 -0
- package/dist/targetRepositoryExecution.test.js +451 -0
- package/dist/targetRepositoryExecution.test.js.map +7 -0
- package/dist/terminalMessages.js +41 -35
- package/dist/terminalMessages.js.map +7 -1
- package/dist/toolOutput.d.ts +2 -0
- package/dist/toolOutput.js +36 -0
- package/dist/toolOutput.js.map +7 -0
- package/dist/toolOutput.test.d.ts +1 -0
- package/dist/toolOutput.test.js +240 -0
- package/dist/toolOutput.test.js.map +7 -0
- package/dist/utils/atomicJson.d.ts +0 -2
- package/dist/utils/atomicJson.js +81 -77
- package/dist/utils/atomicJson.js.map +7 -1
- package/dist/utils/filesystem.d.ts +0 -8
- package/dist/utils/filesystem.js +5 -19
- package/dist/utils/filesystem.js.map +7 -1
- package/dist/utils/lockfile.js +68 -71
- package/dist/utils/lockfile.js.map +7 -1
- package/dist/verification.d.ts +1 -54
- package/dist/verification.js +976 -1941
- package/dist/verification.js.map +7 -1
- package/dist/verificationGate.test.js +127 -117
- package/dist/verificationGate.test.js.map +7 -1
- package/dist/version.js +45 -24
- package/dist/version.js.map +7 -1
- package/package.json +9 -8
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +47 -156
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +238 -44
- package/plugins/ai-delivery/runtime/dist/cli.js +351 -115
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +14 -78
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +35 -36
- package/plugins/ai-delivery/skills/worktree-lifecycle/SKILL.md +14 -15
- package/dist/investigationCompletion.test.js +0 -728
- package/dist/investigationCompletion.test.js.map +0 -1
- package/dist/services/deliveryAdmission.d.ts +0 -49
- package/dist/services/deliveryAdmission.js +0 -165
- package/dist/services/deliveryAdmission.js.map +0 -1
- package/dist/services/worktreeRegistry.d.ts +0 -434
- package/dist/services/worktreeRegistry.js +0 -1248
- package/dist/services/worktreeRegistry.js.map +0 -1
- package/dist/setup.d.ts +0 -60
- package/dist/setup.js +0 -585
- package/dist/setup.js.map +0 -1
- package/dist/setup.test.js +0 -3329
- package/dist/setup.test.js.map +0 -1
- package/dist/worktree.d.ts +0 -28
- package/dist/worktree.js +0 -188
- package/dist/worktree.js.map +0 -1
- package/dist/worktreeTransition.d.ts +0 -211
- package/dist/worktreeTransition.js +0 -1037
- package/dist/worktreeTransition.js.map +0 -1
- package/dist/worktreeTransition.test.js +0 -1191
- package/dist/worktreeTransition.test.js.map +0 -1
- /package/dist/{investigationCompletion.test.d.ts → build.test.d.ts} +0 -0
- /package/dist/{setup.test.d.ts → callerErrors.test.d.ts} +0 -0
- /package/dist/{worktreeTransition.test.d.ts → deliveryBoard.test.d.ts} +0 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/toolOutput.ts"],
|
|
4
|
+
"sourcesContent": ["import { renderDeliveryBoard, type DeliveryBoardResult } from './deliveryBoard.js';\n\n/** Project transport output only; stored content and internal readbacks stay complete. */\nexport function projectToolOutput(command: string, value: unknown, verbose = false): unknown {\n if (command === 'delivery_board' && !verbose) return renderDeliveryBoard(value as DeliveryBoardResult);\n if (verbose || !command.startsWith('issue_')) return value;\n return compact(value);\n}\n\nfunction compact(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(compact);\n if (typeof value !== 'object' || value === null) return value;\n return Object.fromEntries(\n Object.entries(value).flatMap(([key, item]) => {\n // relatedReadback repeats readback plus the verified changes (#240: 10 closes returned 195 KB).\n if (['body', 'routing', 'conversion', 'bodyTransition', 'relatedReadback'].includes(key)) return [];\n // Recovery inputs and diagnostics are actionable data, never presentation copies.\n if (['recovery', 'safeResume', 'warnings', 'failures', 'fields'].includes(key)) return [[key, item]];\n if (key === 'reviewRoute' && typeof item === 'object' && item !== null) {\n const route = item as Record<string, unknown>;\n return [\n [\n key,\n Object.fromEntries(\n Object.entries(route).map(([field, detail]) => {\n if (\n (field === 'author' || field === 'reviewer') &&\n typeof detail === 'object' &&\n detail !== null &&\n 'actorLogin' in detail\n )\n return [field, { actorLogin: detail.actorLogin }];\n return [field, detail];\n }),\n ),\n ],\n ];\n }\n return [[key, compact(item)]];\n }),\n );\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAAqD;AAGvD,SAAS,kBAAkB,SAAiB,OAAgB,UAAU,OAAgB;AAC3F,MAAI,YAAY,oBAAoB,CAAC,QAAS,QAAO,oBAAoB,KAA4B;AACrG,MAAI,WAAW,CAAC,QAAQ,WAAW,QAAQ,EAAG,QAAO;AACrD,SAAO,QAAQ,KAAK;AACtB;AAEA,SAAS,QAAQ,OAAyB;AACxC,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO,MAAM,IAAI,OAAO;AAClD,MAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AACxD,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAK,IAAI,MAAM;AAE7C,UAAI,CAAC,QAAQ,WAAW,cAAc,kBAAkB,iBAAiB,EAAE,SAAS,GAAG,EAAG,QAAO,CAAC;AAElG,UAAI,CAAC,YAAY,cAAc,YAAY,YAAY,QAAQ,EAAE,SAAS,GAAG,EAAG,QAAO,CAAC,CAAC,KAAK,IAAI,CAAC;AACnG,UAAI,QAAQ,iBAAiB,OAAO,SAAS,YAAY,SAAS,MAAM;AACtE,cAAM,QAAQ;AACd,eAAO;AAAA,UACL;AAAA,YACE;AAAA,YACA,OAAO;AAAA,cACL,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,OAAO,MAAM,MAAM;AAC7C,qBACG,UAAU,YAAY,UAAU,eACjC,OAAO,WAAW,YAClB,WAAW,QACX,gBAAgB;AAEhB,yBAAO,CAAC,OAAO,EAAE,YAAY,OAAO,WAAW,CAAC;AAClD,uBAAO,CAAC,OAAO,MAAM;AAAA,cACvB,CAAC;AAAA,YACH;AAAA,UACF;AAAA,QACF;AAAA,MACF;AACA,aAAO,CAAC,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC;AAAA,IAC9B,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { pathToFileURL } from "node:url";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
5
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
6
|
+
import { afterEach, expect, test, vi } from "vitest";
|
|
7
|
+
import * as dispatch from "./dispatch.js";
|
|
8
|
+
import { createAiDeliveryMcpServer } from "./mcp/index.js";
|
|
9
|
+
import { IssueValidationError } from "./issueContract.js";
|
|
10
|
+
import { projectToolOutput } from "./toolOutput.js";
|
|
11
|
+
import { getAiDeliveryMcpTool } from "./mcp/tools.js";
|
|
12
|
+
const issue = {
|
|
13
|
+
issueNumber: 17,
|
|
14
|
+
url: "https://github.com/example/widget/issues/17",
|
|
15
|
+
title: "Synthetic delivery change",
|
|
16
|
+
state: "open",
|
|
17
|
+
projectStatus: "Todo",
|
|
18
|
+
issueType: "Feature",
|
|
19
|
+
points: 3,
|
|
20
|
+
priority: "P1",
|
|
21
|
+
fields: { startDate: null },
|
|
22
|
+
blockedBy: [12],
|
|
23
|
+
parentIssueNumber: 1,
|
|
24
|
+
body: "Synthetic issue body. ".repeat(140).padEnd(3e3, ".") + "\n" + Array.from({ length: 5 }, (_, i) => `- [ ] Criterion ${i + 1}`).join("\n"),
|
|
25
|
+
routing: { repository: "example/widget", statusFieldId: "synthetic-status" }
|
|
26
|
+
};
|
|
27
|
+
const warning = {
|
|
28
|
+
code: "body.length",
|
|
29
|
+
field: "body",
|
|
30
|
+
message: "Consider a smaller body.",
|
|
31
|
+
fixHint: "Shorten the body."
|
|
32
|
+
};
|
|
33
|
+
const results = {
|
|
34
|
+
issue_create: { ...issue, warnings: [warning] },
|
|
35
|
+
issue_update: {
|
|
36
|
+
...issue,
|
|
37
|
+
warnings: [warning],
|
|
38
|
+
conversion: { priorBody: issue.body, canonicalBody: issue.body, diff: issue.body },
|
|
39
|
+
historyComment: { commentId: 30, url: `${issue.url}#issuecomment-30`, body: issue.body, reused: false }
|
|
40
|
+
},
|
|
41
|
+
issue_info: issue,
|
|
42
|
+
issue_comment: { commentId: 31, url: `${issue.url}#issuecomment-31`, body: issue.body, reused: false },
|
|
43
|
+
issue_pr_create: {
|
|
44
|
+
prNumber: 23,
|
|
45
|
+
url: "https://github.com/example/widget/pull/23",
|
|
46
|
+
headSha: "a".repeat(40),
|
|
47
|
+
draft: true,
|
|
48
|
+
reviewRoute: {
|
|
49
|
+
author: { actorLogin: "synthetic-author", credentialSource: "synthetic-author-source", identity: "author" },
|
|
50
|
+
reviewer: {
|
|
51
|
+
actorLogin: "synthetic-reviewer[bot]",
|
|
52
|
+
credentialSource: "synthetic-reviewer-source",
|
|
53
|
+
identity: "reviewer"
|
|
54
|
+
},
|
|
55
|
+
rules: { observedRequiredApprovals: 1, visibility: "complete" },
|
|
56
|
+
approvalEligibility: "unknown",
|
|
57
|
+
nextAction: "Confirm counted approval after exact-head submission."
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
issue_pr_info: {
|
|
61
|
+
prNumber: 23,
|
|
62
|
+
url: "https://github.com/example/widget/pull/23",
|
|
63
|
+
state: "open",
|
|
64
|
+
draft: true,
|
|
65
|
+
headSha: "a".repeat(40),
|
|
66
|
+
headBranch: "issue/17",
|
|
67
|
+
baseBranch: "main",
|
|
68
|
+
merged: false
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const inputs = {
|
|
72
|
+
issue_create: { title: issue.title, issueType: "Feature", points: 3, draft: true },
|
|
73
|
+
issue_update: { issueNumber: 17, title: issue.title },
|
|
74
|
+
issue_info: { issueNumber: 17 },
|
|
75
|
+
issue_comment: {
|
|
76
|
+
issueNumber: 17,
|
|
77
|
+
kind: "start",
|
|
78
|
+
summary: "Started.",
|
|
79
|
+
status: "In progress",
|
|
80
|
+
outcome: "Deliver the change.",
|
|
81
|
+
nextStep: "Test.",
|
|
82
|
+
nextDate: null,
|
|
83
|
+
keyNumbers: [],
|
|
84
|
+
evidence: []
|
|
85
|
+
},
|
|
86
|
+
issue_pr_create: { issueNumber: 17, body: "Closes #17\n\nSynthetic change." },
|
|
87
|
+
issue_pr_info: { issueNumber: 17, prNumber: 23 }
|
|
88
|
+
};
|
|
89
|
+
afterEach(() => vi.restoreAllMocks());
|
|
90
|
+
async function call(name, verbose) {
|
|
91
|
+
const server = createAiDeliveryMcpServer({ repoRoot: "/synthetic" });
|
|
92
|
+
const client = new Client({ name: "compact-output-synthetic", version: "1" });
|
|
93
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
94
|
+
try {
|
|
95
|
+
await server.connect(serverTransport);
|
|
96
|
+
await client.connect(clientTransport);
|
|
97
|
+
return await client.callTool({
|
|
98
|
+
name,
|
|
99
|
+
arguments: { ...inputs[name], repo: "example/widget", ...verbose === void 0 ? {} : { verbose } }
|
|
100
|
+
});
|
|
101
|
+
} finally {
|
|
102
|
+
await client.close();
|
|
103
|
+
await server.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
test.each(Object.keys(results))(
|
|
107
|
+
"%s returns compact MCP JSON and unchanged verbose JSON",
|
|
108
|
+
async (name) => {
|
|
109
|
+
const execute = vi.spyOn(dispatch, "executeTool").mockResolvedValue(results[name]);
|
|
110
|
+
const compact = await call(name);
|
|
111
|
+
expect(compact.isError).not.toBe(true);
|
|
112
|
+
const text = compact.content[0].text;
|
|
113
|
+
expect(text.length).toBeLessThanOrEqual(1500);
|
|
114
|
+
expect(JSON.parse(text)).not.toHaveProperty("body");
|
|
115
|
+
const verbose = await call(name, true);
|
|
116
|
+
expect(verbose.isError).not.toBe(true);
|
|
117
|
+
const full = verbose.content[0].text;
|
|
118
|
+
expect(full).toBe(JSON.stringify(results[name]));
|
|
119
|
+
expect(execute.mock.calls.at(-1)[1]).not.toHaveProperty("verbose");
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
test("MCP compact and verbose snapshots", async () => {
|
|
123
|
+
const compact = {};
|
|
124
|
+
const execute = vi.spyOn(dispatch, "executeTool");
|
|
125
|
+
for (const name of Object.keys(results)) {
|
|
126
|
+
execute.mockResolvedValue(results[name]);
|
|
127
|
+
const reply2 = await call(name);
|
|
128
|
+
compact[name] = JSON.parse(reply2.content[0].text);
|
|
129
|
+
}
|
|
130
|
+
await expect(JSON.stringify(compact, null, 2) + "\n").toMatchFileSnapshot(
|
|
131
|
+
join(process.cwd(), "src/fixtures/toolOutput.compact.snap")
|
|
132
|
+
);
|
|
133
|
+
execute.mockResolvedValue(results.issue_update);
|
|
134
|
+
const reply = await call("issue_update", true);
|
|
135
|
+
await expect(
|
|
136
|
+
JSON.stringify(JSON.parse(reply.content[0].text), null, 2) + "\n"
|
|
137
|
+
).toMatchFileSnapshot(join(process.cwd(), "src/fixtures/toolOutput.verbose.snap"));
|
|
138
|
+
});
|
|
139
|
+
test("contract refusals retain the field and fix hint", async () => {
|
|
140
|
+
vi.spyOn(dispatch, "executeTool").mockRejectedValue(new IssueValidationError([warning]));
|
|
141
|
+
const reply = await call("issue_update");
|
|
142
|
+
expect(reply.isError).toBe(true);
|
|
143
|
+
const refusal = JSON.parse(reply.content[0].text);
|
|
144
|
+
expect(refusal.failures).toEqual([warning]);
|
|
145
|
+
});
|
|
146
|
+
test("verbose belongs to the batch envelope and cannot alter an individual write", () => {
|
|
147
|
+
const schema = getAiDeliveryMcpTool("issue_batch_update").inputSchema;
|
|
148
|
+
expect(
|
|
149
|
+
schema.parse({ verbose: true, items: [{ issueNumber: 17, status: { latestJournal: "Verified" } }] })
|
|
150
|
+
).toHaveProperty("verbose", true);
|
|
151
|
+
expect(
|
|
152
|
+
() => schema.parse({ items: [{ issueNumber: 17, verbose: true, status: { latestJournal: "Verified" } }] })
|
|
153
|
+
).toThrow();
|
|
154
|
+
});
|
|
155
|
+
test("published write schemas state the limits that refuse a write", async () => {
|
|
156
|
+
const server = createAiDeliveryMcpServer({ repoRoot: "/synthetic" });
|
|
157
|
+
const client = new Client({ name: "schema-limits-synthetic", version: "1" });
|
|
158
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
159
|
+
await server.connect(serverTransport);
|
|
160
|
+
await client.connect(clientTransport);
|
|
161
|
+
const { tools } = await client.listTools();
|
|
162
|
+
await client.close();
|
|
163
|
+
await server.close();
|
|
164
|
+
const published = (name) => JSON.stringify(tools.find((tool) => tool.name === name));
|
|
165
|
+
for (const name of ["issue_create", "issue_update", "issue_batch_update"]) {
|
|
166
|
+
expect(published(name)).toContain("10\u201380 characters");
|
|
167
|
+
expect(published(name)).toContain("1, 2, 3, 5 or 8");
|
|
168
|
+
expect(published(name)).toContain("Ready Bug issues need");
|
|
169
|
+
}
|
|
170
|
+
expect(published("issue_comment")).toContain("progress: done, decisionNeeded and non-empty evidence");
|
|
171
|
+
expect(published("issue_comment")).toContain("HTTPS link with a public DNS hostname");
|
|
172
|
+
});
|
|
173
|
+
test("compact batch output reports each item once", () => {
|
|
174
|
+
const item = {
|
|
175
|
+
issueNumber: 17,
|
|
176
|
+
status: "applied",
|
|
177
|
+
changes: { state: "closed", closeReason: "not_planned" },
|
|
178
|
+
readback: issue,
|
|
179
|
+
relatedReadback: { ...issue, closeReason: "not_planned" }
|
|
180
|
+
};
|
|
181
|
+
const value = { dryRun: false, results: Array.from({ length: 10 }, () => item), summary: { total: 10 } };
|
|
182
|
+
const compact = JSON.stringify(projectToolOutput("issue_batch_update", value));
|
|
183
|
+
expect(compact).not.toContain("relatedReadback");
|
|
184
|
+
expect(compact.length).toBeLessThanOrEqual(10 * 600);
|
|
185
|
+
expect(projectToolOutput("issue_batch_update", value, true)).toBe(value);
|
|
186
|
+
});
|
|
187
|
+
test("compact output preserves recovery inputs, fields and diagnostics without mutating evidence", () => {
|
|
188
|
+
const value = {
|
|
189
|
+
status: "update-incomplete",
|
|
190
|
+
native: { readback: issue },
|
|
191
|
+
recovery: { tool: "issue_batch_update", arguments: { items: [{ issueNumber: 17, body: issue.body }] } },
|
|
192
|
+
safeResume: { tool: "issue_start", arguments: { body: issue.body } },
|
|
193
|
+
fields: { body: "An organization field named body" },
|
|
194
|
+
warnings: [warning],
|
|
195
|
+
failures: [warning]
|
|
196
|
+
};
|
|
197
|
+
const before = JSON.stringify(value);
|
|
198
|
+
const compact = projectToolOutput("issue_update", value);
|
|
199
|
+
expect(compact.native.readback).not.toHaveProperty("body");
|
|
200
|
+
expect(compact.recovery).toEqual(value.recovery);
|
|
201
|
+
expect(compact.safeResume).toEqual(value.safeResume);
|
|
202
|
+
expect(compact.fields).toEqual(value.fields);
|
|
203
|
+
expect(compact.warnings).toEqual([warning]);
|
|
204
|
+
expect(compact.failures).toEqual([warning]);
|
|
205
|
+
expect(JSON.stringify(value)).toBe(before);
|
|
206
|
+
expect(projectToolOutput("issue_update", value, true)).toBe(value);
|
|
207
|
+
expect(projectToolOutput("board_reconcile", value)).toBe(value);
|
|
208
|
+
});
|
|
209
|
+
test.each([[], ["--json"], ["--verbose"], ["--json", "--verbose"]].map((flags) => ({ flags })))(
|
|
210
|
+
"actual CLI output flags $flags",
|
|
211
|
+
{ tags: ["release"] },
|
|
212
|
+
async ({ flags }) => {
|
|
213
|
+
const cli = pathToFileURL(join(process.cwd(), "dist/cli.js")).href;
|
|
214
|
+
const module = pathToFileURL(join(process.cwd(), "dist/dispatch.js")).href;
|
|
215
|
+
const result = spawnSync(
|
|
216
|
+
process.execPath,
|
|
217
|
+
[
|
|
218
|
+
"--experimental-test-module-mocks",
|
|
219
|
+
"--no-warnings",
|
|
220
|
+
"--input-type=module",
|
|
221
|
+
"-e",
|
|
222
|
+
`import { mock } from 'node:test';
|
|
223
|
+
mock.module(${JSON.stringify(module)}, { exports: {
|
|
224
|
+
contextFor: () => { throw new Error('Unexpected configuration access'); },
|
|
225
|
+
executeTool: async () => (${JSON.stringify(results.issue_update)})
|
|
226
|
+
}});
|
|
227
|
+
process.argv = [process.execPath, ${JSON.stringify(cli)}, ...${JSON.stringify(flags)}, 'update', '--issue', '17', '--title', 'Synthetic delivery change'];
|
|
228
|
+
await import(${JSON.stringify(cli)});`
|
|
229
|
+
],
|
|
230
|
+
{ encoding: "utf8" }
|
|
231
|
+
);
|
|
232
|
+
expect(result.status, result.stderr).toBe(0);
|
|
233
|
+
expect(result.stderr).toBe("");
|
|
234
|
+
const full = flags.includes("--json") && flags.includes("--verbose");
|
|
235
|
+
if (full) expect(result.stdout).toBe(JSON.stringify(results.issue_update, null, 2) + "\n");
|
|
236
|
+
else expect(result.stdout.length).toBeLessThanOrEqual(1500);
|
|
237
|
+
if (!full) await expect(result.stdout).toMatchFileSnapshot(join(process.cwd(), "src/fixtures/toolOutput.cli.snap"));
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
//# sourceMappingURL=toolOutput.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/toolOutput.test.ts"],
|
|
4
|
+
"sourcesContent": ["import { spawnSync } from 'node:child_process';\nimport { pathToFileURL } from 'node:url';\nimport { join } from 'node:path';\nimport { Client } from '@modelcontextprotocol/sdk/client/index.js';\nimport { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';\nimport { afterEach, expect, test, vi } from 'vitest';\nimport * as dispatch from './dispatch.js';\nimport { createAiDeliveryMcpServer } from './mcp/index.js';\nimport { IssueValidationError } from './issueContract.js';\nimport { projectToolOutput } from './toolOutput.js';\nimport { getAiDeliveryMcpTool } from './mcp/tools.js';\n\nconst issue = {\n issueNumber: 17,\n url: 'https://github.com/example/widget/issues/17',\n title: 'Synthetic delivery change',\n state: 'open',\n projectStatus: 'Todo',\n issueType: 'Feature',\n points: 3,\n priority: 'P1',\n fields: { startDate: null },\n blockedBy: [12],\n parentIssueNumber: 1,\n body:\n 'Synthetic issue body. '.repeat(140).padEnd(3000, '.') +\n '\\n' +\n Array.from({ length: 5 }, (_, i) => `- [ ] Criterion ${i + 1}`).join('\\n'),\n routing: { repository: 'example/widget', statusFieldId: 'synthetic-status' },\n};\nconst warning = {\n code: 'body.length',\n field: 'body',\n message: 'Consider a smaller body.',\n fixHint: 'Shorten the body.',\n};\nconst results = {\n issue_create: { ...issue, warnings: [warning] },\n issue_update: {\n ...issue,\n warnings: [warning],\n conversion: { priorBody: issue.body, canonicalBody: issue.body, diff: issue.body },\n historyComment: { commentId: 30, url: `${issue.url}#issuecomment-30`, body: issue.body, reused: false },\n },\n issue_info: issue,\n issue_comment: { commentId: 31, url: `${issue.url}#issuecomment-31`, body: issue.body, reused: false },\n issue_pr_create: {\n prNumber: 23,\n url: 'https://github.com/example/widget/pull/23',\n headSha: 'a'.repeat(40),\n draft: true,\n reviewRoute: {\n author: { actorLogin: 'synthetic-author', credentialSource: 'synthetic-author-source', identity: 'author' },\n reviewer: {\n actorLogin: 'synthetic-reviewer[bot]',\n credentialSource: 'synthetic-reviewer-source',\n identity: 'reviewer',\n },\n rules: { observedRequiredApprovals: 1, visibility: 'complete' },\n approvalEligibility: 'unknown',\n nextAction: 'Confirm counted approval after exact-head submission.',\n },\n },\n issue_pr_info: {\n prNumber: 23,\n url: 'https://github.com/example/widget/pull/23',\n state: 'open',\n draft: true,\n headSha: 'a'.repeat(40),\n headBranch: 'issue/17',\n baseBranch: 'main',\n merged: false,\n },\n};\nconst inputs = {\n issue_create: { title: issue.title, issueType: 'Feature', points: 3, draft: true },\n issue_update: { issueNumber: 17, title: issue.title },\n issue_info: { issueNumber: 17 },\n issue_comment: {\n issueNumber: 17,\n kind: 'start',\n summary: 'Started.',\n status: 'In progress',\n outcome: 'Deliver the change.',\n nextStep: 'Test.',\n nextDate: null,\n keyNumbers: [],\n evidence: [],\n },\n issue_pr_create: { issueNumber: 17, body: 'Closes #17\\n\\nSynthetic change.' },\n issue_pr_info: { issueNumber: 17, prNumber: 23 },\n};\nafterEach(() => vi.restoreAllMocks());\n\nasync function call(name: keyof typeof results, verbose?: boolean) {\n const server = createAiDeliveryMcpServer({ repoRoot: '/synthetic' });\n const client = new Client({ name: 'compact-output-synthetic', version: '1' });\n const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();\n try {\n await server.connect(serverTransport);\n await client.connect(clientTransport);\n return await client.callTool({\n name,\n arguments: { ...inputs[name], repo: 'example/widget', ...(verbose === undefined ? {} : { verbose }) },\n });\n } finally {\n await client.close();\n await server.close();\n }\n}\n\ntest.each(Object.keys(results) as Array<keyof typeof results>)(\n '%s returns compact MCP JSON and unchanged verbose JSON',\n async (name) => {\n const execute = vi.spyOn(dispatch, 'executeTool').mockResolvedValue(results[name]);\n const compact = await call(name);\n expect(compact.isError).not.toBe(true);\n const text = (compact.content as Array<{ text: string }>)[0]!.text;\n expect(text.length).toBeLessThanOrEqual(1500);\n expect(JSON.parse(text)).not.toHaveProperty('body');\n const verbose = await call(name, true);\n expect(verbose.isError).not.toBe(true);\n const full = (verbose.content as Array<{ text: string }>)[0]!.text;\n expect(full).toBe(JSON.stringify(results[name]));\n\n expect(execute.mock.calls.at(-1)![1]).not.toHaveProperty('verbose');\n },\n);\n\ntest('MCP compact and verbose snapshots', async () => {\n const compact: Record<string, unknown> = {};\n const execute = vi.spyOn(dispatch, 'executeTool');\n for (const name of Object.keys(results) as Array<keyof typeof results>) {\n execute.mockResolvedValue(results[name]);\n const reply = await call(name);\n compact[name] = JSON.parse((reply.content as Array<{ text: string }>)[0]!.text);\n }\n await expect(JSON.stringify(compact, null, 2) + '\\n').toMatchFileSnapshot(\n join(process.cwd(), 'src/fixtures/toolOutput.compact.snap'),\n );\n execute.mockResolvedValue(results.issue_update);\n const reply = await call('issue_update', true);\n await expect(\n JSON.stringify(JSON.parse((reply.content as Array<{ text: string }>)[0]!.text), null, 2) + '\\n',\n ).toMatchFileSnapshot(join(process.cwd(), 'src/fixtures/toolOutput.verbose.snap'));\n});\n\ntest('contract refusals retain the field and fix hint', async () => {\n vi.spyOn(dispatch, 'executeTool').mockRejectedValue(new IssueValidationError([warning]));\n const reply = await call('issue_update');\n expect(reply.isError).toBe(true);\n const refusal = JSON.parse((reply.content as Array<{ text: string }>)[0]!.text) as { failures: unknown };\n expect(refusal.failures).toEqual([warning]);\n});\n\ntest('verbose belongs to the batch envelope and cannot alter an individual write', () => {\n const schema = getAiDeliveryMcpTool('issue_batch_update')!.inputSchema;\n expect(\n schema.parse({ verbose: true, items: [{ issueNumber: 17, status: { latestJournal: 'Verified' } }] }),\n ).toHaveProperty('verbose', true);\n expect(() =>\n schema.parse({ items: [{ issueNumber: 17, verbose: true, status: { latestJournal: 'Verified' } }] }),\n ).toThrow();\n});\n\ntest('published write schemas state the limits that refuse a write', async () => {\n const server = createAiDeliveryMcpServer({ repoRoot: '/synthetic' });\n const client = new Client({ name: 'schema-limits-synthetic', version: '1' });\n const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();\n await server.connect(serverTransport);\n await client.connect(clientTransport);\n const { tools } = await client.listTools();\n await client.close();\n await server.close();\n const published = (name: string) => JSON.stringify(tools.find((tool) => tool.name === name));\n for (const name of ['issue_create', 'issue_update', 'issue_batch_update']) {\n expect(published(name)).toContain('10\u201380 characters');\n expect(published(name)).toContain('1, 2, 3, 5 or 8');\n expect(published(name)).toContain('Ready Bug issues need');\n }\n expect(published('issue_comment')).toContain('progress: done, decisionNeeded and non-empty evidence');\n expect(published('issue_comment')).toContain('HTTPS link with a public DNS hostname');\n});\n\ntest('compact batch output reports each item once', () => {\n const item = {\n issueNumber: 17,\n status: 'applied',\n changes: { state: 'closed', closeReason: 'not_planned' },\n readback: issue,\n relatedReadback: { ...issue, closeReason: 'not_planned' },\n };\n const value = { dryRun: false, results: Array.from({ length: 10 }, () => item), summary: { total: 10 } };\n const compact = JSON.stringify(projectToolOutput('issue_batch_update', value));\n expect(compact).not.toContain('relatedReadback');\n expect(compact.length).toBeLessThanOrEqual(10 * 600);\n expect(projectToolOutput('issue_batch_update', value, true)).toBe(value);\n});\n\ntest('compact output preserves recovery inputs, fields and diagnostics without mutating evidence', () => {\n const value = {\n status: 'update-incomplete',\n native: { readback: issue },\n recovery: { tool: 'issue_batch_update', arguments: { items: [{ issueNumber: 17, body: issue.body }] } },\n safeResume: { tool: 'issue_start', arguments: { body: issue.body } },\n fields: { body: 'An organization field named body' },\n warnings: [warning],\n failures: [warning],\n };\n const before = JSON.stringify(value);\n const compact = projectToolOutput('issue_update', value) as typeof value;\n expect(compact.native.readback).not.toHaveProperty('body');\n expect(compact.recovery).toEqual(value.recovery);\n expect(compact.safeResume).toEqual(value.safeResume);\n expect(compact.fields).toEqual(value.fields);\n expect(compact.warnings).toEqual([warning]);\n expect(compact.failures).toEqual([warning]);\n expect(JSON.stringify(value)).toBe(before);\n expect(projectToolOutput('issue_update', value, true)).toBe(value);\n expect(projectToolOutput('board_reconcile', value)).toBe(value);\n});\n\ntest.each([[], ['--json'], ['--verbose'], ['--json', '--verbose']].map((flags) => ({ flags })))(\n 'actual CLI output flags $flags',\n { tags: ['release'] },\n async ({ flags }) => {\n const cli = pathToFileURL(join(process.cwd(), 'dist/cli.js')).href;\n const module = pathToFileURL(join(process.cwd(), 'dist/dispatch.js')).href;\n const result = spawnSync(\n process.execPath,\n [\n '--experimental-test-module-mocks',\n '--no-warnings',\n '--input-type=module',\n '-e',\n `import { mock } from 'node:test';\n mock.module(${JSON.stringify(module)}, { exports: {\n contextFor: () => { throw new Error('Unexpected configuration access'); },\n executeTool: async () => (${JSON.stringify(results.issue_update)})\n }});\n process.argv = [process.execPath, ${JSON.stringify(cli)}, ...${JSON.stringify(flags)}, 'update', '--issue', '17', '--title', 'Synthetic delivery change'];\n await import(${JSON.stringify(cli)});`,\n ],\n { encoding: 'utf8' },\n );\n expect(result.status, result.stderr).toBe(0);\n expect(result.stderr).toBe('');\n const full = flags.includes('--json') && flags.includes('--verbose');\n if (full) expect(result.stdout).toBe(JSON.stringify(results.issue_update, null, 2) + '\\n');\n else expect(result.stdout.length).toBeLessThanOrEqual(1500);\n if (!full) await expect(result.stdout).toMatchFileSnapshot(join(process.cwd(), 'src/fixtures/toolOutput.cli.snap'));\n },\n);\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,yBAAyB;AAClC,SAAS,WAAW,QAAQ,MAAM,UAAU;AAC5C,YAAY,cAAc;AAC1B,SAAS,iCAAiC;AAC1C,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAErC,MAAM,QAAQ;AAAA,EACZ,aAAa;AAAA,EACb,KAAK;AAAA,EACL,OAAO;AAAA,EACP,OAAO;AAAA,EACP,eAAe;AAAA,EACf,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,UAAU;AAAA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QACE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,mBACW,KAAK,UAAU,MAAM,CAAC;AAAA;AAAA,mCAEN,KAAK,UAAU,QAAQ,YAAY,CAAC;AAAA;AAAA,yCAE9B,KAAK,UAAU,GAAG,CAAC,QAAQ,KAAK,UAAU,KAAK,CAAC;AAAA,oBACrE,KAAK,UAAU,GAAG,CAAC;AAAA,MACjC;AAAA,MACA,EAAE,UAAU,OAAO;AAAA,IACrB;AACA,WAAO,OAAO,QAAQ,OAAO,MAAM,EAAE,KAAK,CAAC;AAC3C,WAAO,OAAO,MAAM,EAAE,KAAK,EAAE;AAC7B,UAAM,OAAO,MAAM,SAAS,QAAQ,KAAK,MAAM,SAAS,WAAW;AACnE,QAAI,KAAM,QAAO,OAAO,MAAM,EAAE,KAAK,KAAK,UAAU,QAAQ,cAAc,MAAM,CAAC,IAAI,IAAI;AAAA,QACpF,QAAO,OAAO,OAAO,MAAM,EAAE,oBAAoB,IAAI;AAC1D,QAAI,CAAC,KAAM,OAAM,OAAO,OAAO,MAAM,EAAE,oBAAoB,KAAK,QAAQ,IAAI,GAAG,kCAAkC,CAAC;AAAA,EACpH;AACF;",
|
|
6
|
+
"names": ["reply"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/** Create a private directory hierarchy and durably publish every new directory entry. */
|
|
2
2
|
export declare function ensurePrivateDirectoryDurably(path: string): void;
|
|
3
|
-
/** Publish a complete JSON file with a same-directory durable rename. */
|
|
4
|
-
export declare function writeJsonFileAtomically(path: string, value: unknown): void;
|
|
5
3
|
/** Publish private JSON evidence with the same durable rename contract. */
|
|
6
4
|
export declare function writePrivateJsonFileAtomically(path: string, value: unknown): void;
|
package/dist/utils/atomicJson.js
CHANGED
|
@@ -1,87 +1,91 @@
|
|
|
1
|
-
import { randomUUID } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
closeSync,
|
|
4
|
+
existsSync,
|
|
5
|
+
fsyncSync,
|
|
6
|
+
lstatSync,
|
|
7
|
+
mkdirSync,
|
|
8
|
+
openSync,
|
|
9
|
+
renameSync,
|
|
10
|
+
unlinkSync,
|
|
11
|
+
writeFileSync
|
|
12
|
+
} from "node:fs";
|
|
13
|
+
import { dirname, join } from "node:path";
|
|
14
|
+
function ensurePrivateDirectoryDurably(path) {
|
|
15
|
+
ensureDirectoryDurably(path, 448);
|
|
7
16
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
writeJsonAtomically({ directoryMode: 0o777, mode: 0o666, path, value });
|
|
11
|
-
}
|
|
12
|
-
/** Publish private JSON evidence with the same durable rename contract. */
|
|
13
|
-
export function writePrivateJsonFileAtomically(path, value) {
|
|
14
|
-
writeJsonAtomically({ directoryMode: 0o700, mode: 0o600, path, value });
|
|
17
|
+
function writePrivateJsonFileAtomically(path, value) {
|
|
18
|
+
writeJsonAtomically({ directoryMode: 448, mode: 384, path, value });
|
|
15
19
|
}
|
|
16
20
|
function ensureDirectoryDurably(directory, mode) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const metadata = lstatSync(path);
|
|
34
|
-
if (!metadata.isDirectory() || metadata.isSymbolicLink() || (mode === 0o700 && (metadata.mode & 0o077) !== 0))
|
|
35
|
-
throw new Error('Concurrent directory creation did not publish a safe directory.');
|
|
36
|
-
}
|
|
37
|
-
fsyncDirectory(dirname(path));
|
|
21
|
+
const missing = [];
|
|
22
|
+
let candidate = directory;
|
|
23
|
+
while (!existsSync(candidate)) {
|
|
24
|
+
missing.push(candidate);
|
|
25
|
+
const parent = dirname(candidate);
|
|
26
|
+
if (parent === candidate) break;
|
|
27
|
+
candidate = parent;
|
|
28
|
+
}
|
|
29
|
+
for (const path of missing.reverse()) {
|
|
30
|
+
try {
|
|
31
|
+
mkdirSync(path, { mode });
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error.code !== "EEXIST") throw error;
|
|
34
|
+
const metadata = lstatSync(path);
|
|
35
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink() || mode === 448 && (metadata.mode & 63) !== 0)
|
|
36
|
+
throw new Error("Concurrent directory creation did not publish a safe directory.");
|
|
38
37
|
}
|
|
38
|
+
fsyncDirectory(dirname(path));
|
|
39
|
+
}
|
|
39
40
|
}
|
|
40
41
|
function fsyncDirectory(directory) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
42
|
+
const descriptor = openSync(directory, "r");
|
|
43
|
+
try {
|
|
44
|
+
fsyncSync(descriptor);
|
|
45
|
+
} finally {
|
|
46
|
+
closeSync(descriptor);
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
|
-
function writeJsonAtomically({
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
function writeJsonAtomically({
|
|
50
|
+
directoryMode,
|
|
51
|
+
mode,
|
|
52
|
+
path,
|
|
53
|
+
value
|
|
54
|
+
}) {
|
|
55
|
+
const directory = dirname(path);
|
|
56
|
+
ensureDirectoryDurably(directory, directoryMode);
|
|
57
|
+
const temporaryPath = join(directory, `.${String(process.pid)}.${randomUUID()}.tmp`);
|
|
58
|
+
let creationDescriptor;
|
|
59
|
+
let fileDescriptor;
|
|
60
|
+
let directoryDescriptor;
|
|
61
|
+
try {
|
|
62
|
+
creationDescriptor = openSync(temporaryPath, "wx", mode);
|
|
63
|
+
closeSync(creationDescriptor);
|
|
64
|
+
creationDescriptor = void 0;
|
|
65
|
+
writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
66
|
+
`, "utf8");
|
|
67
|
+
fileDescriptor = openSync(temporaryPath, "r");
|
|
68
|
+
fsyncSync(fileDescriptor);
|
|
69
|
+
closeSync(fileDescriptor);
|
|
70
|
+
fileDescriptor = void 0;
|
|
71
|
+
renameSync(temporaryPath, path);
|
|
72
|
+
directoryDescriptor = openSync(directory, "r");
|
|
73
|
+
fsyncSync(directoryDescriptor);
|
|
74
|
+
closeSync(directoryDescriptor);
|
|
75
|
+
directoryDescriptor = void 0;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (creationDescriptor !== void 0) closeSync(creationDescriptor);
|
|
78
|
+
if (fileDescriptor !== void 0) closeSync(fileDescriptor);
|
|
79
|
+
if (directoryDescriptor !== void 0) closeSync(directoryDescriptor);
|
|
56
80
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
creationDescriptor = undefined;
|
|
60
|
-
writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}\n`, 'utf8');
|
|
61
|
-
fileDescriptor = openSync(temporaryPath, 'r');
|
|
62
|
-
fsyncSync(fileDescriptor);
|
|
63
|
-
closeSync(fileDescriptor);
|
|
64
|
-
fileDescriptor = undefined;
|
|
65
|
-
renameSync(temporaryPath, path);
|
|
66
|
-
directoryDescriptor = openSync(directory, 'r');
|
|
67
|
-
fsyncSync(directoryDescriptor);
|
|
68
|
-
closeSync(directoryDescriptor);
|
|
69
|
-
directoryDescriptor = undefined;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
if (creationDescriptor !== undefined)
|
|
73
|
-
closeSync(creationDescriptor);
|
|
74
|
-
if (fileDescriptor !== undefined)
|
|
75
|
-
closeSync(fileDescriptor);
|
|
76
|
-
if (directoryDescriptor !== undefined)
|
|
77
|
-
closeSync(directoryDescriptor);
|
|
78
|
-
try {
|
|
79
|
-
unlinkSync(temporaryPath);
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// The temporary file was never created or has already been renamed.
|
|
83
|
-
}
|
|
84
|
-
throw error;
|
|
81
|
+
unlinkSync(temporaryPath);
|
|
82
|
+
} catch {
|
|
85
83
|
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
86
|
}
|
|
87
|
-
|
|
87
|
+
export {
|
|
88
|
+
ensurePrivateDirectoryDurably,
|
|
89
|
+
writePrivateJsonFileAtomically
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=atomicJson.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/atomicJson.ts"],
|
|
4
|
+
"sourcesContent": ["import { randomUUID } from 'node:crypto';\nimport {\n closeSync,\n existsSync,\n fsyncSync,\n lstatSync,\n mkdirSync,\n openSync,\n renameSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs';\nimport { dirname, join } from 'node:path';\n\n/** Create a private directory hierarchy and durably publish every new directory entry. */\nexport function ensurePrivateDirectoryDurably(path: string): void {\n ensureDirectoryDurably(path, 0o700);\n}\n\n/** Publish private JSON evidence with the same durable rename contract. */\nexport function writePrivateJsonFileAtomically(path: string, value: unknown): void {\n writeJsonAtomically({ directoryMode: 0o700, mode: 0o600, path, value });\n}\n\nfunction ensureDirectoryDurably(directory: string, mode: number): void {\n const missing: string[] = [];\n let candidate = directory;\n while (!existsSync(candidate)) {\n missing.push(candidate);\n const parent = dirname(candidate);\n if (parent === candidate) break;\n candidate = parent;\n }\n for (const path of missing.reverse()) {\n try {\n mkdirSync(path, { mode });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'EEXIST') throw error;\n const metadata = lstatSync(path);\n if (!metadata.isDirectory() || metadata.isSymbolicLink() || (mode === 0o700 && (metadata.mode & 0o077) !== 0))\n throw new Error('Concurrent directory creation did not publish a safe directory.');\n }\n fsyncDirectory(dirname(path));\n }\n}\n\nfunction fsyncDirectory(directory: string): void {\n const descriptor = openSync(directory, 'r');\n try {\n fsyncSync(descriptor);\n } finally {\n closeSync(descriptor);\n }\n}\n\nfunction writeJsonAtomically({\n directoryMode,\n mode,\n path,\n value,\n}: {\n directoryMode: number;\n mode: number;\n path: string;\n value: unknown;\n}): void {\n const directory = dirname(path);\n ensureDirectoryDurably(directory, directoryMode);\n const temporaryPath = join(directory, `.${String(process.pid)}.${randomUUID()}.tmp`);\n let creationDescriptor: number | undefined;\n let fileDescriptor: number | undefined;\n let directoryDescriptor: number | undefined;\n try {\n creationDescriptor = openSync(temporaryPath, 'wx', mode);\n closeSync(creationDescriptor);\n creationDescriptor = undefined;\n writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}\\n`, 'utf8');\n fileDescriptor = openSync(temporaryPath, 'r');\n fsyncSync(fileDescriptor);\n closeSync(fileDescriptor);\n fileDescriptor = undefined;\n renameSync(temporaryPath, path);\n directoryDescriptor = openSync(directory, 'r');\n fsyncSync(directoryDescriptor);\n closeSync(directoryDescriptor);\n directoryDescriptor = undefined;\n } catch (error: unknown) {\n if (creationDescriptor !== undefined) closeSync(creationDescriptor);\n if (fileDescriptor !== undefined) closeSync(fileDescriptor);\n if (directoryDescriptor !== undefined) closeSync(directoryDescriptor);\n try {\n unlinkSync(temporaryPath);\n } catch {\n // The temporary file was never created or has already been renamed.\n }\n throw error;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kBAAkB;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,YAAY;AAGvB,SAAS,8BAA8B,MAAoB;AAChE,yBAAuB,MAAM,GAAK;AACpC;AAGO,SAAS,+BAA+B,MAAc,OAAsB;AACjF,sBAAoB,EAAE,eAAe,KAAO,MAAM,KAAO,MAAM,MAAM,CAAC;AACxE;AAEA,SAAS,uBAAuB,WAAmB,MAAoB;AACrE,QAAM,UAAoB,CAAC;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;AAC7C,cAAU,mBAAmB;AAC7B,cAAU,mBAAmB;AAC7B,0BAAsB;AAAA,EACxB,SAAS,OAAgB;AACvB,QAAI,uBAAuB,OAAW,WAAU,kBAAkB;AAClE,QAAI,mBAAmB,OAAW,WAAU,cAAc;AAC1D,QAAI,wBAAwB,OAAW,WAAU,mBAAmB;AACpE,QAAI;AACF,iBAAW,aAAa;AAAA,IAC1B,QAAQ;AAAA,IAER;AACA,UAAM;AAAA,EACR;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,9 +1 @@
|
|
|
1
1
|
export declare const ISSUE_CLI_DATA_DIR = ".issue-cli";
|
|
2
|
-
/**
|
|
3
|
-
* Ensure the `.issue-cli` runtime directory exists.
|
|
4
|
-
* All agent runtime data (worktrees, metrics, audit logs) lives here.
|
|
5
|
-
*
|
|
6
|
-
* @param projectRoot - Project root directory (defaults to cwd)
|
|
7
|
-
* @returns Absolute path to the data directory
|
|
8
|
-
*/
|
|
9
|
-
export declare function ensureDataDirectory(projectRoot?: string): string;
|
package/dist/utils/filesystem.js
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* All agent runtime data (worktrees, metrics, audit logs) lives here.
|
|
7
|
-
*
|
|
8
|
-
* @param projectRoot - Project root directory (defaults to cwd)
|
|
9
|
-
* @returns Absolute path to the data directory
|
|
10
|
-
*/
|
|
11
|
-
export function ensureDataDirectory(projectRoot) {
|
|
12
|
-
const root = projectRoot ?? process.cwd();
|
|
13
|
-
const dataDir = resolve(root, ISSUE_CLI_DATA_DIR);
|
|
14
|
-
if (!existsSync(dataDir)) {
|
|
15
|
-
mkdirSync(dataDir, { recursive: true });
|
|
16
|
-
}
|
|
17
|
-
return dataDir;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=filesystem.js.map
|
|
1
|
+
const ISSUE_CLI_DATA_DIR = ".issue-cli";
|
|
2
|
+
export {
|
|
3
|
+
ISSUE_CLI_DATA_DIR
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=filesystem.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/filesystem.ts"],
|
|
4
|
+
"sourcesContent": ["export const ISSUE_CLI_DATA_DIR = '.issue-cli';\n"],
|
|
5
|
+
"mappings": "AAAO,MAAM,qBAAqB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|