@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.js CHANGED
@@ -2024,6 +2024,7 @@ function registerOrchestrationTools(server2) {
2024
2024
  // src/tools/pipeline.ts
2025
2025
  var import_zod13 = require("zod");
2026
2026
  var import_fs6 = require("fs");
2027
+ var import_proper_lockfile = require("proper-lockfile");
2027
2028
  var import_path6 = require("path");
2028
2029
  var import_crypto3 = require("crypto");
2029
2030
 
@@ -3016,6 +3017,27 @@ function writeState(cwd, state) {
3016
3017
  state.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
3017
3018
  safeWriteSync(statePath(cwd), JSON.stringify(state, null, 2) + "\n");
3018
3019
  }
3020
+ function updateStateAtomic(cwd, mutator) {
3021
+ const dir = (0, import_path6.join)(cwd, ".stackwright");
3022
+ (0, import_fs6.mkdirSync)(dir, { recursive: true });
3023
+ const path4 = statePath(cwd);
3024
+ if (!(0, import_fs6.existsSync)(path4)) {
3025
+ safeWriteSync(path4, JSON.stringify(createDefaultState(), null, 2) + "\n");
3026
+ }
3027
+ const release = (0, import_proper_lockfile.lockSync)(path4, {
3028
+ realpath: false,
3029
+ stale: 1e4
3030
+ // Treat locks older than 10s as stale (guards against crash mid-lock)
3031
+ });
3032
+ try {
3033
+ const state = readState(cwd);
3034
+ mutator(state);
3035
+ writeState(cwd, state);
3036
+ return state;
3037
+ } finally {
3038
+ release();
3039
+ }
3040
+ }
3019
3041
  function extractJsonFromResponse(text) {
3020
3042
  let cleaned = text;
3021
3043
  cleaned = cleaned.replace(/```(?:json)?\s*/gi, "");
@@ -3091,35 +3113,35 @@ function handleSetPipelineState(input) {
3091
3113
  }
3092
3114
  }
3093
3115
  try {
3094
- const state = readState(cwd);
3095
- if (input.status) {
3096
- state.status = input.status;
3097
- }
3098
- if (input.phase) {
3099
- const phase = input.phase;
3100
- if (!state.phases[phase]) {
3101
- state.phases[phase] = defaultPhaseStatus();
3102
- }
3103
- const phaseState = state.phases[phase];
3104
- if (input.field && input.value !== void 0) {
3105
- phaseState[input.field] = input.value;
3106
- }
3107
- if (input.incrementRetry) {
3108
- phaseState.retryCount += 1;
3116
+ const state = updateStateAtomic(cwd, (state2) => {
3117
+ if (input.status) {
3118
+ state2.status = input.status;
3119
+ }
3120
+ if (input.phase) {
3121
+ const phase = input.phase;
3122
+ if (!state2.phases[phase]) {
3123
+ state2.phases[phase] = defaultPhaseStatus();
3124
+ }
3125
+ const phaseState = state2.phases[phase];
3126
+ if (input.field && input.value !== void 0) {
3127
+ phaseState[input.field] = input.value;
3128
+ }
3129
+ if (input.incrementRetry) {
3130
+ phaseState.retryCount += 1;
3131
+ }
3132
+ state2.currentPhase = phase;
3109
3133
  }
3110
- state.currentPhase = phase;
3111
- }
3112
- if (input.updates && input.updates.length > 0) {
3113
- for (const update of input.updates) {
3114
- if (!state.phases[update.phase]) {
3115
- state.phases[update.phase] = defaultPhaseStatus();
3134
+ if (input.updates && input.updates.length > 0) {
3135
+ for (const update of input.updates) {
3136
+ if (!state2.phases[update.phase]) {
3137
+ state2.phases[update.phase] = defaultPhaseStatus();
3138
+ }
3139
+ const batchPhaseState = state2.phases[update.phase];
3140
+ batchPhaseState[update.field] = update.value;
3141
+ state2.currentPhase = update.phase;
3116
3142
  }
3117
- const batchPhaseState = state.phases[update.phase];
3118
- batchPhaseState[update.field] = update.value;
3119
- state.currentPhase = update.phase;
3120
3143
  }
3121
- }
3122
- writeState(cwd, state);
3144
+ });
3123
3145
  try {
3124
3146
  const completedPhases = Object.entries(state.phases).filter(([, ps]) => ps.artifactWritten).map(([p]) => p);
3125
3147
  (0, import_telemetry.emit)(
@@ -3334,11 +3356,11 @@ function handleWritePhaseQuestions(input) {
3334
3356
  requiredPackages
3335
3357
  };
3336
3358
  safeWriteSync(filePath, JSON.stringify(payload, null, 2) + "\n");
3337
- const state = readState(cwd);
3338
- if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
3339
- const ps = state.phases[phase];
3340
- ps.questionsCollected = true;
3341
- writeState(cwd, state);
3359
+ updateStateAtomic(cwd, (state) => {
3360
+ if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
3361
+ const ps = state.phases[phase];
3362
+ ps.questionsCollected = true;
3363
+ });
3342
3364
  return {
3343
3365
  text: JSON.stringify({
3344
3366
  success: true,
@@ -4051,11 +4073,11 @@ function _validateArtifactInner(input) {
4051
4073
  signed = true;
4052
4074
  } catch {
4053
4075
  }
4054
- const state = readState(cwd);
4055
- if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
4056
- const ps = state.phases[phase];
4057
- ps.artifactWritten = true;
4058
- writeState(cwd, state);
4076
+ updateStateAtomic(cwd, (state) => {
4077
+ if (!state.phases[phase]) state.phases[phase] = defaultPhaseStatus();
4078
+ const ps = state.phases[phase];
4079
+ ps.artifactWritten = true;
4080
+ });
4059
4081
  const topKeys = Object.keys(artifact).slice(0, 5).join(", ");
4060
4082
  const result = {
4061
4083
  valid: true,
@@ -5720,7 +5742,7 @@ var _checksums = /* @__PURE__ */ new Map([
5720
5742
  ],
5721
5743
  [
5722
5744
  "stackwright-pro-foreman-otter.json",
5723
- "4db4639e618cdd008d86c416bbc88bd4b2a7965e4bfcf01ec54b828f04ccb816"
5745
+ "9cbe27b8193ebec2ea916aee82d8bdc6c811cc64735923f36b93545a8f1f9551"
5724
5746
  ],
5725
5747
  [
5726
5748
  "stackwright-pro-form-wizard-otter.json",
@@ -7196,10 +7218,12 @@ var package_default = {
7196
7218
  "@stackwright/mcp": "0.6.0-alpha.1",
7197
7219
  "@types/js-yaml": "^4.0.9",
7198
7220
  "js-yaml": "^4.2.0",
7221
+ "proper-lockfile": "^4.1.2",
7199
7222
  zod: "^4.4.3"
7200
7223
  },
7201
7224
  devDependencies: {
7202
7225
  "@types/node": "catalog:",
7226
+ "@types/proper-lockfile": "^4.1.4",
7203
7227
  tsup: "catalog:",
7204
7228
  typescript: "catalog:",
7205
7229
  vitest: "catalog:"
@@ -7213,7 +7237,7 @@ var package_default = {
7213
7237
  "test:coverage": "vitest run --coverage"
7214
7238
  },
7215
7239
  name: "@stackwright-pro/mcp",
7216
- version: "0.2.0-alpha.98",
7240
+ version: "0.2.0-alpha.99",
7217
7241
  description: "MCP tools for Stackwright Pro - Data Explorer, Security, ISR, and Dashboard generation",
7218
7242
  license: "SEE LICENSE IN LICENSE",
7219
7243
  main: "./dist/server.js",