ccdeck 3.49.1 → 3.51.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 (114) hide show
  1. package/README.md +7 -3
  2. package/THIRD_PARTY_NOTICES.md +28 -0
  3. package/bin/cli/commands.js +34 -3
  4. package/bin/cli/second-start.js +6 -1
  5. package/dist/web/assets/BrowserWatchModal-CDpunrq9.js +1 -0
  6. package/dist/web/assets/IntegrationModal-BctMcNU8.js +7 -0
  7. package/dist/web/assets/{RadioPanel-gFYxdsBg.js → RadioPanel-DQNFtYOx.js} +1 -1
  8. package/dist/web/assets/{TrafficRadar-B9MfKca4.js → TrafficRadar-DRt3Al7E.js} +1 -1
  9. package/dist/web/assets/UsageHistoryModal-DlgPufgs.js +1 -0
  10. package/dist/web/assets/{app-D2NP6IPl.js → app-4x4wTE-L.js} +73 -73
  11. package/dist/web/assets/{app-DfGYllmZ.css → app-o4kL0FgZ.css} +1 -1
  12. package/dist/web/assets/{index-Be6Ox-74.js → index-CWUj8Kqh.js} +1 -1
  13. package/dist/web/index.html +3 -3
  14. package/node_modules/bare-addon-resolve/LICENSE +201 -0
  15. package/node_modules/bare-addon-resolve/README.md +226 -0
  16. package/node_modules/bare-addon-resolve/index.d.ts +100 -0
  17. package/node_modules/bare-addon-resolve/index.js +531 -0
  18. package/node_modules/bare-addon-resolve/lib/errors.d.ts +16 -0
  19. package/node_modules/bare-addon-resolve/lib/errors.js +21 -0
  20. package/node_modules/bare-addon-resolve/package.json +57 -0
  21. package/node_modules/bare-module-resolve/LICENSE +201 -0
  22. package/node_modules/bare-module-resolve/README.md +322 -0
  23. package/node_modules/bare-module-resolve/index.d.ts +171 -0
  24. package/node_modules/bare-module-resolve/index.js +899 -0
  25. package/node_modules/bare-module-resolve/lib/errors.d.ts +31 -0
  26. package/node_modules/bare-module-resolve/lib/errors.js +37 -0
  27. package/node_modules/bare-module-resolve/package.json +56 -0
  28. package/node_modules/bare-semver/LICENSE +201 -0
  29. package/node_modules/bare-semver/README.md +147 -0
  30. package/node_modules/bare-semver/index.d.ts +61 -0
  31. package/node_modules/bare-semver/index.js +13 -0
  32. package/node_modules/bare-semver/lib/comparator.js +37 -0
  33. package/node_modules/bare-semver/lib/constants.js +7 -0
  34. package/node_modules/bare-semver/lib/errors.js +22 -0
  35. package/node_modules/bare-semver/lib/range.js +256 -0
  36. package/node_modules/bare-semver/lib/version.js +240 -0
  37. package/node_modules/bare-semver/package.json +43 -0
  38. package/node_modules/fs-native-extensions/CMakeLists.txt +118 -0
  39. package/node_modules/fs-native-extensions/LICENSE +201 -0
  40. package/node_modules/fs-native-extensions/README.md +160 -0
  41. package/node_modules/fs-native-extensions/binding.c +1825 -0
  42. package/node_modules/fs-native-extensions/binding.js +3 -0
  43. package/node_modules/fs-native-extensions/include/fs-ext.h +193 -0
  44. package/node_modules/fs-native-extensions/index.js +356 -0
  45. package/node_modules/fs-native-extensions/package.json +72 -0
  46. package/node_modules/fs-native-extensions/prebuilds/android-arm/fs-native-extensions.bare +0 -0
  47. package/node_modules/fs-native-extensions/prebuilds/android-arm/fs-native-extensions.node +0 -0
  48. package/node_modules/fs-native-extensions/prebuilds/android-arm64/fs-native-extensions.bare +0 -0
  49. package/node_modules/fs-native-extensions/prebuilds/android-arm64/fs-native-extensions.node +0 -0
  50. package/node_modules/fs-native-extensions/prebuilds/android-ia32/fs-native-extensions.bare +0 -0
  51. package/node_modules/fs-native-extensions/prebuilds/android-ia32/fs-native-extensions.node +0 -0
  52. package/node_modules/fs-native-extensions/prebuilds/android-x64/fs-native-extensions.bare +0 -0
  53. package/node_modules/fs-native-extensions/prebuilds/android-x64/fs-native-extensions.node +0 -0
  54. package/node_modules/fs-native-extensions/prebuilds/darwin-arm64/fs-native-extensions.bare +0 -0
  55. package/node_modules/fs-native-extensions/prebuilds/darwin-arm64/fs-native-extensions.node +0 -0
  56. package/node_modules/fs-native-extensions/prebuilds/darwin-x64/fs-native-extensions.bare +0 -0
  57. package/node_modules/fs-native-extensions/prebuilds/darwin-x64/fs-native-extensions.node +0 -0
  58. package/node_modules/fs-native-extensions/prebuilds/ios-arm64/fs-native-extensions.bare +0 -0
  59. package/node_modules/fs-native-extensions/prebuilds/ios-arm64-simulator/fs-native-extensions.bare +0 -0
  60. package/node_modules/fs-native-extensions/prebuilds/ios-x64-simulator/fs-native-extensions.bare +0 -0
  61. package/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.bare +0 -0
  62. package/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.node +0 -0
  63. package/node_modules/fs-native-extensions/prebuilds/linux-x64/fs-native-extensions.bare +0 -0
  64. package/node_modules/fs-native-extensions/prebuilds/linux-x64/fs-native-extensions.node +0 -0
  65. package/node_modules/fs-native-extensions/prebuilds/win32-arm64/fs-native-extensions.bare +0 -0
  66. package/node_modules/fs-native-extensions/prebuilds/win32-arm64/fs-native-extensions.node +0 -0
  67. package/node_modules/fs-native-extensions/prebuilds/win32-x64/fs-native-extensions.bare +0 -0
  68. package/node_modules/fs-native-extensions/prebuilds/win32-x64/fs-native-extensions.node +0 -0
  69. package/node_modules/fs-native-extensions/src/apple.c +197 -0
  70. package/node_modules/fs-native-extensions/src/linux.c +146 -0
  71. package/node_modules/fs-native-extensions/src/platform.h +51 -0
  72. package/node_modules/fs-native-extensions/src/posix.c +33 -0
  73. package/node_modules/fs-native-extensions/src/shared.c +397 -0
  74. package/node_modules/fs-native-extensions/src/win32/nt.h +226 -0
  75. package/node_modules/fs-native-extensions/src/win32.c +531 -0
  76. package/node_modules/require-addon/LICENSE +201 -0
  77. package/node_modules/require-addon/README.md +19 -0
  78. package/node_modules/require-addon/lib/bare.js +1 -0
  79. package/node_modules/require-addon/lib/default.js +7 -0
  80. package/node_modules/require-addon/lib/node.js +79 -0
  81. package/node_modules/require-addon/package.json +64 -0
  82. package/node_modules/which-runtime/LICENSE +201 -0
  83. package/node_modules/which-runtime/README.md +29 -0
  84. package/node_modules/which-runtime/index.js +36 -0
  85. package/node_modules/which-runtime/package.json +32 -0
  86. package/package.json +12 -2
  87. package/release-notes.json +25 -0
  88. package/src/server/claude-accounts.mjs +19 -3
  89. package/src/server/claude-collector.mjs +18 -2
  90. package/src/server/cswap-install.mjs +60 -18
  91. package/src/server/integrations/jira-comment.mjs +37 -0
  92. package/src/server/integrations/jira-move.mjs +37 -11
  93. package/src/server/integrations/jira-transition.mjs +43 -0
  94. package/src/server/integrations/jira-write-guard.mjs +218 -0
  95. package/src/server/integrations/jira.mjs +16 -0
  96. package/src/server/integrations/routes.mjs +70 -7
  97. package/src/server/lan-deck.mjs +9 -0
  98. package/src/server/lan-engine.mjs +17 -2
  99. package/src/server/lan-manifest.mjs +10 -3
  100. package/src/server/lifecycle.mjs +27 -2
  101. package/src/server/login-guard.mjs +4 -0
  102. package/src/server/npm-upgrade.mjs +46 -18
  103. package/src/server/pinned-build.mjs +5 -0
  104. package/src/server/quota-store-resets.mjs +13 -6
  105. package/src/server/quota.mjs +8 -1
  106. package/src/server/running-deck.mjs +14 -0
  107. package/src/server/static-cache.mjs +34 -16
  108. package/src/server/terminal-cli-update.mjs +189 -0
  109. package/src/server/terminal-cli.mjs +93 -0
  110. package/src/server/traffic-radar-wire.mjs +6 -0
  111. package/src/server/usage-share.mjs +444 -0
  112. package/dist/web/assets/BrowserWatchModal-CCARqAMn.js +0 -1
  113. package/dist/web/assets/IntegrationModal-B8t53aE5.js +0 -7
  114. package/dist/web/assets/UsageHistoryModal-DvYWhsYv.js +0 -1
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "which-runtime",
3
+ "version": "1.4.0",
4
+ "description": "Detect if you are in Bare or Node and which os etc",
5
+ "main": "index.js",
6
+ "files": [
7
+ "index.js"
8
+ ],
9
+ "scripts": {
10
+ "format": "prettier --write .",
11
+ "lint": "prettier --check . && lunte .",
12
+ "test": "npm run test:node && npm run test:bare",
13
+ "test:node": "brittle-node test.js",
14
+ "test:bare": "brittle-bare test.js"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/holepunchto/which-runtime.git"
19
+ },
20
+ "author": "Holepunch Inc.",
21
+ "license": "Apache-2.0",
22
+ "bugs": {
23
+ "url": "https://github.com/holepunchto/which-runtime/issues"
24
+ },
25
+ "homepage": "https://github.com/holepunchto/which-runtime",
26
+ "devDependencies": {
27
+ "brittle": "^3.0.0",
28
+ "lunte": "^1.4.0",
29
+ "prettier": "^3.6.2",
30
+ "prettier-config-holepunch": "^2.0.0"
31
+ }
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccdeck",
3
- "version": "3.49.1",
3
+ "version": "3.51.0",
4
4
  "description": "Local dashboard for Claude Code and Codex CLI sessions: which Claude Code session needs input, every tool call and Claude Code subagent live, token cost and quota, several Claude accounts. Run npx ccdeck.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -72,6 +72,10 @@
