@probelabs/probe 0.6.0-rc304 → 0.6.0-rc305

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.
@@ -63,7 +63,11 @@ export class TaskManager {
63
63
  * @throws {Error} If dependencies are invalid or create a cycle
64
64
  */
65
65
  createTask(taskData) {
66
- const id = this._generateId();
66
+ const id = taskData.id || this._generateId();
67
+ // If a user-provided ID collides with an existing task, throw
68
+ if (taskData.id && this.tasks.has(taskData.id)) {
69
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
70
+ }
67
71
  const now = this._now();
68
72
 
69
73
  // Validate dependencies exist
@@ -148,46 +152,42 @@ export class TaskManager {
148
152
  }
149
153
  }
150
154
 
151
- // Build a mapping of user-provided IDs to future auto-generated IDs
152
- const idMap = new Map();
153
- const batchAutoIds = new Set();
154
- let nextCounter = this.taskCounter;
155
+ // Collect all IDs that will exist after this batch (for dependency validation)
156
+ const batchIds = new Set();
155
157
  for (const taskData of tasksData) {
156
- nextCounter++;
157
- const autoId = `task-${nextCounter}`;
158
- batchAutoIds.add(autoId);
159
158
  if (taskData.id) {
160
- idMap.set(taskData.id, autoId);
159
+ if (this.tasks.has(taskData.id)) {
160
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
161
+ }
162
+ if (batchIds.has(taskData.id)) {
163
+ throw new Error(`Duplicate task ID "${taskData.id}" in batch. Each task must have a unique ID.`);
164
+ }
165
+ batchIds.add(taskData.id);
161
166
  }
162
167
  }
163
168
 
164
- // Resolve dependencies and "after" references, then validate before creating anything
169
+ // Validate dependencies and "after" references before creating anything
165
170
  const resolvedTasksData = tasksData.map(taskData => {
166
171
  const resolved = { ...taskData };
167
- delete resolved.id; // Don't pass user ID to createTask
168
172
 
169
173
  if (resolved.dependencies) {
170
174
  resolved.dependencies = resolved.dependencies.map(depId => {
171
- if (idMap.has(depId)) return idMap.get(depId);
172
- // Check if it's already an existing task ID or a batch auto-generated ID
173
- if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
174
- const batchIds = idMap.size > 0 ? Array.from(idMap.keys()).join(', ') : '(none provided)';
175
- throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${batchIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
175
+ if (batchIds.has(depId) || this.tasks.has(depId)) return depId;
176
+ const knownIds = batchIds.size > 0 ? Array.from(batchIds).join(', ') : '(none provided)';
177
+ throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${knownIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
176
178
  });
177
179
  }
178
180
 
179
181
  if (resolved.after) {
180
- if (idMap.has(resolved.after)) {
181
- resolved.after = idMap.get(resolved.after);
182
- } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
183
- throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(', ')}` : ''}`);
182
+ if (!batchIds.has(resolved.after) && !this.tasks.has(resolved.after)) {
183
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${batchIds.size > 0 ? `, batch IDs: ${Array.from(batchIds).join(', ')}` : ''}`);
184
184
  }
185
185
  }
186
186
 
187
187
  return resolved;
188
188
  });
189
189
 
190
- // All validation passed — create tasks
190
+ // All validation passed — create tasks (user-provided IDs are preserved by createTask)
191
191
  const createdTasks = [];
192
192
  for (const taskData of resolvedTasksData) {
193
193
  const task = this.createTask(taskData);
@@ -50389,7 +50389,10 @@ var init_TaskManager = __esm({
50389
50389
  * @throws {Error} If dependencies are invalid or create a cycle
50390
50390
  */
50391
50391
  createTask(taskData) {
50392
- const id = this._generateId();
50392
+ const id = taskData.id || this._generateId();
50393
+ if (taskData.id && this.tasks.has(taskData.id)) {
50394
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
50395
+ }
50393
50396
  const now = this._now();
50394
50397
  const dependencies = taskData.dependencies || [];
50395
50398
  for (const depId of dependencies) {
@@ -50457,33 +50460,30 @@ var init_TaskManager = __esm({
50457
50460
  }
50458
50461
  }
50459
50462
  }
50460
- const idMap = /* @__PURE__ */ new Map();
50461
- const batchAutoIds = /* @__PURE__ */ new Set();
50462
- let nextCounter = this.taskCounter;
50463
+ const batchIds = /* @__PURE__ */ new Set();
50463
50464
  for (const taskData of tasksData) {
50464
- nextCounter++;
50465
- const autoId = `task-${nextCounter}`;
50466
- batchAutoIds.add(autoId);
50467
50465
  if (taskData.id) {
50468
- idMap.set(taskData.id, autoId);
50466
+ if (this.tasks.has(taskData.id)) {
50467
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
50468
+ }
50469
+ if (batchIds.has(taskData.id)) {
50470
+ throw new Error(`Duplicate task ID "${taskData.id}" in batch. Each task must have a unique ID.`);
50471
+ }
50472
+ batchIds.add(taskData.id);
50469
50473
  }
50470
50474
  }
50471
50475
  const resolvedTasksData = tasksData.map((taskData) => {
50472
50476
  const resolved = { ...taskData };
50473
- delete resolved.id;
50474
50477
  if (resolved.dependencies) {
50475
50478
  resolved.dependencies = resolved.dependencies.map((depId) => {
50476
- if (idMap.has(depId)) return idMap.get(depId);
50477
- if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
50478
- const batchIds = idMap.size > 0 ? Array.from(idMap.keys()).join(", ") : "(none provided)";
50479
- throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${batchIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
50479
+ if (batchIds.has(depId) || this.tasks.has(depId)) return depId;
50480
+ const knownIds = batchIds.size > 0 ? Array.from(batchIds).join(", ") : "(none provided)";
50481
+ throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${knownIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
50480
50482
  });
50481
50483
  }
50482
50484
  if (resolved.after) {
50483
- if (idMap.has(resolved.after)) {
50484
- resolved.after = idMap.get(resolved.after);
50485
- } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
50486
- throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
50485
+ if (!batchIds.has(resolved.after) && !this.tasks.has(resolved.after)) {
50486
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${batchIds.size > 0 ? `, batch IDs: ${Array.from(batchIds).join(", ")}` : ""}`);
50487
50487
  }
50488
50488
  }
50489
50489
  return resolved;
package/cjs/index.cjs CHANGED
@@ -26847,7 +26847,10 @@ var init_TaskManager = __esm({
26847
26847
  * @throws {Error} If dependencies are invalid or create a cycle
26848
26848
  */
26849
26849
  createTask(taskData) {
26850
- const id = this._generateId();
26850
+ const id = taskData.id || this._generateId();
26851
+ if (taskData.id && this.tasks.has(taskData.id)) {
26852
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
26853
+ }
26851
26854
  const now = this._now();
26852
26855
  const dependencies = taskData.dependencies || [];
26853
26856
  for (const depId of dependencies) {
@@ -26915,33 +26918,30 @@ var init_TaskManager = __esm({
26915
26918
  }
26916
26919
  }
26917
26920
  }
26918
- const idMap = /* @__PURE__ */ new Map();
26919
- const batchAutoIds = /* @__PURE__ */ new Set();
26920
- let nextCounter = this.taskCounter;
26921
+ const batchIds = /* @__PURE__ */ new Set();
26921
26922
  for (const taskData of tasksData) {
26922
- nextCounter++;
26923
- const autoId = `task-${nextCounter}`;
26924
- batchAutoIds.add(autoId);
26925
26923
  if (taskData.id) {
26926
- idMap.set(taskData.id, autoId);
26924
+ if (this.tasks.has(taskData.id)) {
26925
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
26926
+ }
26927
+ if (batchIds.has(taskData.id)) {
26928
+ throw new Error(`Duplicate task ID "${taskData.id}" in batch. Each task must have a unique ID.`);
26929
+ }
26930
+ batchIds.add(taskData.id);
26927
26931
  }
26928
26932
  }
26929
26933
  const resolvedTasksData = tasksData.map((taskData) => {
26930
26934
  const resolved = { ...taskData };
26931
- delete resolved.id;
26932
26935
  if (resolved.dependencies) {
26933
26936
  resolved.dependencies = resolved.dependencies.map((depId) => {
26934
- if (idMap.has(depId)) return idMap.get(depId);
26935
- if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
26936
- const batchIds = idMap.size > 0 ? Array.from(idMap.keys()).join(", ") : "(none provided)";
26937
- throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${batchIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
26937
+ if (batchIds.has(depId) || this.tasks.has(depId)) return depId;
26938
+ const knownIds = batchIds.size > 0 ? Array.from(batchIds).join(", ") : "(none provided)";
26939
+ throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${knownIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
26938
26940
  });
26939
26941
  }
26940
26942
  if (resolved.after) {
26941
- if (idMap.has(resolved.after)) {
26942
- resolved.after = idMap.get(resolved.after);
26943
- } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
26944
- throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(", ")}` : ""}`);
26943
+ if (!batchIds.has(resolved.after) && !this.tasks.has(resolved.after)) {
26944
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${batchIds.size > 0 ? `, batch IDs: ${Array.from(batchIds).join(", ")}` : ""}`);
26945
26945
  }
26946
26946
  }
26947
26947
  return resolved;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@probelabs/probe",
3
- "version": "0.6.0-rc304",
3
+ "version": "0.6.0-rc305",
4
4
  "description": "Node.js wrapper for the probe code search tool",
5
5
  "main": "src/index.js",
6
6
  "module": "src/index.js",
@@ -63,7 +63,11 @@ export class TaskManager {
63
63
  * @throws {Error} If dependencies are invalid or create a cycle
64
64
  */
65
65
  createTask(taskData) {
66
- const id = this._generateId();
66
+ const id = taskData.id || this._generateId();
67
+ // If a user-provided ID collides with an existing task, throw
68
+ if (taskData.id && this.tasks.has(taskData.id)) {
69
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
70
+ }
67
71
  const now = this._now();
68
72
 
69
73
  // Validate dependencies exist
@@ -148,46 +152,42 @@ export class TaskManager {
148
152
  }
149
153
  }
150
154
 
151
- // Build a mapping of user-provided IDs to future auto-generated IDs
152
- const idMap = new Map();
153
- const batchAutoIds = new Set();
154
- let nextCounter = this.taskCounter;
155
+ // Collect all IDs that will exist after this batch (for dependency validation)
156
+ const batchIds = new Set();
155
157
  for (const taskData of tasksData) {
156
- nextCounter++;
157
- const autoId = `task-${nextCounter}`;
158
- batchAutoIds.add(autoId);
159
158
  if (taskData.id) {
160
- idMap.set(taskData.id, autoId);
159
+ if (this.tasks.has(taskData.id)) {
160
+ throw new Error(`Task ID "${taskData.id}" already exists. Choose a different ID. Available tasks: ${this._getAvailableTaskIds()}`);
161
+ }
162
+ if (batchIds.has(taskData.id)) {
163
+ throw new Error(`Duplicate task ID "${taskData.id}" in batch. Each task must have a unique ID.`);
164
+ }
165
+ batchIds.add(taskData.id);
161
166
  }
162
167
  }
163
168
 
164
- // Resolve dependencies and "after" references, then validate before creating anything
169
+ // Validate dependencies and "after" references before creating anything
165
170
  const resolvedTasksData = tasksData.map(taskData => {
166
171
  const resolved = { ...taskData };
167
- delete resolved.id; // Don't pass user ID to createTask
168
172
 
169
173
  if (resolved.dependencies) {
170
174
  resolved.dependencies = resolved.dependencies.map(depId => {
171
- if (idMap.has(depId)) return idMap.get(depId);
172
- // Check if it's already an existing task ID or a batch auto-generated ID
173
- if (this.tasks.has(depId) || batchAutoIds.has(depId)) return depId;
174
- const batchIds = idMap.size > 0 ? Array.from(idMap.keys()).join(', ') : '(none provided)';
175
- throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${batchIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
175
+ if (batchIds.has(depId) || this.tasks.has(depId)) return depId;
176
+ const knownIds = batchIds.size > 0 ? Array.from(batchIds).join(', ') : '(none provided)';
177
+ throw new Error(`Dependency "${depId}" does not exist. Each task in the batch must have an "id" field, and dependencies must reference those IDs. Current batch IDs: ${knownIds}. Existing tasks: ${this._getAvailableTaskIds()}`);
176
178
  });
177
179
  }
178
180
 
179
181
  if (resolved.after) {
180
- if (idMap.has(resolved.after)) {
181
- resolved.after = idMap.get(resolved.after);
182
- } else if (!this.tasks.has(resolved.after) && !batchAutoIds.has(resolved.after)) {
183
- throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${idMap.size > 0 ? `, batch IDs: ${Array.from(idMap.keys()).join(', ')}` : ''}`);
182
+ if (!batchIds.has(resolved.after) && !this.tasks.has(resolved.after)) {
183
+ throw new Error(`Task "${resolved.after}" does not exist. Cannot insert after non-existent task. Available tasks: ${this._getAvailableTaskIds()}${batchIds.size > 0 ? `, batch IDs: ${Array.from(batchIds).join(', ')}` : ''}`);
184
184
  }
185
185
  }
186
186
 
187
187
  return resolved;
188
188
  });
189
189
 
190
- // All validation passed — create tasks
190
+ // All validation passed — create tasks (user-provided IDs are preserved by createTask)
191
191
  const createdTasks = [];
192
192
  for (const taskData of resolvedTasksData) {
193
193
  const task = this.createTask(taskData);