delimit-cli 1.0.0 → 2.1.1

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 (95) hide show
  1. package/.github/workflows/api-governance.yml +43 -0
  2. package/README.md +70 -113
  3. package/adapters/codex-skill.js +87 -0
  4. package/adapters/cursor-extension.js +190 -0
  5. package/adapters/gemini-action.js +93 -0
  6. package/adapters/openai-function.js +112 -0
  7. package/adapters/xai-plugin.js +151 -0
  8. package/bin/delimit-cli.js +921 -0
  9. package/bin/delimit.js +237 -1
  10. package/delimit.yml +19 -0
  11. package/hooks/evidence-status.sh +12 -0
  12. package/hooks/git/commit-msg +4 -0
  13. package/hooks/git/pre-commit +4 -0
  14. package/hooks/git/pre-push +4 -0
  15. package/hooks/install-hooks.sh +583 -0
  16. package/hooks/message-auth-hook.js +9 -0
  17. package/hooks/message-governance-hook.js +9 -0
  18. package/hooks/models/claude-post.js +4 -0
  19. package/hooks/models/claude-pre.js +4 -0
  20. package/hooks/models/codex-post.js +4 -0
  21. package/hooks/models/codex-pre.js +4 -0
  22. package/hooks/models/cursor-post.js +4 -0
  23. package/hooks/models/cursor-pre.js +4 -0
  24. package/hooks/models/gemini-post.js +4 -0
  25. package/hooks/models/gemini-pre.js +4 -0
  26. package/hooks/models/openai-post.js +4 -0
  27. package/hooks/models/openai-pre.js +4 -0
  28. package/hooks/models/windsurf-post.js +4 -0
  29. package/hooks/models/windsurf-pre.js +4 -0
  30. package/hooks/models/xai-post.js +4 -0
  31. package/hooks/models/xai-pre.js +4 -0
  32. package/hooks/post-bash-hook.js +13 -0
  33. package/hooks/post-mcp-hook.js +13 -0
  34. package/hooks/post-response-hook.js +4 -0
  35. package/hooks/post-tool-hook.js +126 -0
  36. package/hooks/post-write-hook.js +13 -0
  37. package/hooks/pre-bash-hook.js +30 -0
  38. package/hooks/pre-mcp-hook.js +13 -0
  39. package/hooks/pre-read-hook.js +13 -0
  40. package/hooks/pre-search-hook.js +13 -0
  41. package/hooks/pre-submit-hook.js +4 -0
  42. package/hooks/pre-task-hook.js +13 -0
  43. package/hooks/pre-tool-hook.js +121 -0
  44. package/hooks/pre-web-hook.js +13 -0
  45. package/hooks/pre-write-hook.js +31 -0
  46. package/hooks/test-hooks.sh +12 -0
  47. package/hooks/update-delimit.sh +6 -0
  48. package/lib/agent.js +509 -0
  49. package/lib/api-engine.js +156 -0
  50. package/lib/auth-setup.js +891 -0
  51. package/lib/decision-engine.js +474 -0
  52. package/lib/hooks-installer.js +416 -0
  53. package/lib/platform-adapters.js +353 -0
  54. package/lib/proxy-handler.js +114 -0
  55. package/package.json +38 -30
  56. package/scripts/infect.js +128 -0
  57. package/test-decision-engine.js +181 -0
  58. package/test-hook.js +27 -0
  59. package/dist/commands/validate.d.ts +0 -2
  60. package/dist/commands/validate.d.ts.map +0 -1
  61. package/dist/commands/validate.js +0 -106
  62. package/dist/commands/validate.js.map +0 -1
  63. package/dist/index.d.ts +0 -3
  64. package/dist/index.d.ts.map +0 -1
  65. package/dist/index.js +0 -71
  66. package/dist/index.js.map +0 -1
  67. package/dist/types/index.d.ts +0 -39
  68. package/dist/types/index.d.ts.map +0 -1
  69. package/dist/types/index.js +0 -3
  70. package/dist/types/index.js.map +0 -1
  71. package/dist/utils/api.d.ts +0 -3
  72. package/dist/utils/api.d.ts.map +0 -1
  73. package/dist/utils/api.js +0 -64
  74. package/dist/utils/api.js.map +0 -1
  75. package/dist/utils/file.d.ts +0 -7
  76. package/dist/utils/file.d.ts.map +0 -1
  77. package/dist/utils/file.js +0 -69
  78. package/dist/utils/file.js.map +0 -1
  79. package/dist/utils/logger.d.ts +0 -14
  80. package/dist/utils/logger.d.ts.map +0 -1
  81. package/dist/utils/logger.js +0 -28
  82. package/dist/utils/logger.js.map +0 -1
  83. package/dist/utils/masker.d.ts +0 -14
  84. package/dist/utils/masker.d.ts.map +0 -1
  85. package/dist/utils/masker.js +0 -89
  86. package/dist/utils/masker.js.map +0 -1
  87. package/src/commands/validate.ts +0 -150
  88. package/src/index.ts +0 -80
  89. package/src/types/index.ts +0 -41
  90. package/src/utils/api.ts +0 -68
  91. package/src/utils/file.ts +0 -71
  92. package/src/utils/logger.ts +0 -27
  93. package/src/utils/masker.ts +0 -101
  94. package/test-sensitive.yaml +0 -109
  95. package/tsconfig.json +0 -23
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Delimit™ OpenAI Function Adapter
4
+ * Implements OpenAI Functions/Tools interface
5
+ */
6
+
7
+ const axios = require('axios');
8
+ const AGENT_URL = `http://127.0.0.1:${process.env.DELIMIT_AGENT_PORT || 7823}`;
9
+
10
+ class DelimitOpenAIFunction {
11
+ constructor() {
12
+ this.name = 'delimit_governance_check';
13
+ this.description = 'Check governance compliance for code operations';
14
+ }
15
+
16
+ /**
17
+ * OpenAI Functions are called as tools
18
+ */
19
+ async execute(args) {
20
+ console.log('[DELIMIT OPENAI] Function called with:', args);
21
+
22
+ try {
23
+ const { action, context } = args;
24
+
25
+ // Validate the action
26
+ const response = await axios.post(`${AGENT_URL}/evaluate`, {
27
+ action: action || 'openai_function',
28
+ context: context,
29
+ tool: 'openai'
30
+ });
31
+
32
+ return {
33
+ allowed: response.data.action !== 'block',
34
+ action: response.data.action,
35
+ message: response.data.message || 'Check complete',
36
+ rule: response.data.rule
37
+ };
38
+ } catch (error) {
39
+ console.warn('[DELIMIT OPENAI] Governance check failed:', error.message);
40
+ return {
41
+ allowed: true,
42
+ message: 'Governance unavailable, proceeding with caution'
43
+ };
44
+ }
45
+ }
46
+
47
+ /**
48
+ * OpenAI Plugins interface
49
+ */
50
+ async handleRequest(request) {
51
+ const { method, path, body } = request;
52
+
53
+ if (path === '/governance/check') {
54
+ return await this.execute(body);
55
+ }
56
+
57
+ if (path === '/governance/status') {
58
+ const { execSync } = require('child_process');
59
+ const status = execSync('delimit status --json').toString();
60
+ return JSON.parse(status);
61
+ }
62
+
63
+ if (path === '/governance/audit') {
64
+ const { execSync } = require('child_process');
65
+ const audit = execSync('delimit audit --json').toString();
66
+ return JSON.parse(audit);
67
+ }
68
+
69
+ return { error: 'Unknown endpoint' };
70
+ }
71
+
72
+ /**
73
+ * Tool definition for OpenAI
74
+ */
75
+ toToolDefinition() {
76
+ return {
77
+ type: 'function',
78
+ function: {
79
+ name: this.name,
80
+ description: this.description,
81
+ parameters: {
82
+ type: 'object',
83
+ properties: {
84
+ action: {
85
+ type: 'string',
86
+ description: 'The action to validate'
87
+ },
88
+ context: {
89
+ type: 'object',
90
+ description: 'Context for validation',
91
+ properties: {
92
+ code: { type: 'string' },
93
+ language: { type: 'string' },
94
+ file: { type: 'string' },
95
+ operation: { type: 'string' }
96
+ }
97
+ }
98
+ },
99
+ required: ['action']
100
+ }
101
+ }
102
+ };
103
+ }
104
+ }
105
+
106
+ // Export for OpenAI
107
+ module.exports = new DelimitOpenAIFunction();
108
+
109
+ // OpenAI registration (if available)
110
+ if (typeof registerFunction === 'function') {
111
+ registerFunction(new DelimitOpenAIFunction());
112
+ }
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Delimit™ xAI Grok Plugin Adapter
4
+ * Implements xAI Plugin interface
5
+ */
6
+
7
+ const axios = require('axios');
8
+ const AGENT_URL = `http://127.0.0.1:${process.env.DELIMIT_AGENT_PORT || 7823}`;
9
+
10
+ class DelimitXAIPlugin {
11
+ constructor() {
12
+ this.name = 'delimit-governance';
13
+ this.version = '2.0.0';
14
+ this.capabilities = ['code_validation', 'security_check', 'audit_logging'];
15
+ }
16
+
17
+ /**
18
+ * xAI Plugins use hooks for different stages
19
+ */
20
+ async prePrompt(context) {
21
+ console.log('[DELIMIT XAI] Pre-prompt validation...');
22
+
23
+ try {
24
+ const { prompt, session, user } = context;
25
+
26
+ // Check for risky prompts
27
+ const riskyPatterns = [
28
+ /sudo/i,
29
+ /rm\s+-rf/i,
30
+ /password/i,
31
+ /credential/i,
32
+ /secret/i
33
+ ];
34
+
35
+ const isRisky = riskyPatterns.some(pattern => pattern.test(prompt));
36
+
37
+ if (isRisky) {
38
+ const response = await axios.post(`${AGENT_URL}/evaluate`, {
39
+ action: 'xai_prompt',
40
+ prompt: prompt,
41
+ riskLevel: 'high',
42
+ session: session,
43
+ tool: 'xai'
44
+ });
45
+
46
+ if (response.data.action === 'block') {
47
+ return {
48
+ block: true,
49
+ message: `[DELIMIT] Prompt blocked: ${response.data.reason}`
50
+ };
51
+ }
52
+
53
+ if (response.data.action === 'prompt') {
54
+ return {
55
+ warning: response.data.message
56
+ };
57
+ }
58
+ }
59
+
60
+ return { allow: true };
61
+ } catch (error) {
62
+ console.warn('[DELIMIT XAI] Governance check failed:', error.message);
63
+ return { allow: true }; // Fail open
64
+ }
65
+ }
66
+
67
+ async postResponse(context) {
68
+ console.log('[DELIMIT XAI] Post-response processing...');
69
+
70
+ try {
71
+ const { response, session, metrics } = context;
72
+
73
+ // Collect evidence
74
+ await axios.post(`${AGENT_URL}/audit`, {
75
+ action: 'xai_response',
76
+ session: session,
77
+ metrics: metrics,
78
+ timestamp: new Date().toISOString()
79
+ });
80
+
81
+ // Check for sensitive data in response
82
+ const sensitivePatterns = [
83
+ /\b[A-Z0-9]{20,}\b/g, // API keys
84
+ /-----BEGIN.*KEY-----/g, // Private keys
85
+ /Bearer\s+[A-Za-z0-9\-._~+\/]+=*/g // Bearer tokens
86
+ ];
87
+
88
+ for (const pattern of sensitivePatterns) {
89
+ if (pattern.test(response)) {
90
+ console.warn('[DELIMIT XAI] ⚠️ Sensitive data detected in response');
91
+ // Could redact or block here
92
+ }
93
+ }
94
+ } catch (error) {
95
+ // Silent fail for audit
96
+ }
97
+
98
+ return context;
99
+ }
100
+
101
+ async validateCode(code, language) {
102
+ console.log('[DELIMIT XAI] Validating code...');
103
+
104
+ try {
105
+ const response = await axios.post(`${AGENT_URL}/evaluate`, {
106
+ action: 'code_validation',
107
+ code: code,
108
+ language: language,
109
+ tool: 'xai'
110
+ });
111
+
112
+ return {
113
+ valid: response.data.action !== 'block',
114
+ issues: response.data.issues || [],
115
+ message: response.data.message
116
+ };
117
+ } catch (error) {
118
+ return { valid: true, message: 'Validation unavailable' };
119
+ }
120
+ }
121
+
122
+ // xAI command interface
123
+ async executeCommand(command, args) {
124
+ const commands = {
125
+ 'governance': () => this.runCLI('status'),
126
+ 'audit': () => this.runCLI('audit'),
127
+ 'mode': () => this.runCLI('mode', args),
128
+ 'policy': () => this.runCLI('policy')
129
+ };
130
+
131
+ if (commands[command]) {
132
+ return await commands[command]();
133
+ }
134
+
135
+ return `Unknown command: ${command}`;
136
+ }
137
+
138
+ runCLI(command, args = []) {
139
+ const { execSync } = require('child_process');
140
+ const cmd = `delimit ${command} ${args.join(' ')}`.trim();
141
+ return execSync(cmd).toString();
142
+ }
143
+ }
144
+
145
+ // Export for xAI
146
+ module.exports = new DelimitXAIPlugin();
147
+
148
+ // xAI registration
149
+ if (typeof registerPlugin === 'function') {
150
+ registerPlugin(new DelimitXAIPlugin());
151
+ }