@stackwright-pro/mcp 0.2.0-alpha.98 → 0.2.0-alpha.99

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/dist/server.mjs CHANGED
@@ -2000,6 +2000,7 @@ function registerOrchestrationTools(server2) {
2000
2000
  // src/tools/pipeline.ts
2001
2001
  import { z as z13 } from "zod";
2002
2002
  import { readFileSync as readFileSync5, writeFileSync as writeFileSync4, existsSync as existsSync5, mkdirSync as mkdirSync4, lstatSync as lstatSync6 } from "fs";
2003
+ import { lockSync } from "proper-lockfile";
2003
2004
  import { join as join5 } from "path";
2004
2005
  import { createHash as createHash3 } from "crypto";
2005
2006
 
@@ -3020,6 +3021,27 @@ function writeState(cwd, state) {
3020
3021
  state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
3021
3022
  safeWriteSync(statePath(cwd), JSON.stringify(state, null, 2) + "\n");
3022
3023
  }
3024
+ function updateStateAtomic(cwd, mutator) {
3025
+ const dir = join5(cwd, ".stackwright");
3026
+ mkdirSync4(dir, { recursive: true });
3027
+ const path4 = statePath(cwd);
3028
+ if (!existsSync5(path4)) {
3029
+ safeWriteSync(path4, JSON.stringify(createDefaultState(), null, 2) + "\n");
3030
+ }
3031
+ const release = lockSync(path4, {
3032
+ realpath: false,
3033
+ stale: 1e4
3034
+ // Treat locks older than 10s as stale (guards against crash mid-lock)
3035
+ });
3036
+ try {
3037
+ const state = readState(cwd);
3038
+ mutator(state);
3039
+ writeState(cwd, state);
3040
+ return state;
3041
+ } finally {
3042
+ release();
3043
+ }
3044
+ }
3023
3045
  function extractJsonFromResponse(text) {
3024
3046
  let cleaned = text;
3025
3047
  cleaned = cleaned.replace(/```(?:json)?\s*/gi, "");
@@ -3095,35 +3117,35 @@ function handleSetPipelineState(input) {
3095
3117
  }
3096
3118
  }
3097
3119
  try {
3098
- const state = readState(cwd);
3099
- if (input.status) {
3100
- state.status = input.status;
3101
- }
3102
- if (input.phase) {
3103
- const phase = input.phase;
3104
- if (!state.phases[phase]) {
3105
- state.phases[phase] = defaultPhaseStatus();
3106
- }
3107
- const phaseState = state.phases[phase];
3108
- if (input.field && input.value !== void 0) {
3109
- phaseState[input.field] = input.value;
3110
- }
3111
- if (input.incrementRetry) {
3112
- phaseState.retryCount += 1;
3120
+ const state = updateStateAtomic(cwd, (state2) => {
3121
+ if (input.status) {
3122
+ state2.status = input.status;
3123
+ }
3124
+ if (input.phase) {
3125
+ const phase = input.phase;
3126
+ if (!state2.phases[phase]) {
3127
+ state2.phases[phase] = defaultPhaseStatus();
3128
+ }
3129
+ const phaseState = state2.phases[phase];
3130
+ if (input.field && input.value !== void 0) {
3131
+ phaseState[input.field] = input.value;
3132
+ }
3133
+ if (input.incrementRetry) {
3134
+ phaseState.retryCount += 1;
3135
+ }
3136
+ state2.currentPhase = phase;
3113
3137
  }
3114
- state.currentPhase = phase;
3115
- }
3116
- if (input.updates && input.updates.length > 0) {
3117
- for (const update of input.updates) {
3118
- if (!state.phases[update.phase]) {
3119
- state.phases[update.phase] = defaultPhaseStatus();
3138
+ if (input.updates && input.updates.length > 0) {
3139
+ for (const update of input.updates) {
3140
+ if (!state2.phases[update.phase]) {
3141
+ state2.phases[update.phase] = defaultPhaseStatus();
3142
+ }
3143
+ const batchPhaseState = state2.phases[update.phase];
3144
+ batchPhaseState[update.field] = update.value;
3145
+ state2.currentPhase = update.phase;
3120
3146
  }
3121
- const batchPhaseState = state.phases[update.phase];
3122
- batchPhaseState[update.field] = update.value;
3123
- state.currentPhase = update.phase;
3124
3147
  }
3125
- }
3126
- writeState(cwd, state);
3148
+ });
3127
3149
  try {
3128
3150
  const completedPhases = Object.entries(state.phases).filter(([, ps]) => ps.artifactWritten).map(([p]) => p);
3129
3151
  emit(
@@ -3338,11 +3360,11 @@ function handleWritePhaseQuestions(input) {
3338
3360
  requiredPackages
3339
3361
  };
3340
3362
  safeWriteSync(filePath, JSON.stringify(payload, null, 2) + "\n");
3341
- const state = readState(cwd);
3342
- if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
3343
- const ps = state.phases[phase];
3344
- ps.questionsCollected = true;
3345
- writeState(cwd, state);
3363
+ updateStateAtomic(cwd, (state) => {
3364
+ if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
3365
+ const ps = state.phases[phase];
3366
+ ps.questionsCollected = true;
3367
+ });
3346
3368
  return {
3347
3369
  text: JSON.stringify({
3348
3370
  success: true,
@@ -4055,11 +4077,11 @@ function _validateArtifactInner(input) {
4055
4077
  signed = true;
4056
4078
  } catch {
4057
4079
  }
4058
- const state = readState(cwd);
4059
- if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
4060
- const ps = state.phases[phase];
4061
- ps.artifactWritten = true;
4062
- writeState(cwd, state);
4080
+ updateStateAtomic(cwd, (state) => {
4081
+ if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
4082
+ const ps = state.phases[phase];
4083
+ ps.artifactWritten = true;
4084
+ });
4063
4085
  const topKeys = Object.keys(artifact).slice(0, 5).join(", ");
4064
4086
  const result = {
4065
4087
  valid: true,
@@ -5724,7 +5746,7 @@ var _checksums = /* @__PURE__ */ new Map([
5724
5746
  ],
5725
5747
  [
5726
5748
  "stackwright-pro-foreman-otter.json",
5727
- "4db4639e618cdd008d86c416bbc88bd4b2a7965e4bfcf01ec54b828f04ccb816"
5749
+ "9cbe27b8193ebec2ea916aee82d8bdc6c811cc64735923f36b93545a8f1f9551"
5728
5750
  ],
5729
5751
  [
5730
5752
  "stackwright-pro-form-wizard-otter.json",
@@ -7209,10 +7231,12 @@ var package_default = {
7209
7231
  "@stackwright/mcp": "0.6.0-alpha.1",
7210
7232
  "@types/js-yaml": "^4.0.9",
7211
7233
  "js-yaml": "^4.2.0",
7234
+ "proper-lockfile": "^4.1.2",
7212
7235
  zod: "^4.4.3"
7213
7236
  },
7214
7237
  devDependencies: {
7215
7238
  "@types/node": "catalog:",
7239
+ "@types/proper-lockfile": "^4.1.4",
7216
7240
  tsup: "catalog:",
7217
7241
  typescript: "catalog:",
7218
7242
  vitest: "catalog:"
@@ -7226,7 +7250,7 @@ var package_default = {
7226
7250
  "test:coverage": "vitest run --coverage"
7227
7251
  },
7228
7252
  name: "@stackwright-pro/mcp",
7229
- version: "0.2.0-alpha.98",
7253
+ version: "0.2.0-alpha.99",
7230
7254
  description: "MCP tools for Stackwright Pro - Data Explorer, Security, ISR, and Dashboard generation",
7231
7255
  license: "SEE LICENSE IN LICENSE",
7232
7256
  main: "./dist/server.js",