dashclaw 2.13.1 → 3.0.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 (3) hide show
  1. package/README.md +61 -15
  2. package/dashclaw.js +174 -19
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -223,6 +223,39 @@ answer to "does this need human review?" is always `action.status` on the
223
223
  Short version: **trust `action.status`, not `decision.decision`, for HITL
224
224
  branching.**
225
225
 
226
+ ### Non-fabrication checks
227
+
228
+ When a `non_fabrication` guard policy is active, attach the outbound text and the
229
+ facts it is allowed to state, and DashClaw verifies the content before the action
230
+ proceeds — every amount, date, percentage, and registered ID must trace to an
231
+ allowed fact, every required fact must be present, and no forbidden pattern may
232
+ appear. A violation blocks (or routes to approval) and is recorded with a signed,
233
+ re-verifiable receipt.
234
+
235
+ ```javascript
236
+ const decision = await claw.guard({
237
+ action_type: 'message',
238
+ content: 'Hi Jane — your refund of $1,500.00 will arrive by June 1, 2026.',
239
+ sourceOfTruth: {
240
+ allowedFacts: [
241
+ { label: 'refund', value: '$1,500.00' },
242
+ { label: 'date', value: 'June 1, 2026' },
243
+ ],
244
+ requiredFacts: [{ label: 'name', value: 'Jane' }],
245
+ // forbiddenPatterns, extract (money/dates/percentages/patterns) are optional
246
+ },
247
+ });
248
+ // decision.decision === 'block' if the text states a fact not in sourceOfTruth.
249
+ // decision.non_fabrication[0].receipt is an Ed25519-signed proof you can
250
+ // re-verify at POST /api/integrity/verify (public key: /.well-known/jwks.json),
251
+ // or null if the instance has no usable signing key — the verdict is enforced either way.
252
+ ```
253
+
254
+ `createAction()` accepts the same `content` + `sourceOfTruth` fields. Fail-closed:
255
+ a missing or malformed `sourceOfTruth` blocks. A signature proves integrity, the
256
+ verdict, the ruleset version, and the issuer — not time-of-issuance or the
257
+ correctness of prose with no extractable token.
258
+
226
259
  ---
227
260
 
228
261
  ## SDK Tiers
@@ -266,6 +299,9 @@ The v2 SDK exposes the stable governance runtime plus promoted execution domains
266
299
  - `approveAction(id, decision, reasoning?)` -- Submit approval decisions from code
267
300
  - `getPendingApprovals()` -- List actions awaiting human review
268
301
 
302
+ ### Policies
303
+ - `simulatePolicy({ policy_type, rules, days })` -- Side-effect-free dry-run of a proposed policy against recent historical actions before committing it (pairs with `guard()` for live enforcement). `policy_type` and `rules` are required; `days` is optional. Returns `{ summary: { total, matches, block, warn, require_approval, allow }, matches, sample_size, window_days }`. Persists nothing.
304
+
269
305
  ### Durable Execution Finality (v2.13.3+)
