@codeyam-editor/codeyam-editor 0.1.5 → 0.1.6

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 (76) hide show
  1. package/npm/cli.js +5 -1
  2. package/npm/cloud.js +1884 -210
  3. package/npm/codesign-plan.js +68 -0
  4. package/npm/empty-project-dir.js +92 -7
  5. package/npm/fleet-add-failure.js +252 -0
  6. package/npm/fleet-asset-version.js +37 -0
  7. package/npm/fleet-auth-health.js +143 -5
  8. package/npm/fleet-build-data.js +60 -5
  9. package/npm/fleet-cleanup.js +114 -9
  10. package/npm/fleet-destroy-safety.js +230 -13
  11. package/npm/fleet-early-roster.js +87 -0
  12. package/npm/fleet-effect-poll.js +110 -0
  13. package/npm/fleet-env.js +86 -0
  14. package/npm/fleet-ghcr-secret.js +129 -0
  15. package/npm/fleet-git-maintenance.js +142 -0
  16. package/npm/fleet-host-op-limiter.js +68 -0
  17. package/npm/fleet-iap-token.js +165 -0
  18. package/npm/fleet-live-status.js +40 -8
  19. package/npm/fleet-memory.js +245 -9
  20. package/npm/fleet-plans.js +98 -4
  21. package/npm/fleet-pool.js +75 -16
  22. package/npm/fleet-prewarm.js +87 -11
  23. package/npm/fleet-project-drift.js +58 -0
  24. package/npm/fleet-public-url.js +234 -0
  25. package/npm/fleet-queue.js +58 -1
  26. package/npm/fleet-reachability-debounce.js +69 -0
  27. package/npm/fleet-reachability.js +80 -0
  28. package/npm/fleet-reset.js +32 -0
  29. package/npm/fleet-running-plan.js +85 -0
  30. package/npm/fleet-session-token-cache.js +65 -0
  31. package/npm/fleet-setup-steps.js +19 -12
  32. package/npm/fleet-status-refs.js +96 -0
  33. package/npm/fleet-strand.js +39 -8
  34. package/npm/fleet-stuck-status.js +13 -7
  35. package/npm/fleet-vm-access.js +170 -0
  36. package/npm/fleet-vm-probe-target.js +282 -0
  37. package/npm/fleet-vm-readiness.js +136 -3
  38. package/npm/google-ingress.js +15 -0
  39. package/npm/ingress-invoke.js +478 -0
  40. package/npm/launch-config.js +182 -6
  41. package/npm/scenario-check.js +282 -10
  42. package/npm/scenario-handlers.js +85 -27
  43. package/npm/scenario-interactivity.js +145 -6
  44. package/npm/scenario-issues.js +13 -1
  45. package/npm/scenario-mocks.js +129 -26
  46. package/npm/scenario-playwright.js +286 -12
  47. package/npm/script-drift.js +72 -1
  48. package/npm/utils.js +37 -3
  49. package/package.json +5 -5
  50. package/ui/dist/assets/{ContainerInspector-D7VZkkaj.js → ContainerInspector-DgM0pTAx.js} +1 -1
  51. package/ui/dist/assets/EditorShell-B7Q06uJ_.js +252 -0
  52. package/ui/dist/assets/EditorShell-DP5UY20G.css +1 -0
  53. package/ui/dist/assets/{Markdown-BoLHHFXH.js → Markdown-Chgdf3PW.js} +1 -1
  54. package/ui/dist/assets/ProjectLauncherScreen-BRrEr8Ng.js +1 -0
  55. package/ui/dist/assets/ScenarioDataPanel-BeQfa28g.js +9 -0
  56. package/ui/dist/assets/{ScenarioDataPanel-DYP7pi_n.css → ScenarioDataPanel-C1LukYI6.css} +1 -1
  57. package/ui/dist/assets/{ScenarioDataPanelFullPage-CBLTGC4-.js → ScenarioDataPanelFullPage-BLqRCxQX.js} +1 -1
  58. package/ui/dist/assets/ScenarioRenderer-CIAxfHPh.js +21 -0
  59. package/ui/dist/assets/{StepsSimulator-BFldWyoX.js → StepsSimulator-CymGgfbu.js} +1 -1
  60. package/ui/dist/assets/index-BygCiJSb.css +1 -0
  61. package/ui/dist/assets/{index-QsOiOG9x.js → index-DCHqRrwO.js} +4 -4
  62. package/ui/dist/assets/{markdown-v0F0UEt3.js → markdown-C9tbsVHX.js} +1 -1
  63. package/ui/dist/assets/react-nrLBr15I.js +28 -0
  64. package/ui/dist/assets/{useEvents-DHkLJZR4.js → useEvents-S3Qk1Y_d.js} +1 -1
  65. package/ui/dist/assets/useServerIdentity-B7rI0u3O.js +1 -0
  66. package/ui/dist/index.html +4 -4
  67. package/ui/dist/open-source/codeyam-counter.png +0 -0
  68. package/ui/dist/open-source/el-carot.png +0 -0
  69. package/ui/dist/open-source/tabcommand.png +0 -0
  70. package/ui/dist/assets/EditorShell-DHhIaotd.css +0 -1
  71. package/ui/dist/assets/EditorShell-r-796N_W.js +0 -191
  72. package/ui/dist/assets/ProjectLauncherScreen-Ck-XWkQN.js +0 -1
  73. package/ui/dist/assets/ScenarioDataPanel-B9iDSUpA.js +0 -5
  74. package/ui/dist/assets/ScenarioRenderer-BhLfT-nX.js +0 -21
  75. package/ui/dist/assets/index-CIXZkwfB.css +0 -1
  76. package/ui/dist/assets/react-CSS0HapR.js +0 -28
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ // Pure helpers for scripts/package-mcpb.js's darwin code-signing step.
3
+ //
4
+ // Dependency-free and unit-tested (npm/codesign-plan.test.js) so the packaging
5
+ // script keeps the sign decision + argv rendering out of its execSync path:
6
+ // signDarwinBinary stays thin boundary glue while every branch of "do we sign,
7
+ // and with which command" is exercised here without invoking codesign.
8
+
9
+ /**
10
+ * The `codesign` argv for a Developer ID signature with a secure timestamp.
11
+ * Pure — takes the identity and binary path, returns the flag list. `--force`
12
+ * replaces cargo's ad-hoc signature (codesign refuses an already-signed binary
13
+ * otherwise); `--timestamp` embeds the secure timestamp a later notarization
14
+ * needs.
15
+ */
16
+ function codesignArgs(identity, binaryPath) {
17
+ return ["--force", "--timestamp", "--sign", identity, binaryPath];
18
+ }
19
+
20
+ /**
21
+ * The shell-quoted `codesign …` command string for signing `binaryPath` with
22
+ * `identity`. Pure: quotes each argv element so a path or identity with spaces
23
+ * survives the shell.
24
+ */
25
+ function codesignCommand(identity, binaryPath) {
26
+ const quoted = codesignArgs(identity, binaryPath)
27
+ .map((a) => `"${a}"`)
28
+ .join(" ");
29
+ return `codesign ${quoted}`;
30
+ }
31
+
32
+ /**
33
+ * Decide whether/how to sign the staged darwin binary, given the target
34
+ * `platform`, the configured Developer ID `identity`, the `hostPlatform`
35
+ * (process.platform), and a `serverLabel` for the warning text. Pure — no I/O,
36
+ * no env, no clock — so the decision and its warnings are unit-testable.
37
+ *
38
+ * Returns `{ action: "sign", identity }` when a real Developer ID signature is
39
+ * possible, otherwise `{ action: "skip", warning? }`: the non-darwin target is a
40
+ * silent skip (its binary is not Mach-O), while a missing identity or a
41
+ * non-macOS host skips WITH a warning so an unsigned local bundle stays testable
42
+ * on the machine that built it rather than failing the build.
43
+ */
44
+ function signPlan({ platform, identity, hostPlatform, serverLabel }) {
45
+ if (platform !== "darwin") {
46
+ return { action: "skip" };
47
+ }
48
+ if (!identity) {
49
+ return {
50
+ action: "skip",
51
+ warning:
52
+ `⚠️ ${serverLabel} is ad-hoc signed — set MCPB_SIGN_IDENTITY (or ` +
53
+ `APPLE_SIGNING_IDENTITY) to a Developer ID identity to sign it. An unsigned ` +
54
+ `binary has no stable Keychain identity and re-prompts for access.`,
55
+ };
56
+ }
57
+ if (hostPlatform !== "darwin") {
58
+ return {
59
+ action: "skip",
60
+ warning:
61
+ `⚠️ cannot codesign ${serverLabel} on ${hostPlatform} — ` +
62
+ `sign the darwin binary on a macOS host.`,
63
+ };
64
+ }
65
+ return { action: "sign", identity };
66
+ }
67
+
68
+ module.exports = { codesignArgs, codesignCommand, signPlan };
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  /**
4
- * Launcher-side mirror of `is_empty_project_dir` in
4
+ * Launcher-side mirrors of `is_empty_project_dir` and
5
+ * `looks_like_onboardable_project` in
5
6
  * `crates/codeyam-editor/src/commands/init.rs`. The Rust side decides
6
- * which `/codeyam-…` skill the init binary points at; this JS mirror
7
- * decides the same for the launcher's post-launch tail banner. Keep
8
- * both in sync — the test `empty-project-dir.test.js` and Rust's
9
- * `is_empty_project_dir_ignores_hidden_entries` /
10
- * `is_empty_project_dir_detects_visible_entry` pin the contract.
7
+ * which `/codeyam-…` skill the init binary points at; these JS mirrors
8
+ * decide the same for the launcher's post-launch tail banner. Keep both
9
+ * predicates in sync with Rust — the test `empty-project-dir.test.js`
10
+ * and Rust's `is_empty_project_dir_*` / `looks_like_onboardable_project_*`
11
+ * tests pin the contracts.
11
12
  *
12
13
  * A "fresh" project directory has no non-hidden entries — only things
13
14
  * like `.git/`, `.gitignore`, or other dotfiles. Hidden entries don't
@@ -19,6 +20,7 @@
19
20
  */