72
72
  "url": "https://github.com/BarganConstantin/ccdeck/issues"
73
73
  },
74
74
  "homepage": "https://ccdeck.dev",
75
+ "funding": {
76
+ "type": "github",
77
+ "url": "https://github.com/sponsors/BarganConstantin"
78
+ },
75
79
  "devDependencies": {
76
80
  "@types/dagre": "^0.7.54",
77
81
  "@types/node": "^22.20.1",
@@ -91,5 +95,11 @@
91
95
  "typescript": "^5.6.3",
92
96
  "vite": "^6.0.0",
93
97
  "vitest": "^2.1.9"
94
- }
98
+ },
99
+ "dependencies": {
100
+ "fs-native-extensions": "1.5.2"
101
+ },
102
+ "bundledDependencies": [
103
+ "fs-native-extensions"
104
+ ]
95
105
  }
@@ -84,6 +84,7 @@
84
84
  "without one."
85
85
  ],
86
86
  "//summaries": {
87
+ "3.51.0": "Jira integration updates",
87
88
  "3.46.0": "Plans, accounts and skills at a glance"
88
89
  },
89
90
  "//nothing-to-say": [
@@ -129,6 +130,30 @@
129
130
  "3.48.1",
130
131
  "3.49.1"
131
132
  ],
