dashclaw 2.0.2 → 2.1.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.
package/index.cjs CHANGED
@@ -1,9 +1,16 @@
1
1
  /**
2
- * DashClaw SDK: CommonJS compatibility wrapper.
3
- * For ESM: import { DashClaw } from 'dashclaw'
4
- * For CJS: const { DashClaw } = require('dashclaw')
2
+ * DashClaw SDK v2 (Stable Runtime API)
3
+ * CommonJS compatibility bridge.
4
+ *
5
+ * ESM: import { DashClaw } from 'dashclaw'
6
+ * CJS: const { DashClaw } = require('dashclaw')
5
7
  */
6
8
 
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+
12
+ // Minimal CommonJS shim for the v2 SDK
13
+ // We use a simplified bridge that forwards calls to the async ESM import
7
14
  let _module;
8
15
 
9
16
  async function loadModule() {
@@ -13,79 +20,51 @@ async function loadModule() {
13
20
  return _module;
14
21
  }
15
22
 
16
- // Re-export via dynamic import (CJS → ESM bridge)
17
- module.exports = new Proxy({}, {
18
- get(target, prop) {
19
- if (prop === '__esModule') return true;
20
- if (prop === 'then') return undefined; // Prevent Promise-like behavior
23
+ module.exports = {
24
+ // Sync wrapper that returns a proxy for the DashClaw class
25
+ DashClaw: class DashClawProxy {
26
+ constructor(opts) {
27
+ this._opts = opts;
28
+ this._ready = loadModule().then(m => {
29
+ this._instance = new m.DashClaw(opts);
30
+ });
21
31
 
22
- // Return a lazy-loading constructor wrapper
23
- if (prop === 'GuardBlockedError') {
24
- const Placeholder = class GuardBlockedError extends Error {
25
- constructor(decision) {
26
- const reasons = (decision.reasons || []).join('; ') || 'no reason';
27
- super(`Guard blocked action: ${decision.decision}. Reasons: ${reasons}`);
28
- this.name = 'GuardBlockedError';
29
- this.decision = decision.decision;
30
- this.reasons = decision.reasons || [];
31
- this.warnings = decision.warnings || [];
32
- this.matchedPolicies = decision.matched_policies || [];
33
- this.riskScore = decision.risk_score ?? null;
34
- }
35
- };
36
-
37
- // Support instanceof across ESM/CJS boundary
38
- loadModule().then(m => {
39
- if (m.GuardBlockedError) {
40
- Object.defineProperty(Placeholder, Symbol.hasInstance, {
41
- value: (instance) => instance && (instance.name === 'GuardBlockedError' || instance instanceof m.GuardBlockedError)
42
- });
32
+ return new Proxy(this, {
33
+ get(target, prop) {
34
+ if (prop in target) return target[prop];
35
+ if (prop === 'then') return undefined;
36
+
37
+ return async (...args) => {
38
+ await target._ready;
39
+ if (!target._instance[prop]) {
40
+ throw new Error(`Method ${String(prop)} does not exist on DashClaw v2`);
41
+ }
42
+ return target._instance[prop](...args);
43
+ };
43
44
  }
44
45
  });
45
-
46
- return Placeholder;
47
46
  }
48
- if (prop === 'DashClaw' || prop === 'OpenClawAgent' || prop === 'default') {
49
- return class DashClawProxy {
50
- constructor(opts) {
51
- this._opts = opts;
52
- this._ready = loadModule().then(m => {
53
- const Cls = m.DashClaw || m.default;
54
- this._instance = new Cls(opts);
55
- });
56
47
 
57
- // Return a proxy that forwards all method calls to the async instance
58
- return new Proxy(this, {
59
- get(target, prop) {
60
- if (prop in target) return target[prop];
61
- if (prop === 'then') return undefined;
48
+ static async create(opts) {
49
+ const mod = await loadModule();
50
+ return new mod.DashClaw(opts);
51
+ }
52
+ },
62
53
 
63
- return async (...args) => {
64
- await target._ready;
65
- if (!target._instance[prop]) {
66
- throw new Error(`Method ${String(prop)} does not exist on DashClaw`);
67
- }
68
- return target._instance[prop](...args);
69
- };
70
- }
71
- });
72
- }
54
+ // Errors from v2
55
+ ApprovalDeniedError: class ApprovalDeniedError extends Error {
56
+ constructor(message, decision) {
57
+ super(message);
58
+ this.name = 'ApprovalDeniedError';
59
+ this.decision = decision;
60
+ }
61
+ },
73
62
 
74
- // For synchronous construction, use DashClaw.create()
75
- static async create(opts) {
76
- const mod = await loadModule();
77
- const Cls = mod.DashClaw || mod.default;
78
- return new Cls(opts);
79
- }
80
- };
63
+ GuardBlockedError: class GuardBlockedError extends Error {
64
+ constructor(decision) {
65
+ super(decision.reason || 'Action blocked by policy');
66
+ this.name = 'GuardBlockedError';
67
+ this.decision = decision;
81
68
  }
82
- return undefined;
83
69
  }
84
- });
85
-
86
- // Preferred: async factory
87
- module.exports.create = async function create(opts) {
88
- const mod = await loadModule();
89
- const Cls = mod.DashClaw || mod.default;
90
- return new Cls(opts);
91
70
  };