20
21
 
21
22
  const fs = require("node:fs");
23
+ const path = require("node:path");
22
24
 
23
25
  function isEmptyProjectDir(projectDir) {
24
26
  let entries;
@@ -30,4 +32,87 @@ function isEmptyProjectDir(projectDir) {
30
32
  return entries.every((name) => name.startsWith("."));
31
33
  }
32
34
 
33
- module.exports = { isEmptyProjectDir };
35
+ // Root files that signal a real project: dependency/build manifests,
36
+ // lockfiles, and the static-site `index.html`. Mirror of the Rust
37
+ // `MANIFEST_MARKERS` list.
38
+ const MANIFEST_MARKERS = new Set([
39
+ "package.json",
40
+ "Cargo.toml",
41
+ "pyproject.toml",
42
+ "requirements.txt",
43
+ "setup.py",
44
+ "go.mod",
45
+ "Gemfile",
46
+ "pom.xml",
47
+ "build.gradle",
48
+ "build.gradle.kts",
49
+ "composer.json",
50
+ "pubspec.yaml",
51
+ "Package.swift",
52
+ "mix.exs",
53
+ "deno.json",
54
+ "CMakeLists.txt",
55
+ "Makefile",
56
+ "tsconfig.json",
57
+ "index.html",
58
+ ]);
59
+
60
+ // Subdirectories that signal an organized source tree. Mirror of the Rust
61
+ // `SOURCE_DIR_MARKERS` list.
62
+ const SOURCE_DIR_MARKERS = new Set([
63
+ "src",
64
+ "app",
65
+ "lib",
66
+ "pages",
67
+ "components",
68
+ "crates",
69
+ "packages",
70
+ "source",
71
+ "include",
72
+ ]);
73
+
74
+ /**
75
+ * Does this directory contain a *project* worth onboarding, as opposed to
76
+ * being empty or holding only a stray file or two? Mirror of Rust
77
+ * `looks_like_onboardable_project`. A folder "contains a project" when it
78
+ * holds a recognized manifest / lockfile, a `.csproj` / `.xcodeproj`, a root
79
+ * `index.html`, OR an organized source subdirectory. Intentionally
80
+ * marker-based, not file-count based: a home dir full of loose files is still
81
+ * not a project. A read error returns false (not a project → the
82
+ * auto-init/open path), matching Rust's `Err(_) => false`.
83
+ */
84
+ function looksLikeOnboardableProject(projectDir) {
85
+ let entries;
86
+ try {
87
+ entries = fs.readdirSync(projectDir, { withFileTypes: true });
88
+ } catch {
89
+ return false;
90
+ }
91
+ for (const entry of entries) {
92
+ const name = entry.name;
93
+ if (MANIFEST_MARKERS.has(name)) {
94
+ return true;
95
+ }
96
+ if (name.endsWith(".csproj") || name.endsWith(".xcodeproj")) {
97
+ return true;
98
+ }
99
+ // Source-tree markers only count as directories, not like-named files.
100
+ if (SOURCE_DIR_MARKERS.has(name)) {
101
+ let isDir = entry.isDirectory();
102
+ // A symlinked source dir surfaces as a symlink Dirent; resolve it.
103
+ if (!isDir && entry.isSymbolicLink()) {
104
+ try {
105
+ isDir = fs.statSync(path.join(projectDir, name)).isDirectory();
106
+ } catch {
107
+ isDir = false;
108
+ }
109
+ }
110
+ if (isDir) {
111
+ return true;
112
+ }
113
+ }
114
+ }
115
+ return false;
116
+ }
117
+
118
+ module.exports = { isEmptyProjectDir, looksLikeOnboardableProject };
@@ -0,0 +1,252 @@
1
+ 'use strict';
2
+
3
+ const fc = require('./fleet-cleanup');
4
+ const { parseRosterMarkers } = require('./fleet-early-roster');
5
+
6
+ // npm/fleet-add-failure.js — pure classifier for a FAILED fleet-dashboard `add`
7
+ // provision. Before this, every failed add rendered an identical red "add error"
8
+ // badge whose only action was "Clear badge", and a restart mid-add collapsed the
9
+ // message to a content-free `(re-attached after restart — detached provision
10
+ // exited 1)`. The real cause — captured to the provision transcript on disk — was
11
+ // thrown away. This happened live with VM9/VM10: both aborted at the streamed-
12
+ // script drift guard because a bootstrap script had uncommitted local edits, but
13
+ // the operator saw only "exited 1" and had to dig through /tmp/dash-add-vm-N.log.
14
+ //
15
+ // classifyAddFailure turns a transcript tail + exit code into a differentiated,
16
+ // ACTIONABLE verdict: a plain-language headline, a concrete recovery instruction,
17
+ // and — crucially — a `retryable` flag that is true ONLY where a one-click retry
18
+ // provably cannot orphan or duplicate a GCP box: either nothing was provisioned,
19
+ // or the remaining work is re-entrant so the retry converges on the existing VM.
20
+ // Both grounds are spelled out on ADD_FAILURE_RETRYABLE below. The decision logic
21
+ // lives here as a pure module (like fleet-job-badge.js::canClearBadge) so the
22
+ // whole failure matrix is unit-tested without a live VM; server.js is the thin
23
+ // I/O shell that gathers the transcript and turns the verdict into a card + a
24
+ // server-re-guarded retry action.
25
+
26
+ // The SINGLE source of truth for which categories are safe to auto-retry.
27
+ // `retryable` on every returned verdict is stamped from this Set, so the
28
+ // invariant `retryable === has(category)` holds by construction and the server
29
+ // can re-guard a retry against the same Set.
30
+ //
31
+ // A category earns membership on EITHER of two grounds — both of which
32
+ // guarantee a one-click retry cannot silently orphan or duplicate a GCP box:
33
+ //
34
+ // 1. NOTHING WAS PROVISIONED. The classifier can prove no cloud resource was
35
+ // created (`preflight-drift` aborts before the first gcloud call;
36
+ // `instance-vanished` confirms the instance is gone). Retry starts clean.
37
+ //
38
+ // 2. THE REMAINING WORK IS RE-ENTRANT. A real VM exists, but every step the
39
+ // retry would re-run is skip-on-exists or re-attaching, so the retry
40
+ // CONVERGES on the existing box instead of building a second one.
41
+ // `project-bootstrap-timeout` is this shape: the VM is up and its detached
42
+ // bootstrap is still running, `ensureInstance` reuses the live instance,
43
+ // `ensureBootstrapped` skips on the present image, and
44
+ // `ensureProjectBootstrapped` re-attaches to the in-flight install rather
45
+ // than starting a second `npm install` over the first.
46
+ //
47
+ // Ground 2 is deliberately narrow — it is NOT "the VM probably still works".
48
+ // `container-stuck` and `incomplete-workspace` also leave a live VM, but their
49
+ // remaining work is NOT provably re-entrant, so they stay non-retryable.
50
+ const ADD_FAILURE_RETRYABLE = new Set([
51
+ 'preflight-drift',
52
+ 'instance-vanished',
53
+ 'project-bootstrap-timeout',
54
+ ]);
55
+
56
+ // Collect the ` - <path>` bullets the drift guard prints AFTER the "following
57
+ // files differ" header (see npm/cloud.js), stopping at the first non-bullet line
58
+ // so an unrelated "- " elsewhere in the transcript can't leak in. Returns [] when
59
+ // no drift block is present.
60
+ function extractDriftFiles(logTail) {
61
+ const lines = String(logTail || '').split('\n');
62
+ const files = [];
63
+ let inBlock = false;
64
+ for (const line of lines) {
65
+ if (!inBlock) {
66
+ if (/following files differ/i.test(line)) inBlock = true;
67
+ continue;
68
+ }
69
+ const m = line.match(/^\s+-\s+(.+?)\s*$/);
70
+ if (m) { files.push(m[1]); continue; }
71
+ break; // first non-bullet after the header ends the block
72
+ }
73
+ return files;
74
+ }
75
+
76
+ // Pure transform: the last `maxLines` non-empty lines of a transcript, each
77
+ // right-trimmed. Extracted from readProvisionTail (server.js) so the aggregation
78
+ // is unit-tested and that function stays a thin filesystem-boundary call. Returns
79
+ // '' for empty/whitespace-only input.
80
+ function lastNonEmptyLines(text, maxLines = 50) {
81
+ const lines = String(text || '')
82
+ .split('\n')
83
+ .map((l) => l.replace(/\s+$/, ''))
84
+ .filter((l) => l.length > 0)
85
+ .slice(-maxLines);
86
+ return lines.join('\n');
87
+ }
88
+
89
+ // True iff the provision transcript reached the early-roster marker (`CY_ROSTER
90
+ // <n>`) — i.e. the instance exists and the container gate passed, so the VM is
91
+ // rostered. Reuses parseRosterMarkers (npm/fleet-early-roster.js) so the
92
+ // `CY_ROSTER` grammar has a single owner rather than a second inlined regex. Any
93
+ // valid marker means "rostered"; the specific VM number is irrelevant here — a
94
+ // provision transcript only ever carries its own VM's marker. Never throws.
95
+ function transcriptRostered(logTail) {
96
+ return parseRosterMarkers(String(logTail || '')).length > 0;
97
+ }
98
+
99
+ // Build a verdict, stamping `retryable` from the single-source-of-truth Set so it
100
+ // can never drift from the category.
101
+ function buildFailureVerdict(category, headline, recovery, extra) {
102
+ const out = { category, headline, recovery, retryable: ADD_FAILURE_RETRYABLE.has(category) };
103
+ if (extra && extra.files) out.files = extra.files;
104
+ return out;
105
+ }
106
+
107
+ // Classify a failed add from its transcript tail + exit code.
108
+ //
109
+ // logTail the last lines of the provision transcript (string; '' when the
110
+ // log was unreadable — must never throw)
111
+ // exitCode the provision's exit code (number; used for signal-kill detection)
112
+ //
113
+ // Returns { category, headline, recovery, retryable, files? }.
114
+ //
115
+ // Detection is ORDER-SENSITIVE. The provision shell echoes cloud:up's tail, so a
116
+ // drift / instance-vanished / container-stuck transcript ALSO contains the
117
+ // generic `cloud:up FAILED (exit N)` line. Each specific (and every retryable)
118
+ // signature is therefore tested BEFORE the generic cloud-up-failed signature, or
119
+ // a retryable drift would misclassify as a non-retryable cloud:up failure and the
120
+ // operator would lose the safe one-click recovery.
121
+ function classifyAddFailure({ logTail, exitCode } = {}) {
122
+ const log = String(logTail || '');
123
+
124
+ // 1. preflight-drift — the streamed-script drift guard aborted BEFORE any
125
+ // gcloud call, so nothing was provisioned. Retryable once the file is fixed.
126
+ // We match the unambiguous abort header / verdict label, NOT the bare
127
+ // `CODEYAM_SKIP_SCRIPT_DRIFT_CHECK` token: that token ALSO appears in the
128
+ // "bypass active — skipping drift check" warning, so keying on it would
129
+ // misclassify a bypass-active add that later failed for a real reason as a
130
+ // (retryable!) drift — inviting an unsafe retry. The header below is printed
131
+ // only on a genuine drift abort.
132
+ if (/Streamed scripts carry unreviewed local content/i.test(log)
133
+ || /UNCOMMITTED LOCAL EDITS/.test(log)) {
134
+ const files = extractDriftFiles(log);
135
+ const fileList = files.length ? files.join(', ') : 'the streamed scripts';
136
+ const fix = files.length
137
+ ? `Commit & push them, or discard with \`git checkout -- ${files.join(' ')}\`, then Retry add.`
138
+ : 'Commit & push them, or discard the local edits, then Retry add.';
139
+ return buildFailureVerdict('preflight-drift', 'Blocked by local edits',
140
+ `Uncommitted local edits in ${fileList} tripped the streamed-script drift guard, which aborts before any cloud resource is created. ${fix}`,
141
+ { files });
142
+ }
143
+
144
+ // 2. instance-vanished — the GCP instance is confirmed gone; nothing to orphan.
145
+ if (/instance .* is gone/i.test(log)) {
146
+ return buildFailureVerdict('instance-vanished', 'Instance never came up',
147
+ 'The GCP instance is gone — provisioning failed before the container started, so nothing was left behind. Retrying the add is safe.');
148
+ }
149
+
150
+ // 3. project-bootstrap-timeout — the VM came up and its DETACHED project
151
+ // bootstrap is still running; we merely stopped waiting on it. This is the
152
+ // VM-8 / six-self-host-VM incident: a heavy `npm install` (a ~293 MB
153
+ // playwright postinstall, a large `git clone`) outran a local budget, the
154
+ // SIGTERM'd gcloud child returned `status: null`, and the abort path read
155
+ // that as a broken bootstrap script and DELETED A COMPLETELY HEALTHY VM.
156
+ //
157
+ // Retryable on re-entrancy grounds (see ADD_FAILURE_RETRYABLE): the retry
158
+ // re-attaches to the in-flight install rather than starting a second one.
159
+ // Tested BEFORE cloud-up-failed because the provision shell echoes cloud:up's
160
+ // tail, so this transcript ALSO carries the generic `cloud:up FAILED (exit N)`
161
+ // line — matching that first would strip the safe recovery and steer the
162
+ // operator to destroy a healthy, still-provisioning VM. The signature is the
163
+ // wording ensureProjectBootstrapped (npm/cloud.js) throws for both its
164
+ // overall-deadline and its launch-budget timeouts.
165
+ if (/project bootstrap exceeded the local/i.test(log)) {
166
+ return buildFailureVerdict('project-bootstrap-timeout', 'Still installing — we stopped waiting',
167
+ 'The VM provisioned fine and its project bootstrap is still running on it; only the local wait budget elapsed. Nothing is broken and nothing was left half-built. Retry the add to re-attach to the running install — each bootstrap step is skip-on-exists. Do NOT destroy this VM.');
168
+ }
169
+
170
+ // 4. container-stuck — the instance exists but the editor container never
171
+ // became healthy, so a half-provisioned box may exist. Not retryable.
172
+ if (/container never came up/i.test(log)) {
173
+ return buildFailureVerdict('container-stuck', 'Container never became healthy',
174
+ 'The instance came up but the editor container never became healthy — it may be half-provisioned. Reconcile or destroy this VM before re-adding.');
175
+ }
176
+
177
+ // 5. incomplete-workspace — the container came up but the project was never
178
+ // scaffolded: no `.codeyam/editor.json` exists under ~/projects on the VM,
179
+ // so the greenfield `init` did not complete onboarding. This is specific
180
+ // and more actionable than the generic cloud-up-failed below, so it is
181
+ // tested first. The VM exists and is half-provisioned, so it is NOT
182
+ // auto-retryable — reconcile finishes the scaffold, then re-add.
183
+ if (/no \.codeyam\/editor\.json found under ~\/projects/i.test(log)) {
184
+ return buildFailureVerdict('incomplete-workspace', 'Workspace never scaffolded',
185
+ 'The container came up but the project was never scaffolded (no .codeyam/editor.json on the VM), so provisioning did not finish onboarding. Reconcile this VM to complete the scaffold, then re-add.');
186
+ }
187
+
188
+ // 6. cloud-up-failed — a generic cloud:up failure, reached ONLY when the drift /
189
+ // vanished / stuck signatures above did not match. A partial instance may
190
+ // exist, so not retryable.
191
+ if (/cloud:up FAILED \(exit/i.test(log)) {
192
+ return buildFailureVerdict('cloud-up-failed', 'Provisioning failed',
193
+ 'cloud:up failed during provisioning, so a partial instance may exist. Reconcile or destroy this VM before re-adding.');
194
+ }
195
+
196
+ // 7. interrupted — a signal kill (OOM 137, SIGTERM 143, …) or an explicit
197
+ // Killed / out-of-memory marker. The real VM state is unknown. Not retryable.
198
+ if (fc.isSignalKillExit(Number(exitCode)) || /\bKilled\b/.test(log) || /Out of memory/i.test(log)) {
199
+ return buildFailureVerdict('interrupted', 'Provisioning interrupted',
200
+ 'The provision was interrupted (killed or out of memory), so the VM state is unknown. Reconcile or destroy this VM before re-adding.');
201
+ }
202
+
203
+ // 8. converging — the add reached the early-roster marker (`CY_ROSTER`): the
204
+ // container gate passed, the instance is real, and the VM is rostered, yet it
205
+ // exited non-zero WITHOUT matching any specific hard-failure signature above.
206
+ // By construction of the provision script, every genuine hard failure (drift,
207
+ // instance-vanished, container-stuck, incomplete-workspace, cloud-up-failed,
208
+ // interrupted) is printed BEFORE `CY_ROSTER`, so a rostered transcript that
209
+ // fell through to here is a still-wiring box owned by the detached
210
+ // wire-add-tail / reconcile-ingress — NOT an add failure. Surface it as an
211
+ // honest in-flight state instead of the scary red `unknown`. Not retryable:
212
+ // the VM exists and its detached wiring owns finishing it, so a one-click
213
+ // retry could duplicate/orphan a live box. Tested LAST so a hard-failure
214
+ // signature (all printed pre-roster) always wins — `converging` can never
215
+ // shadow a proven failure.
216
+ if (transcriptRostered(log)) {
217
+ return buildFailureVerdict('converging', 'Add still converging',
218
+ 'The container is up and the VM is rostered; the LB ingress is still wiring in the background. This resolves on its own once the editor is reachable over the LB — no action needed unless it persists past the wiring deadline.');
219
+ }
220
+
221
+ // 9. unknown — fallback. Never invite an unproven retry.
222
+ return buildFailureVerdict('unknown', 'Add failed',
223
+ 'The add failed for an unclassified reason — inspect the transcript below, then reconcile or destroy this VM before re-adding.');
224
+ }
225
+
226
+ // Pure guard for the operator "Retry add" action: given a VM number and its
227
+ // carried job, decide whether a one-click retry is SAFE. Retry is allowed ONLY
228
+ // for a terminal add-error whose classifier verdict is retryable (a category
229
+ // where nothing was provisioned). Returns { ok, reason } — reason is a stable
230
+ // code the server shell (actionRetryAdd) maps to an operator message. Mirrors
231
+ // fleet-job-badge.js::canClearBadge so the handler stays a thin I/O shell and the
232
+ // safety decision is unit-tested without a live dashboard.
233
+ function canRetryAdd({ n, job } = {}) {
234
+ if (!Number.isInteger(n) || n < 1) return { ok: false, reason: 'invalid-vm' };
235
+ if (!job || job.action !== 'add' || job.state !== 'error') return { ok: false, reason: 'no-failed-add' };
236
+ if (!job.retryable) return { ok: false, reason: 'not-retryable' };
237
+ return { ok: true, reason: null };
238
+ }
239
+
240
+ // Pure badge-hold predicate for deriveStatus (server.js): hold the calm in-flight
241
+ // `add-converging` card — instead of the red add-failed — ONLY when the add was
242
+ // classified `converging` AND its detached first-wiring is still in flight. Once
243
+ // the wire-add-tail fails/deadlines (`addTailFailed`) or is gone (`addTailInflight`
244
+ // false), or the category is anything else, return false so the caller falls
245
+ // through to the red add-failed status — the operator-chosen escalation. Kept pure
246
+ // (like canRetryAdd / canClearBadge) so the badge decision is unit-tested without a
247
+ // live dashboard.
248
+ function holdConvergingBadge({ category, addTailInflight, addTailFailed } = {}) {
249
+ return category === 'converging' && !!addTailInflight && !addTailFailed;
250
+ }
251
+
252
+ module.exports = { classifyAddFailure, extractDriftFiles, lastNonEmptyLines, canRetryAdd, transcriptRostered, holdConvergingBadge, ADD_FAILURE_RETRYABLE };
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+ // Pure content-hash UI versioning for the fleet dashboard's cache-busting
3
+ // (vm: Honest VM Card Display + Dashboard Cache-Busting).
4
+ //
5
+ // The dashboard serves its single-file UI (public/index.html) with `no-store`,
6
+ // so a hard-refresh always fetches the new code — but an already-OPEN tab never
7
+ // refetches the HTML and silently runs the pre-restart UI until the operator
8
+ // manually reloads. To fix that, the server stamps a short content hash of the
9
+ // served HTML into every /data response; the client records the version it
10
+ // booted with and `location.reload()`s on a mismatch, so a dashboard restart
11
+ // with new UI reaches an open tab automatically.
12
+ //
13
+ // This module is the PURE half — a deterministic hash of the HTML string, no
14
+ // I/O — mirroring the pure/impure split the other fleet-* modules follow
15
+ // (server.js owns reading the file; this owns turning bytes into a version).
16
+ // Unit-tested in npm/fleet-asset-version.test.js.
17
+ //
18
+ // Stack note: this is fleet-operator dashboard infrastructure (the GCE fleet
19
+ // that runs codeyam-editor itself). A project that never runs the dashboard
20
+ // never reaches it.
21
+ const crypto = require('crypto');
22
+
23
+ // computeAssetVersion returns a stable, short (12 hex chars) fingerprint of the
24
+ // served UI. Same HTML in ⇒ same version out (so an unchanged deploy never
25
+ // spuriously reloads open tabs); any byte change ⇒ a different version (so a
26
+ // real UI change always reloads them). 12 hex chars of SHA-1 is ample to make
27
+ // an accidental collision between two distinct UI builds negligible while
28
+ // keeping the badge short.
29
+ function computeAssetVersion(html) {
30
+ return crypto
31
+ .createHash('sha1')
32
+ .update(String(html == null ? '' : html))
33
+ .digest('hex')
34
+ .slice(0, 12);
35
+ }
36
+
37
+ module.exports = { computeAssetVersion };