133
+ "3.51.0": [
134
+ {
135
+ "title": "✏️ Comment and change status in Jira",
136
+ "body": "Add a comment or change an issue’s status from its details in ccdeck.",
137
+ "priority": "highlight",
138
+ "noticeLabel": "Jira edits",
139
+ "notice": "Changes are sent to your connected Jira account and follow its permissions. Jira edits require a supported native build and filesystem; if safe coordination is unavailable, ccdeck refuses the edit and you can still browse your board."
140
+ },
141
+ {
142
+ "title": "📍 Jira moves follow your selection",
143
+ "body": "Drag the issue you select, move completed issues between sprints, and place issues at the end by default.",
144
+ "priority": "highlight"
145
+ },
146
+ {
147
+ "title": "🛠️ Reduced memory use during long sessions",
148
+ "body": "ccdeck releases more unused memory, and Jira edits recover more reliably when a connection is interrupted."
149
+ }
150
+ ],
151
+ "3.50.0": [
152
+ {
153
+ "title": "🤝 Paired decks no longer each read a shared account's usage",
154
+ "body": "No more rate limits from every machine reading it: one deck reads the account and passes the numbers to the others. Hover the reading's age to see which deck read it."
155
+ }
156
+ ],
132
157
  "3.49.0": [
133
158
  {
134
159
  "title": "🗞️ What's new is shorter and easier to scan",
@@ -47,7 +47,8 @@ import { verdictFor, verdictsAskedAt, verdictsNow } from "./claude-verdicts.mjs"
47
47
  export { verdictNow, verdictsNow } from "./claude-verdicts.mjs";
48
48
  // Asking claude-swap to collect, which every roster read does when something is
49
49
  // due, and when each account will next be read.
50
- import { nextReadAt, nudgeCollector } from "./claude-collector.mjs";
50
+ import { heldNow, nextReadAt, nudgeCollector } from "./claude-collector.mjs";
51
+ import { sharedReadingFrom } from "./usage-share.mjs";
51
52
  // Which accounts the deck signed in itself, and the incident one of them is in
52
53
  // (#1893). Pure, and keyed the way LAN sync keys accounts.
53
54
  import { hasRecovered, reauthFor } from "./account-origins.mjs";
@@ -600,6 +601,10 @@ function rosterRow({ activeNum, num, acct, row, identity, now, key, origin = nul
600
601
  // plan alone would promise "next in 15m" while the panel actually
601
602
  // updates in three.
602
603
  nextAt: nextReadAt(row, matches, fetchedAtMs, isActive, now),
604
+ // The paired deck these numbers were read on, while claude-swap holds this
605
+ // account for its readings (usage-share.mjs); null when this deck reads
606
+ // the account itself.
607
+ sharedFrom: matches && heldNow(row, now) ? sharedReadingFrom(key, now) : null,
603
608
  stale: fetchedAtMs == null || now - fetchedAtMs > STALE_AFTER_MS,
604
609
  // Surfaced rather than hidden: a rate-limited or re-login-needed account
605
610
  // is exactly the one the user is about to try switching to.
@@ -750,6 +755,9 @@ export async function activeAccountUsage() {
750
755
  organizationUuid: acct.organizationUuid ?? null,
751
756
  lastGood: row.lastGood,
752
757
  fetchedAt: Math.round(row.fetchedAt * 1000),
758
+ // Until when claude-swap holds this account for a paired deck's readings
759
+ // (usage-share.mjs), in ms, or null.
760
+ heldUntil: observedMs(row.heldUntil),
753
761
  };
754
762
  }
755
763
 
@@ -758,7 +766,11 @@ export async function activeAccountUsage() {
758
766
  * files activeAccountUsage reads, under the same identity guard, and nothing
759
767
  * else — no CLI, no verdicts, no repair. The record of how full each window was
760
768
  * at its reset (quota-close-watch.mjs) reads this on a timer, and a timer must
761
- * not start what a look at the accounts panel does.
769
+ * not start what a look at the accounts panel does. The readings a paired deck
770
+ * is sent (usage-share.mjs) come from here too, with the row's plan: when
771
+ * claude-swap polls it next, how long it is backing off, and how long it is
772
+ * held for another deck's reading — each in ms, or null — and why its last
773
+ * fetch failed, or null.
762
774
  */
763
775
  export async function storedUsageReadings() {
764
776
  const root = backupRoot();
@@ -769,7 +781,11 @@ export async function storedUsageReadings() {
769
781
  const row = rows[num];
770
782
  const fetchedAt = rowIsFor(row, acct) ? observedMs(row.fetchedAt) : null;
771
783
  return row?.lastGood && fetchedAt != null
772
- ? [{ email: acct.email, organizationUuid: acct.organizationUuid ?? "", lastGood: row.lastGood, fetchedAt }]
784
+ ? [{
785
+ email: acct.email, organizationUuid: acct.organizationUuid ?? "", lastGood: row.lastGood, fetchedAt,
786
+ nextPollAt: observedMs(row.nextPollAt), backoffUntil: observedMs(row.backoffUntil), heldUntil: observedMs(row.heldUntil),
787
+ lastError: typeof row.lastError === "string" ? row.lastError : null,
788
+ }]
773
789
  : [];
774
790
  });
775
791
  }
@@ -38,11 +38,22 @@ const FRESH_MIN_AGE_MS = 190_000;
38
38
  // congestion control is deliberately holding back, and so do we.
39
39
  const RECENT_429_MS = 3_600_000;
40
40
 
41
+ /**
42
+ * Whether this row is held for another deck's reading: `cswap import-usage
43
+ * --hold` keeps every claude-swap collector off it until `heldUntil`
44
+ * (usage-share.mjs). Exported for tests.
45
+ */
46
+ export function heldNow(row, now) {
47
+ return typeof row?.heldUntil === "number" && row.heldUntil * 1000 > now;
48
+ }
49
+
41
50
  /**
42
51
  * Whether anything is waiting to be collected.
43
52
  *
44
- * Judged per account that actually exists, and an account counts as waiting in
45
- * three cases:
53
+ * A held row is never waiting: claude-swap will not fetch it, so asking would
54
+ * only spawn a `cswap list` every minute that reads nothing. Otherwise judged
55
+ * per account that actually exists, and an account counts as waiting in three
56
+ * cases:
46
57
  *
47
58
  * - it has no usage row at all;
48
59
  * - it has a row whose fetchedAt is not a number. claude-swap writes a row
@@ -61,6 +72,7 @@ export function collectionDue(rows, slots, now) {
61
72
  for (const slot of slots) {
62
73
  const r = rows[slot];
63
74
  if (!r) return true; // never seen
75
+ if (heldNow(r, now)) continue; // another deck reads it
64
76
  if (typeof r.fetchedAt !== "number") return true; // seen, never fetched
65
77
  if (typeof r.nextPollAt === "number" && r.nextPollAt * 1000 <= now) return true;
66
78
  }
@@ -93,6 +105,7 @@ export function collectionDue(rows, slots, now) {
93
105
  export function freshenAllowed(row, now, recent429Ms = RECENT_429_MS) {
94
106
  if (!row || typeof row.fetchedAt !== "number") return false; // the list path owns this case
95
107
  if (process.env.AGENTS_DECK_NO_FRESHEN === "1") return false;
108
+ if (heldNow(row, now)) return false;
96
109
  if (typeof row.backoffUntil === "number" && row.backoffUntil * 1000 > now) return false;
97
110
  if ((row.consecutiveFailures ?? 0) > 0) return false;
98
111
  if (typeof row.last429At === "number" && now - row.last429At * 1000 < recent429Ms) return false;
@@ -114,6 +127,9 @@ export function freshenDue(row, now, { minAgeMs = FRESH_MIN_AGE_MS, recent429Ms
114
127
  * own freshen tick gets there first. Exported for tests.
115
128
  */
116
129
  export function nextReadAt(row, matches, fetchedAtMs, isActive, now) {
130
+ // Held for another deck's reading: nothing here reads it, so there is no
131
+ // time to promise. The next number arrives with that deck's next poll.
132
+ if (matches && heldNow(row, now)) return null;
117
133
  const planned = matches && typeof row?.nextPollAt === "number"
118
134
  ? Math.round(row.nextPollAt * 1000)
119
135
  : null;
@@ -275,7 +275,7 @@ export async function cswapBin() {
275
275
  * ensureCswap below, whose return value says nothing about which binary the
276
276
  * following twenty account operations will be sent to. See cswap-bin-memo.test.ts.
277
277
  */
278
- export function resetCswapBin() { _bin = null; _probe = null; _refused = null; }
278
+ export function resetCswapBin() { _bin = null; _probe = null; _refused = null; _importsUsage = null; }
279
279
 
280
280
  /** Installed version string, or null when cswap cannot be found. */
281
281
  export async function cswapVersion() {
@@ -290,6 +290,26 @@ export async function cswapVersion() {
290
290
  return versionIn(r);
291
291
  }
292
292
 
293
+ // `cswap import-usage`, which paired decks hand each other's readings to
294
+ // (usage-share.mjs), arrived in claude-swap 0.27.0 (realiti4/claude-swap#352).
295
+ const IMPORT_USAGE_VERSION = "0.27.0";
296
+ // Asked every LAN round, so the answer is kept: a version changes only with an
297
+ // upgrade, and the upgrade calls resetCswapBin.
298
+ const IMPORTS_USAGE_FRESH_MS = 10 * 60_000;
299
+ let _importsUsage = null;
300
+
301
+ /**
302
+ * Whether this claude-swap has `import-usage`. A copy that prints no version
303
+ * ("installed") cannot be shown to have it, so it does not.
304
+ */
305
+ export async function cswapImportsUsage() {
306
+ if (_importsUsage && Date.now() - _importsUsage.at < IMPORTS_USAGE_FRESH_MS) return _importsUsage.can;
307
+ const v = await cswapVersion();
308
+ const can = typeof v === "string" && v !== "installed" && !isOlder(v, IMPORT_USAGE_VERSION);
309
+ _importsUsage = { at: Date.now(), can };
310
+ return can;
311
+ }
312
+
293
313
  /**
294
314
  * Python interpreters that are safe to execute on this machine.
295
315
  *
@@ -370,13 +390,16 @@ async function safePythons() {
370
390
  * probe still decides WHICH of an owner's spellings runs.
371
391
  *
372
392
  * The INSTALL line carries a version specifier and the UPGRADE line carries the
373
- * bare name, which is not an inconsistency: both installers record what they
374
- * were asked for and re-resolve an upgrade against that recorded requirement —
375
- * uv in the tool's `uv-receipt.toml`, pipx in `pipx_metadata.json`'s
376
- * `package_or_url` — and neither `uv tool upgrade` nor `pipx upgrade` accepts a
377
- * specifier in the first place. So the bound set here at install time is the
378
- * bound every later upgrade of that install is resolved inside, and the deck
379
- * states it once, where it is actually read.
393
+ * bare name, because neither `uv tool upgrade` nor `pipx upgrade` accepts a
394
+ * specifier. The two installers then part ways over what was recorded at
395
+ * install time. uv re-resolves an upgrade inside the requirement in its
396
+ * `uv-receipt.toml` — so a copy installed as `claude-swap==0.26.0`, which is
397
+ * what installCswap asks for whenever PyPI answers, is pinned there for good:
398
+ * `uv tool upgrade` prints "Nothing to upgrade" and exits 0, every day. pipx
399
+ * 1.18 upgrades past the `==` in `package_or_url` to the newest release on the
400
+ * index. The uv half is what upgradeInBackground's second step is for; the pipx
401
+ * half is why that step is uv's alone (and why the bound is re-checked on
402
+ * arrival, not trusted to the installer).
380
403
  */
381
404
  async function installers(spec = RANGE_SPEC) {
382
405
  const out = [
@@ -621,35 +644,49 @@ export function cswapInstalling() { return _installing; }
621
644
  * argv sent to a tool that does not own the package is just as invisible as a
622
645
  * wrong argv, and was the longer-lived of the two. Both are now written down.
623
646
  */
624
- function upgradeInBackground({ cmd, upgrade, via }, { from, want }) {
647
+ function upgradeInBackground({ cmd, upgrade, pin, owner, via }, { from, want }) {
625
648
  _upgrade = (async () => {
626
649
  let entry;
627
650
  try {
628
- const r = await run(cmd, upgrade, { timeout: INSTALL_TIMEOUT_MS });
651
+ let r = await run(cmd, upgrade, { timeout: INSTALL_TIMEOUT_MS });
629
652
  // The version read below must be taken AFTER the upgrade, and cswapBin
630
653
  // memoizes the last `--version` it saw for PROBE_FRESH_MS. An upgrade
631
654
  // that finds nothing to do returns in well under those five seconds, so
632
655
  // without this the recorded "to" could be the reading from before the
633
656
  // command ran — the one number this whole function exists to replace.
634
657
  resetCswapBin();
635
- const to = await cswapVersion();
658
+ let to = await cswapVersion();
659
+ // PINNED BY ITS OWN INSTALL. uv keeps an upgrade inside the requirement it
660
+ // recorded, and a deck-installed copy recorded `claude-swap==<exact>` (see
661
+ // installers), so the upgrade above exits 0 with the same version. The
662
+ // install line again, naming the version the daily check just chose, is
663
+ // the move uv's own hint gives. It runs only when the upgrade left the
664
+ // copy behind, so a copy whose receipt has no pin is never given one.
665
+ if (r.ok && owner === "uv" && pin && behind(to, want)) {
666
+ r = await run(cmd, pin, { timeout: INSTALL_TIMEOUT_MS });
667
+ resetCswapBin();
668
+ to = await cswapVersion();
669
+ }
636
670
  entry = {
637
671
  from,
638
672
  want: want ?? null,
639
673
  to,
640
674
  at: new Date().toISOString(),
641
675
  via: via ?? null,
642
- ok: r.ok && typeof to === "string" && (to === "installed" || isAcceptableVersion(to)),
676
+ ok: r.ok && typeof to === "string" && (to === "installed" || isAcceptableVersion(to)) && !behind(to, want),
643
677
  // Why not, when not. An upgrade that exits non-zero and one that lands
644
678
  // a version outside the bound are very different events, and the second
645
679
  // is the one worth a person's attention: the specifier this deck
646
680
  // installs with does not permit it, so something other than that
647
- // specifier decided what to install.
681
+ // specifier decided what to install. The third, an upgrade that exited
682
+ // 0 and moved nothing, used to be recorded as a success.
648
683
  reason: !r.ok
649
684
  ? "command_failed"
650
685
  : (typeof to === "string" && to !== "installed" && !isAcceptableVersion(to))
651
686
  ? "unexpected_version"
652
- : null,
687
+ : behind(to, want)
688
+ ? "not_upgraded"
689
+ : null,
653
690
  detail: r.ok ? null : failureDetail(r, 300),
654
691
  };
655
692
  } catch (e) {
@@ -669,15 +706,20 @@ function upgradeInBackground({ cmd, upgrade, via }, { from, want }) {
669
706
  * claude-swap came from pipx is skipped rather than handed an upgrade it will
670
707
  * refuse. A null owner probes nothing at all: there is no tool here to ask.
671
708
  */
672
- async function findUpgrader(owner) {
709
+ async function findUpgrader(owner, want) {
673
710
  if (!owner) return null;
674
- for (const { cmd, probe, upgrade, via, owner: speaksFor } of await installers()) {
711
+ for (const { cmd, probe, args, upgrade, via, owner: speaksFor } of await installers(`${PKG}==${want}`)) {
675
712
  if (speaksFor !== owner) continue;
676
- if ((await run(cmd, probe, { timeout: 8_000 })).ok) return { cmd, upgrade, via };
713
+ if ((await run(cmd, probe, { timeout: 8_000 })).ok) return { cmd, upgrade, pin: args, owner, via };
677
714
  }
678
715
  return null;
679
716
  }
680
717
 
718
+ /** True when `to` is a version this deck reads and it is still older than `want`. */
719
+ function behind(to, want) {
720
+ return typeof to === "string" && to !== "installed" && typeof want === "string" && isOlder(to, want);
721
+ }
722
+
681
723
  /**
682
724
  * Make sure cswap exists and is reasonably current, installing it if missing.
683
725
  *
@@ -731,7 +773,7 @@ export async function ensureCswap({ onInstalling = null } = {}) {
731
773
  // would then be a sentence printed daily about nothing. When nobody
732
774
  // offered here owns it, "present" is the whole truth and is what gets
733
775
  // said.
734
- const found = await findUpgrader(cswapOwner(await cswapBin()));
776
+ const found = await findUpgrader(cswapOwner(await cswapBin()), latest);
735
777
  if (found) {
736
778
  upgradeInBackground(found, { from: existing, want: latest });
737
779
  return { state: "upgrading", version: existing, latest, via: found.via };
@@ -0,0 +1,37 @@
1
+ // A single comment, with no caller-selected upstream URL, visibility or fields.
2
+ import { errorFromFetchFailure, errorFromStatus, integrationError } from "./errors.mjs";
3
+ import { isSafeTarget, originOf } from "./proxy.mjs";
4
+ const KEY = /^[A-Z][A-Z0-9_]{0,40}-[1-9]\d{0,11}$/;
5
+ export const MAX_COMMENT_LENGTH = 10000;
6
+
7
+ // Cloud API v3 uses ADF; Server/DC API v2 accepts its native text format.
8
+ export function commentBody(text, cloud) {
9
+ if (!cloud) return text;
10
+ return { type: "doc", version: 1, content: text.split("\n").map(line => ({ type: "paragraph", ...(line ? { content: [{ type: "text", text: line }] } : {}) })) };
11
+ }
12
+ export function createJiraComment({ secret, origins, sign, authCheck, fetchImpl = globalThis.fetch, rest, cloud, invalidate }) {
13
+ return async (key, body, signal) => {
14
+ if (!KEY.test(key) || !body || typeof body !== "object" || Array.isArray(body) || Object.keys(body).length !== 1 || typeof body.text !== "string" || !body.text.trim() || body.text.length > MAX_COMMENT_LENGTH) {
15
+ throw integrationError("invalid", "Enter a comment of up to 10,000 characters.");
16
+ }
17
+ const url = `${rest}/issue/${encodeURIComponent(key)}/comment`;
18
+ if (!isSafeTarget(url) || !origins().includes(originOf(url))) throw integrationError("permission", "This Jira write is outside the connection's token origins.");
19
+ const controller = new AbortController();
20
+ const stop = () => controller.abort();
21
+ if (signal?.aborted) stop(); else signal?.addEventListener("abort", stop, { once: true });
22
+ const timer = setTimeout(stop, 15000); timer.unref?.();
23
+ let res;
24
+ try {
25
+ try { res = await fetchImpl(url, { method: "POST", redirect: "manual", headers: { Accept: "application/json", "Content-Type": "application/json", "User-Agent": "ccdeck", ...sign(secret) }, body: JSON.stringify({ body: commentBody(body.text, cloud) }), signal: controller.signal }); }
26
+ catch (err) { const failure = errorFromFetchFailure(err, "Jira"); failure.message = "The comment could not be confirmed. Refresh the issue before sending again."; throw failure; }
27
+ if (res.status >= 300 && res.status < 400) throw integrationError("upstream", "Jira redirected the comment. Refresh the issue before sending again.");
28
+ const refused = authCheck(res.headers, secret);
29
+ if (refused) throw integrationError("expired", refused, { status: 401 });
30
+ if (res.status !== 201) {
31
+ if (!res.ok && res.status < 500) throw errorFromStatus(res.status, res.headers, { label: "Jira" });
32
+ throw integrationError("upstream", "The comment could not be confirmed. Refresh the issue before sending again.");
33
+ }
34
+ return { status: 200, body: { ok: true, issueKey: key } };
35
+ } finally { invalidate(); clearTimeout(timer); signal?.removeEventListener("abort", stop); await res?.body?.cancel().catch(() => {}); }
36
+ };
37
+ }
@@ -14,7 +14,7 @@ const only = (v, keys) => object(v) && Object.keys(v).every(k => keys.includes(k
14
14
  const invalid = message => integrationError("invalid", message);
15
15
 
16
16
  export function parseJiraMove(body) {
17
- if (!only(body, ["issueKey", "issueKeys", "target", "beforeIssue", "afterIssue"]) || Object.hasOwn(body, "issueKey") === Object.hasOwn(body, "issueKeys")) {
17
+ if (!only(body, ["issueKey", "issueKeys", "target", "beforeIssue", "afterIssue", "atEnd"]) || Object.hasOwn(body, "issueKey") === Object.hasOwn(body, "issueKeys")) {
18
18
  throw invalid("Supply either one issueKey or 2–50 ordered issueKeys and a sprint or backlog target.");
19
19
  }
20
20
  const key = value => typeof value === "string" && value === value.trim() && KEY.test(value) ? value : null;
@@ -27,10 +27,10 @@ export function parseJiraMove(body) {
27
27
  !(t.kind === "backlog" || (t.kind === "sprint" && positiveId(t.sprintId)))) throw invalid("Not a valid issue key or move target.");
28
28
  const beforeIssue = Object.hasOwn(body, "beforeIssue") ? key(body.beforeIssue) : undefined;
29
29
  const afterIssue = Object.hasOwn(body, "afterIssue") ? key(body.afterIssue) : undefined;
30
- if (beforeIssue === null || afterIssue === null || (beforeIssue && afterIssue) || issueKeys.includes(beforeIssue) || issueKeys.includes(afterIssue)) {
30
+ if ((Object.hasOwn(body, "atEnd") && body.atEnd !== true) || (body.atEnd && (beforeIssue || afterIssue)) || beforeIssue === null || afterIssue === null || (beforeIssue && afterIssue) || issueKeys.includes(beforeIssue) || issueKeys.includes(afterIssue)) {
31
31
  throw invalid("Use at most one other issue as the rank anchor.");
32
32
  }
33
- return { issueKeys: issueKeys.slice(), batch, target: t.kind === "sprint" ? { kind: "sprint", sprintId: t.sprintId } : { kind: "backlog" }, beforeIssue, afterIssue };
33
+ return { issueKeys: issueKeys.slice(), batch, target: t.kind === "sprint" ? { kind: "sprint", sprintId: t.sprintId } : { kind: "backlog" }, beforeIssue, afterIssue, atEnd: body.atEnd === true };
34
34
  }
35
35
 
36
36
  /** Conservative support, not a claim about the token's write permissions. */
@@ -115,8 +115,8 @@ export function createJiraMover({ secret, origins, sign, authCheck, fetchImpl =
115
115
 
116
116
  return async (boardId, input, signal) => {
117
117
  const move = parseJiraMove(input);
118
- const { issueKeys, batch, target, beforeIssue, afterIssue } = move;
119
- const anchor = beforeIssue ?? afterIssue;
118
+ const { issueKeys, batch, target, beforeIssue, afterIssue, atEnd } = move;
119
+ let anchor = beforeIssue ?? afterIssue;
120
120
  const read = reader(signal);
121
121
  const outcomes = new Map(issueKeys.map(key => [key, { membership: "unchanged", rank: "unchanged" }]));
122
122
  let attempted = false;
@@ -153,8 +153,11 @@ export function createJiraMover({ secret, origins, sign, authCheck, fetchImpl =
153
153
  // Match Jira's issue normalizer, including renamed epic-level types.
154
154
  const type = issue.fields?.issuetype;
155
155
  const epic = type?.hierarchyLevel === 1 || /^epic$/i.test(String(type?.name ?? ""));
156
- if (issueKeys.includes(key) && (epic || !["new", "indeterminate"].includes(issue.fields?.status?.statusCategory?.key))) {
157
- throw invalid("Only unfinished top-level non-epic issues can be moved.");
156
+ if (issueKeys.includes(key) && (epic || !["new", "indeterminate", "done"].includes(issue.fields?.status?.statusCategory?.key))) {
157
+ throw invalid("Only top-level non-epic issues with a known status can be moved.");
158
+ }
159
+ if (issueKeys.includes(key) && target.kind === "backlog" && issue.fields?.status?.statusCategory?.key === "done") {
160
+ throw invalid("Done issues cannot be moved to the backlog because Jira hides them there. Change the status first.");
158
161
  }
159
162
  }
160
163
  const sources = new Map();
@@ -188,6 +191,25 @@ export function createJiraMover({ secret, origins, sign, authCheck, fetchImpl =
188
191
  const found = await readIssues(groupSuffix(group), keys, "issuetype");
189
192
  if (keys.some(key => !found.has(key))) throw invalid("An issue's source changed or is a closed sprint. Refresh the board.");
190
193
  }
194
+ if (atEnd) {
195
+ // Read Jira's full destination order, never a filtered or partial UI list.
196
+ // Jira's board endpoints are rank-ordered by default. Ask for the
197
+ // reverse order and find the first top-level issue outside this batch.
198
+ let complete = false;
199
+ for (let startAt = 0, page = 0; page < 200; page++) {
200
+ const q = new URLSearchParams({ jql: "ORDER BY Rank DESC", fields: "issuetype", startAt: String(startAt), maxResults: "50" });
201
+ const result = await read.json(`${agile}/board/${boardId}/${groupSuffix(target)}?${q}`);
202
+ if (!Array.isArray(result?.issues)) throw invalid("Could not determine the destination's last issue. Refresh and try again.");
203
+ const values = result.issues;
204
+ if (values.some(i => !KEY.test(i?.key ?? "") || typeof i.fields?.issuetype?.subtask !== "boolean")) throw invalid("Could not verify the destination order. Refresh and try again.");
205
+ if (!values.length && Number.isInteger(result.total) && startAt < result.total) throw invalid("Could not verify the destination order. Refresh and try again.");
206
+ const last = values.find(i => KEY.test(i?.key ?? "") && i.fields?.issuetype?.subtask === false && !issueKeys.includes(i.key));
207
+ if (last) { anchor = last.key; complete = true; break; }
208
+ if (result.isLast === true || values.length === 0 || (Number.isInteger(result.total) && startAt + values.length >= result.total)) { complete = true; break; }
209
+ startAt += values.length;
210
+ }
211
+ if (!complete) throw invalid("The destination is too large to determine the last issue. Refresh and try again.");
212
+ }
191
213
  if (anchor && !(await readIssues(groupSuffix(target), [anchor], "issuetype")).has(anchor)) throw invalid("The rank anchor must be in the target group. Refresh the board.");
192
214
  const needed = issueKeys.filter(key => !sameGroup(sources.get(key)));
193
215
  if (needed.length) {
@@ -197,13 +219,17 @@ export function createJiraMover({ secret, origins, sign, authCheck, fetchImpl =
197
219
  await write(suffix, "POST", { issues: needed }, needed, signal);
198
220
  for (const key of needed) outcomes.get(key).membership = "moved";
199
221
  }
222
+ // With no outside anchor, the destination contains only this batch (or
223
+ // is empty). Once membership is set, order the rest after its first item.
224
+ const rankKeys = !anchor && atEnd && issueKeys.length > 1 ? issueKeys.slice(1) : issueKeys;
225
+ if (!anchor && atEnd && rankKeys !== issueKeys) anchor = issueKeys[0];
200
226
  if (anchor) {
201
227
  stage = "rank";
202
228
  attempted = true;
203
- pendingKeys = issueKeys;
204
- await write("issue/rank", "PUT", { issues: issueKeys, rankCustomFieldId: capability.rankCustomFieldId,
205
- ...(beforeIssue ? { rankBeforeIssue: beforeIssue } : { rankAfterIssue: afterIssue }) }, issueKeys, signal);
206
- for (const key of issueKeys) outcomes.get(key).rank = "ranked";
229
+ pendingKeys = rankKeys;
230
+ await write("issue/rank", "PUT", { issues: rankKeys, rankCustomFieldId: capability.rankCustomFieldId,
231
+ ...(beforeIssue ? { rankBeforeIssue: beforeIssue } : { rankAfterIssue: anchor }) }, rankKeys, signal);
232
+ for (const key of rankKeys) outcomes.get(key).rank = "ranked";
207
233
  }
208
234
  return { status: 200, body: { ok: true, ...(batch ? { issueKeys } : { issueKey: issueKeys[0] }), target, refresh: true } };
209
235
  } catch (err) {
@@ -0,0 +1,43 @@
1
+ // A bounded Jira workflow transition. Never accept a URL or arbitrary fields.
2
+ import { errorFromFetchFailure, errorFromStatus, integrationError } from './errors.mjs';
3
+ import { isSafeTarget, originOf } from './proxy.mjs';
4
+
5
+ const keyPattern = /^[A-Z][A-Z0-9_]{0,40}-[1-9]\d{0,11}$/;
6
+ const idPattern = /^[0-9]{1,12}$/;
7
+ export async function jiraTransitions(read, rest, key) {
8
+ if (!keyPattern.test(key)) throw integrationError('invalid', 'Not an issue key.');
9
+ const result = await read.json(`${rest}/issue/${encodeURIComponent(key)}/transitions?expand=transitions.fields`);
10
+ if (!Array.isArray(result?.transitions)) throw integrationError('upstream', 'Jira did not return its available transitions.');
11
+ return result.transitions.slice(0, 100).filter(t => typeof t.id === 'string' && idPattern.test(t.id) && typeof t.name === 'string' && t.name.trim())
12
+ .map(t => ({ id: t.id, name: t.name.slice(0, 120), to: typeof t.to?.name === 'string' ? t.to.name.slice(0, 120) : '',
13
+ requiresScreen: t.hasScreen === true || Object.values(t.fields ?? {}).some(f => f?.required === true) }));
14
+ }
15
+ export function createJiraTransition({ secret, origins, sign, authCheck, fetchImpl = globalThis.fetch, reader, rest, invalidate }) {
16
+ return async (key, body, signal) => {
17
+ if (!keyPattern.test(key) || !body || typeof body !== 'object' || Array.isArray(body) || Object.keys(body).length !== 1 || typeof body.transitionId !== 'string' || !idPattern.test(body.transitionId)) throw integrationError('invalid', 'Choose a valid transition.');
18
+ const choices = await jiraTransitions(reader(signal), rest, key);
19
+ const choice = choices.find(t => t.id === body.transitionId);
20
+ if (!choice || choice.requiresScreen) throw integrationError('invalid', 'This transition is unavailable or requires additional fields in Jira.');
21
+ const url = `${rest}/issue/${encodeURIComponent(key)}/transitions`;
22
+ if (!isSafeTarget(url) || !origins().includes(originOf(url))) throw integrationError('permission', 'This Jira write is outside the connection’s token origins.');
23
+ const controller = new AbortController();
24
+ const stop = () => controller.abort();
25
+ if (signal?.aborted) stop(); else signal?.addEventListener('abort', stop, { once: true });
26
+ const timer = setTimeout(stop, 15000); timer.unref?.();
27
+ let res;
28
+ try {
29
+ try { res = await fetchImpl(url, { method: 'POST', redirect: 'manual', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'User-Agent': 'ccdeck', ...sign(secret) }, body: JSON.stringify({ transition: { id: choice.id } }), signal: controller.signal }); }
30
+ catch (err) { throw errorFromFetchFailure(err, 'Jira'); }
31
+ if (res.status >= 300 && res.status < 400) throw integrationError('upstream', 'Jira redirected the transition. Refresh the issue before trying again.');
32
+ const refused = authCheck(res.headers, secret);
33
+ if (refused) throw integrationError('expired', refused, { status: 401 });
34
+ if (res.status !== 204) {
35
+ if (!res.ok) throw errorFromStatus(res.status, res.headers, { label: 'Jira' });
36
+ throw integrationError('upstream', 'Jira did not confirm the transition. Refresh the issue.');
37
+ }
38
+ return { status: 200, body: { ok: true, issueKey: key } };
39
+ } finally {
40
+ invalidate(); clearTimeout(timer); signal?.removeEventListener('abort', stop); await res?.body?.cancel().catch(() => {});
41
+ }
42
+ };
43
+ }