270
306
  Terminal outcome reporting that is one-shot, retry-safe, and immutable once non-pending. Separate from `updateOutcome`, which remains the lifecycle-PATCH path. Full spec: [`docs/architecture/durable-execution-finality.md`](../docs/architecture/durable-execution-finality.md). Detailed examples in the [Action Outcome](#action-outcome-durable-execution-finality) subsection of Execution Studio below.
271
307
 
@@ -291,6 +327,22 @@ Terminal outcome reporting that is one-shot, retry-safe, and immutable once non-
291
327
  - `getLessons({ actionType, limit })` -- Fetch consolidated lessons from scored outcomes.
292
328
  - `renderPrompt({ template_id, version_id, variables, record })` -- Fetch a rendered prompt template from DashClaw. `template_id` is required; `version_id` defaults to the active version; `variables` is an object of mustache values; `record: true` persists the render as a governance event.
293
329
 
330
+ ### Prompt Library
331
+
332
+ Manage reusable prompt templates, their versions, and usage analytics. `renderPrompt` (above) fetches a rendered version; these manage the library itself. Mutations (`create*`, `update*`, `delete*`, version creation, and `activate*`) require an admin org role.
333
+
334
+ - `listPromptTemplates({ category })` -- List prompt templates (each with `version_count` + `active_version`). Returns `{ templates }`.
335
+ - `getPromptTemplate(templateId)` -- Fetch a single template.
336
+ - `createPromptTemplate({ name, description, category })` -- Create a template (admin). `name` is required; `description` and `category` are optional. Returns `{ id, name, description, category }`.
337
+ - `updatePromptTemplate(templateId, patch)` -- Update a template (admin). `patch` accepts `name`, `description`, `category`.
338
+ - `deletePromptTemplate(templateId)` -- Delete a template plus its versions and runs (admin). Returns `{ deleted: true }`.
339
+ - `listPromptVersions(templateId)` -- List versions for a template (newest first). Returns `{ versions }`.
340
+ - `createPromptVersion(templateId, { content, model_hint, parameters, changelog })` -- Create a version (admin). `content` is required; `model_hint`, `parameters`, `changelog` are optional.
341
+ - `getPromptVersion(templateId, versionId)` -- Fetch a single version.
342
+ - `activatePromptVersion(templateId, versionId)` -- Activate a version (admin). Activating one version deactivates the others for that template.
343
+ - `getPromptStats({ template_id })` -- Prompt usage analytics, optionally scoped to one template.
344
+ - `listPromptRuns({ template_id, version_id, limit })` -- List recorded prompt runs.
345
+
294
346
  ### Learning Loop
295
347
 
296
348
  The guard response now includes a `learning` field when DashClaw has historical data for the agent and action type. This creates a closed learning loop: outcomes feed back into guard decisions automatically.
@@ -315,6 +367,9 @@ lessons.forEach(l => console.log(l.guidance));
315
367
  // guidance, sample_size
316
368
  ```
317
369
 
370
+ - `recordDecision({ decision, context, reasoning, outcome, confidence, agent_id })` -- Record a decision/outcome into the learning ledger. `decision` is required; `agent_id` is auto-injected from the constructor when omitted. Returns `{ decision }`.
371
+ - `getLearningRecommendations({ agent_id, action_type, include_metrics, lookback_days, limit })` -- Read learned recommendations for an agent/action type. `agent_id` defaults to the constructor's agent.
372
+
318
373
  ### Scoring Profiles
319
374
  - `createScorer(name, type, config)` -- Define automated evaluations.
320
375
  - `createScoringProfile(profile)` -- Create a weighted multi-dimensional scoring profile.
@@ -335,6 +390,9 @@ lessons.forEach(l => console.log(l.guidance));
335
390
  - `deleteRiskTemplate(templateId)` -- Delete a risk template.
336
391
  - `autoCalibrate(options)` -- Analyze historical actions and suggest percentile-based scoring scales.
337
392
 
393
+ ### Evaluations
394
+ - `previewScorer({ scorer_type, config, sample })` -- Dry-run a scorer config against a sample action to validate a quality gate before creating a scorer or launching a run. `scorer_type` is required; `config` and `sample` are optional. Writes **no** `eval_scores` row (distinct from the scoring-profiles subsystem above). Returns `{ preview, scorer_type, result: { score, label, reasoning, error } }`.
395
+
338
396
  ### Messaging
339
397
  - `sendMessage({ to, type, subject, body, threadId, urgent })` -- Send a message to another agent or broadcast.
340
398
  - `getInbox({ type, unread, limit })` -- Retrieve inbox messages with optional filters.
@@ -389,21 +447,6 @@ if (result.recommendation === 'block') {
389
447
  }
390
448
  ```
391
449
 
392
- ### Feedback
393
- - `submitFeedback({ action_id, rating, comment, category, tags, metadata })` -- Submit feedback on an action.
394
-
395
- ```javascript
396
- // Submit feedback on an action
397
- await claw.submitFeedback({
398
- action_id: 'act_123',
399
- rating: 5,
400
- comment: 'Deploy was smooth',
401
- category: 'deployment',
402
- tags: ['fast', 'clean'],
403
- metadata: { deploy_duration_ms: 1200 }
404
- });
405
- ```
406
-
407
450
  ### Context Threads
408
451
  - `createThread(thread)` -- Create a context thread for tracking multi-step work.
409
452
  - `addThreadEntry(threadId, content, entryType)` -- Add an entry to a context thread.
@@ -911,6 +954,9 @@ const { results } = await claw.searchKnowledgeCollection(
911
954
  { limit: 5 }
912
955
  );
913
956
  results.forEach(r => console.log(`${(r.score * 100).toFixed(1)}%: ${r.content.slice(0, 80)}...`));
957
+
958
+ // Delete a collection (cascades its items + chunks)
959
+ const { deleted, collection_id } = await claw.deleteKnowledgeCollection(collection.collection_id);
914
960
  ```
915
961
 
916
962
  ### Capability Runtime
package/dashclaw.js CHANGED
@@ -121,6 +121,14 @@ class DashClaw {
121
121
  /**
122
122
  * POST /api/guard — "Can I do X?"
123
123
  * @param {Object} context
124
+ * @param {string} [context.content] - Outbound content to fabrication-check
125
+ * (e.g. a drafted email/message). Pairs with `sourceOfTruth` and a
126
+ * `non_fabrication` guard policy: every operational token (amounts, dates,
127
+ * percentages, registered IDs) must trace to an allowed fact, or the action
128
+ * is blocked / routed to approval. The response carries a signed,
129
+ * re-verifiable receipt under `non_fabrication`.
130
+ * @param {Object} [context.sourceOfTruth] - The facts `content` is allowed to
131
+ * state: `{ allowedFacts, requiredFacts, forbiddenPatterns?, extract? }`.
124
132
  * @returns {Promise<{
125
133
  * decision: 'allow'|'block'|'require_approval'|'warn',
126
134
  * action_id: string,
@@ -150,6 +158,13 @@ class DashClaw {
150
158
 
151
159
  /**
152
160
  * POST /api/actions — "I am attempting X."
161
+ *
162
+ * Optional non-fabrication fields: pass `content` (the outbound text) and
163
+ * `sourceOfTruth` ({ allowedFacts, requiredFacts, forbiddenPatterns?, extract? })
164
+ * to have a `non_fabrication` guard policy verify the content before the
165
+ * action proceeds. A violation blocks the action or routes it to approval and
166
+ * is recorded with a signed receipt in the decision ledger.
167
+ * @param {Object} action
153
168
  */
154
169
  async createAction(action) {
155
170
  return this._request('/api/actions', 'POST', {
@@ -738,25 +753,6 @@ class DashClaw {
738
753
  });
739
754
  }
740
755
 
741
- // ---------------------------------------------------------------------------
742
- // User Feedback
743
- // ---------------------------------------------------------------------------
744
-
745
- /**
746
- * POST /api/feedback — Submit user feedback linked to an action.
747
- */
748
- async submitFeedback({ action_id, rating, comment, category, tags, metadata }) {
749
- return this._request('/api/feedback', 'POST', {
750
- action_id,
751
- agent_id: this.agentId,
752
- rating,
753
- comment,
754
- category,
755
- tags,
756
- metadata,
757
- });
758
- }
759
-
760
756
  // ---------------------------------------------------------------------------
761
757
  // Context Threads
762
758
  // ---------------------------------------------------------------------------
@@ -1129,6 +1125,13 @@ class DashClaw {
1129
1125
  });
1130
1126
  }
1131
1127
 
1128
+ /**
1129
+ * DELETE /api/knowledge/collections/:id — Delete a collection (cascades items + chunks).
1130
+ */
1131
+ async deleteKnowledgeCollection(collectionId) {
1132
+ return this._request(`/api/knowledge/collections/${collectionId}`, 'DELETE');
1133
+ }
1134
+
1132
1135
  // ---------------------------------------------------------------------------
1133
1136
  // Execution Studio — Capability Registry
1134
1137
  // ---------------------------------------------------------------------------
@@ -1202,6 +1205,158 @@ class DashClaw {
1202
1205
  async getCapabilityHistory(capabilityId, filters = {}) {
1203
1206
  return this._request(`/api/capabilities/${capabilityId}/history`, 'GET', null, filters);
1204
1207
  }
1208
+
1209
+ // ---------------------------------------------------------------------------
1210
+ // Prompt Library — reusable prompt templates, versions, render + analytics.
1211
+ // renderPrompt() already lives in the rendering section above; these add the
1212
+ // template/version management surface so the library is first-class in the SDK.
1213
+ // Mutations (create/update/delete/version/activate) require an admin org role.
1214
+ // ---------------------------------------------------------------------------
1215
+
1216
+ /**
1217
+ * GET /api/prompts/templates — List prompt templates (each with version_count + active_version).
1218
+ * @param {Object} [filters={}] - { category }
1219
+ */
1220
+ async listPromptTemplates(filters = {}) {
1221
+ return this._request('/api/prompts/templates', 'GET', null, filters);
1222
+ }
1223
+
1224
+ /**
1225
+ * GET /api/prompts/templates/:id — Fetch a single template.
1226
+ */
1227
+ async getPromptTemplate(templateId) {
1228
+ return this._request(`/api/prompts/templates/${templateId}`, 'GET');
1229
+ }
1230
+
1231
+ /**
1232
+ * POST /api/prompts/templates — Create a template (admin). { name, description?, category? }
1233
+ */
1234
+ async createPromptTemplate(data) {
1235
+ return this._request('/api/prompts/templates', 'POST', data);
1236
+ }
1237
+
1238
+ /**
1239
+ * PATCH /api/prompts/templates/:id — Update a template (admin). { name?, description?, category? }
1240
+ */
1241
+ async updatePromptTemplate(templateId, patch) {
1242
+ return this._request(`/api/prompts/templates/${templateId}`, 'PATCH', patch);
1243
+ }
1244
+
1245
+ /**
1246
+ * DELETE /api/prompts/templates/:id — Delete a template + its versions/runs (admin).
1247
+ */
1248
+ async deletePromptTemplate(templateId) {
1249
+ return this._request(`/api/prompts/templates/${templateId}`, 'DELETE');
1250
+ }
1251
+
1252
+ /**
1253
+ * GET /api/prompts/templates/:id/versions — List versions (newest first).
1254
+ */
1255
+ async listPromptVersions(templateId) {
1256
+ return this._request(`/api/prompts/templates/${templateId}/versions`, 'GET');
1257
+ }
1258
+
1259
+ /**
1260
+ * POST /api/prompts/templates/:id/versions — Create a version (admin).
1261
+ * @param {string} templateId
1262
+ * @param {Object} data - { content, model_hint?, parameters?, changelog? }
1263
+ */
1264
+ async createPromptVersion(templateId, data) {
1265
+ return this._request(`/api/prompts/templates/${templateId}/versions`, 'POST', data);
1266
+ }
1267
+
1268
+ /**
1269
+ * GET /api/prompts/templates/:id/versions/:versionId — Fetch a single version.
1270
+ */
1271
+ async getPromptVersion(templateId, versionId) {
1272
+ return this._request(`/api/prompts/templates/${templateId}/versions/${versionId}`, 'GET');
1273
+ }
1274
+
1275
+ /**
1276
+ * POST /api/prompts/templates/:id/versions/:versionId — Activate a version (admin).
1277
+ * Activating one version deactivates the others for that template.
1278
+ */
1279
+ async activatePromptVersion(templateId, versionId) {
1280
+ return this._request(`/api/prompts/templates/${templateId}/versions/${versionId}`, 'POST');
1281
+ }
1282
+
1283
+ /**
1284
+ * GET /api/prompts/stats — Prompt usage analytics.
1285
+ * @param {Object} [filters={}] - { template_id }
1286
+ */
1287
+ async getPromptStats(filters = {}) {
1288
+ return this._request('/api/prompts/stats', 'GET', null, filters);
1289
+ }
1290
+
1291
+ /**
1292
+ * GET /api/prompts/runs — List recorded prompt runs.
1293
+ * @param {Object} [filters={}] - { template_id, version_id, limit }
1294
+ */
1295
+ async listPromptRuns(filters = {}) {
1296
+ return this._request('/api/prompts/runs', 'GET', null, filters);
1297
+ }
1298
+
1299
+ // ---------------------------------------------------------------------------
1300
+ // Learning — record decisions/outcomes and read back recommendations so the
1301
+ // governance loop improves over time.
1302
+ // ---------------------------------------------------------------------------
1303
+
1304
+ /**
1305
+ * POST /api/learning — Record a decision/outcome into the learning ledger.
1306
+ * @param {Object} entry - { decision (required), context?, reasoning?, outcome?, confidence?, agent_id? }
1307
+ * @returns {Promise<{ decision: Object }>}
1308
+ */
1309
+ async recordDecision(entry) {
1310
+ return this._request('/api/learning', 'POST', {
1311
+ ...entry,
1312
+ agent_id: entry.agent_id || this.agentId,
1313
+ });
1314
+ }
1315
+
1316
+ /**
1317
+ * GET /api/learning/recommendations — Read learned recommendations for an agent/action_type.
1318
+ * @param {Object} [filters={}] - { agent_id, action_type, include_metrics, lookback_days, limit }
1319
+ */
1320
+ async getLearningRecommendations(filters = {}) {
1321
+ return this._request('/api/learning/recommendations', 'GET', null, {
1322
+ ...filters,
1323
+ agent_id: filters.agent_id || this.agentId,
1324
+ });
1325
+ }
1326
+
1327
+ // ---------------------------------------------------------------------------
1328
+ // Policies — dry-run a proposed policy against historical actions before
1329
+ // committing it (no persistence; pairs with guard() for live enforcement).
1330
+ // ---------------------------------------------------------------------------
1331
+
1332
+ /**
1333
+ * POST /api/policies/simulate — Simulate a single proposed policy against
1334
+ * recent historical actions. Side-effect-free.
1335
+ * @param {Object} args - { policy_type (required), rules (Object, required), days? }
1336
+ * @returns {Promise<{ summary: { total, matches, block, warn, require_approval, allow }, matches: Array, sample_size, window_days }>}
1337
+ */
1338
+ async simulatePolicy({ policy_type, rules, days } = {}) {
1339
+ return this._request('/api/policies/simulate', 'POST', {
1340
+ policy_type,
1341
+ rules,
1342
+ ...(days !== undefined ? { days } : {}),
1343
+ });
1344
+ }
1345
+
1346
+ // ---------------------------------------------------------------------------
1347
+ // Evaluations — preview a scorer (dry-run, no eval_scores written).
1348
+ // ---------------------------------------------------------------------------
1349
+
1350
+ /**
1351
+ * POST /api/evaluations/scorers/preview — Dry-run a scorer config against a
1352
+ * sample action without persisting a score. Use to validate a quality gate
1353
+ * (e.g. branch-finish scoring) before creating a scorer or launching a run.
1354
+ * @param {Object} args - { scorer_type (required), config?, sample? }
1355
+ * @returns {Promise<{ preview: true, scorer_type, result: { score, label, reasoning, error } }>}
1356
+ */
1357
+ async previewScorer({ scorer_type, config, sample } = {}) {
1358
+ return this._request('/api/evaluations/scorers/preview', 'POST', { scorer_type, config, sample });
1359
+ }
1205
1360
  }
1206
1361
 
1207
1362
  export { DashClaw, ApprovalDeniedError, GuardBlockedError };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dashclaw",
3
- "version": "2.13.1",
3
+ "version": "3.0.0",
4
4
  "description": "Minimal governance runtime for AI agents. Intercept, govern, and verify agent actions.",
5
5
  "type": "module",
6
6
  "publishConfig": {