@omnitype-code/agent-sdk 2.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.
- package/dist/index.d.ts +79 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +291 -0
- package/dist/index.js.map +1 -0
- package/package.json +36 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @omnitype-code/agent-sdk — TypeScript/Node.js SDK for AI tools.
|
|
3
|
+
*
|
|
4
|
+
* Tools that embed this SDK directly produce T0 (deterministic) attribution events.
|
|
5
|
+
* The SDK connects to the local journal daemon over UDS and wraps every file write
|
|
6
|
+
* in a txn boundary with exact splices, pre/post hashes, session id, and model.
|
|
7
|
+
*
|
|
8
|
+
* Usage (in an AI tool's write path):
|
|
9
|
+
*
|
|
10
|
+
* import { OmniTypeAgent } from '@omnitype-code/agent-sdk';
|
|
11
|
+
* const agent = await OmniTypeAgent.connect({ workspace, sessionId, model, tool });
|
|
12
|
+
*
|
|
13
|
+
* // Wrap each file write:
|
|
14
|
+
* await agent.withEdit(filePath, async () => {
|
|
15
|
+
* await yourWriteFunction(filePath, newContent);
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Or fine-grained:
|
|
19
|
+
* const txn = await agent.beginTxn([filePath]);
|
|
20
|
+
* await yourWriteFunction(filePath, newContent);
|
|
21
|
+
* await agent.commitTxn(txn, [{ path: filePath, preHash, postHash, splices }]);
|
|
22
|
+
*/
|
|
23
|
+
export interface AgentConfig {
|
|
24
|
+
workspace: string;
|
|
25
|
+
sessionId: string;
|
|
26
|
+
model: string;
|
|
27
|
+
tool: string;
|
|
28
|
+
parentSession?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface Splice {
|
|
31
|
+
offset: number;
|
|
32
|
+
delete_len: number;
|
|
33
|
+
insert_text: string;
|
|
34
|
+
}
|
|
35
|
+
export interface EditRecord {
|
|
36
|
+
path: string;
|
|
37
|
+
preHash: string;
|
|
38
|
+
postHash: string;
|
|
39
|
+
splices: Splice[];
|
|
40
|
+
}
|
|
41
|
+
export interface TxnHandle {
|
|
42
|
+
txnId: string;
|
|
43
|
+
expectedFiles: string[];
|
|
44
|
+
startedAt: number;
|
|
45
|
+
}
|
|
46
|
+
export declare class OmniTypeAgent {
|
|
47
|
+
private readonly config;
|
|
48
|
+
private readonly socketPath;
|
|
49
|
+
private socket;
|
|
50
|
+
private buf;
|
|
51
|
+
private pending;
|
|
52
|
+
private idCounter;
|
|
53
|
+
private constructor();
|
|
54
|
+
static connect(config: AgentConfig): Promise<OmniTypeAgent>;
|
|
55
|
+
/**
|
|
56
|
+
* Connect if daemon is running, return null otherwise (graceful degradation).
|
|
57
|
+
* Pass `{ policyMode: 'strict' }` to throw instead of returning null — for org
|
|
58
|
+
* compliance enforcement where un-journaled AI use must be blocked. (Day 10 fix: §10.1)
|
|
59
|
+
*/
|
|
60
|
+
static tryConnect(config: AgentConfig, opts?: {
|
|
61
|
+
policyMode?: 'permissive' | 'strict';
|
|
62
|
+
}): Promise<OmniTypeAgent | null>;
|
|
63
|
+
beginTxn(expectedFiles: string[]): Promise<TxnHandle>;
|
|
64
|
+
commitTxn(txn: TxnHandle, edits: EditRecord[]): Promise<void>;
|
|
65
|
+
abortTxn(txn: TxnHandle, reason: string): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Wrap a single file write with automatic txn, pre/post hashing, and exact splice.
|
|
68
|
+
* The `write` callback receives the resolved absolute path and should perform the write.
|
|
69
|
+
*/
|
|
70
|
+
withEdit(relPath: string, newContent: string, write: (absPath: string, content: string) => Promise<void>): Promise<void>;
|
|
71
|
+
emitPrompt(promptText: string, shareText?: boolean): Promise<void>;
|
|
72
|
+
end(reason?: 'user' | 'timeout' | 'tool-exit'): Promise<void>;
|
|
73
|
+
private makeActor;
|
|
74
|
+
private openSocket;
|
|
75
|
+
private send;
|
|
76
|
+
}
|
|
77
|
+
export declare function hashFile(absPath: string): string;
|
|
78
|
+
export declare function hashBytes(buf: Buffer): string;
|
|
79
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,qBAAa,aAAa;IAOtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAP7B,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,OAAO,CAAoF;IACnG,OAAO,CAAC,SAAS,CAAK;IAEtB,OAAO;WAOM,OAAO,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IA4BjE;;;;OAIG;WACU,UAAU,CACrB,MAAM,EAAE,WAAW,EACnB,IAAI,GAAE;QAAE,UAAU,CAAC,EAAE,YAAY,GAAG,QAAQ,CAAA;KAAO,GAClD,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAgB1B,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC;IAiBrD,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC7D,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7D;;;OAGG;IACG,QAAQ,CACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,GACzD,OAAO,CAAC,IAAI,CAAC;IAwBV,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,UAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhE,GAAG,CAAC,MAAM,GAAE,MAAM,GAAG,SAAS,GAAG,WAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;IAchF,OAAO,CAAC,SAAS;IAcjB,OAAO,CAAC,UAAU;IA8BlB,OAAO,CAAC,IAAI;CAQb;AASD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMhD;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @omnitype-code/agent-sdk — TypeScript/Node.js SDK for AI tools.
|
|
3
|
+
*
|
|
4
|
+
* Tools that embed this SDK directly produce T0 (deterministic) attribution events.
|
|
5
|
+
* The SDK connects to the local journal daemon over UDS and wraps every file write
|
|
6
|
+
* in a txn boundary with exact splices, pre/post hashes, session id, and model.
|
|
7
|
+
*
|
|
8
|
+
* Usage (in an AI tool's write path):
|
|
9
|
+
*
|
|
10
|
+
* import { OmniTypeAgent } from '@omnitype-code/agent-sdk';
|
|
11
|
+
* const agent = await OmniTypeAgent.connect({ workspace, sessionId, model, tool });
|
|
12
|
+
*
|
|
13
|
+
* // Wrap each file write:
|
|
14
|
+
* await agent.withEdit(filePath, async () => {
|
|
15
|
+
* await yourWriteFunction(filePath, newContent);
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* // Or fine-grained:
|
|
19
|
+
* const txn = await agent.beginTxn([filePath]);
|
|
20
|
+
* await yourWriteFunction(filePath, newContent);
|
|
21
|
+
* await agent.commitTxn(txn, [{ path: filePath, preHash, postHash, splices }]);
|
|
22
|
+
*/
|
|
23
|
+
import * as net from 'node:net';
|
|
24
|
+
import * as crypto from 'node:crypto';
|
|
25
|
+
import * as fs from 'node:fs';
|
|
26
|
+
import * as path from 'node:path';
|
|
27
|
+
import * as os from 'node:os';
|
|
28
|
+
// ─── OmniTypeAgent ────────────────────────────────────────────────────────────
|
|
29
|
+
export class OmniTypeAgent {
|
|
30
|
+
config;
|
|
31
|
+
socketPath;
|
|
32
|
+
socket = null;
|
|
33
|
+
buf = '';
|
|
34
|
+
pending = new Map();
|
|
35
|
+
idCounter = 0;
|
|
36
|
+
constructor(config, socketPath) {
|
|
37
|
+
this.config = config;
|
|
38
|
+
this.socketPath = socketPath;
|
|
39
|
+
}
|
|
40
|
+
// ─── Factory ──────────────────────────────────────────────────────────────
|
|
41
|
+
static async connect(config) {
|
|
42
|
+
const socketPath = getSocketPath(config.workspace);
|
|
43
|
+
const agent = new OmniTypeAgent(config, socketPath);
|
|
44
|
+
await agent.openSocket();
|
|
45
|
+
// Emit SessionStarted with prompt_deferred=true — prompt hash bound later via
|
|
46
|
+
// emitPrompt(). This allows the chain to prove session↔prompt link when supplied.
|
|
47
|
+
// (Day 19 fix: §1.4)
|
|
48
|
+
await agent.send('append', {
|
|
49
|
+
actor: agent.makeActor(),
|
|
50
|
+
body: {
|
|
51
|
+
type: 'SessionStarted',
|
|
52
|
+
session_id: config.sessionId,
|
|
53
|
+
tool: config.tool,
|
|
54
|
+
model: config.model,
|
|
55
|
+
prompt_hash: '0'.repeat(64),
|
|
56
|
+
prompt_bytes: 0,
|
|
57
|
+
prompt_deferred: true,
|
|
58
|
+
...(config.parentSession ? { parent_session: config.parentSession } : {}),
|
|
59
|
+
},
|
|
60
|
+
tier: 'T0',
|
|
61
|
+
adapter_id: `${config.tool}-agent-sdk`,
|
|
62
|
+
sync: false,
|
|
63
|
+
});
|
|
64
|
+
return agent;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Connect if daemon is running, return null otherwise (graceful degradation).
|
|
68
|
+
* Pass `{ policyMode: 'strict' }` to throw instead of returning null — for org
|
|
69
|
+
* compliance enforcement where un-journaled AI use must be blocked. (Day 10 fix: §10.1)
|
|
70
|
+
*/
|
|
71
|
+
static async tryConnect(config, opts = {}) {
|
|
72
|
+
try {
|
|
73
|
+
return await OmniTypeAgent.connect(config);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (opts.policyMode === 'strict') {
|
|
77
|
+
throw new Error(`[omnitype] org-policy requires journal daemon — cannot proceed without attribution. ` +
|
|
78
|
+
`Start daemon with: omnitype-daemon start. Cause: ${String(err)}`);
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// ─── Transaction API ──────────────────────────────────────────────────────
|
|
84
|
+
async beginTxn(expectedFiles) {
|
|
85
|
+
const txnId = crypto.randomBytes(16).toString('hex');
|
|
86
|
+
await this.send('append', {
|
|
87
|
+
actor: this.makeActor(),
|
|
88
|
+
body: {
|
|
89
|
+
type: 'TxnBegin',
|
|
90
|
+
txn_id: txnId,
|
|
91
|
+
session_id: this.config.sessionId,
|
|
92
|
+
expected_files: expectedFiles,
|
|
93
|
+
},
|
|
94
|
+
tier: 'T0',
|
|
95
|
+
adapter_id: `${this.config.tool}-agent-sdk`,
|
|
96
|
+
sync: true, // synchronous — ensures TxnBegin is flushed before file write
|
|
97
|
+
});
|
|
98
|
+
return { txnId, expectedFiles, startedAt: Date.now() };
|
|
99
|
+
}
|
|
100
|
+
async commitTxn(txn, edits) {
|
|
101
|
+
const editSeqs = [];
|
|
102
|
+
for (const edit of edits) {
|
|
103
|
+
const result = await this.send('append', {
|
|
104
|
+
actor: this.makeActor(),
|
|
105
|
+
body: {
|
|
106
|
+
type: 'EditOp',
|
|
107
|
+
path: edit.path,
|
|
108
|
+
pre_hash: edit.preHash,
|
|
109
|
+
post_hash: edit.postHash,
|
|
110
|
+
ops: edit.splices,
|
|
111
|
+
origin: 'ai',
|
|
112
|
+
intent: 'edit-tool',
|
|
113
|
+
},
|
|
114
|
+
tier: 'T0',
|
|
115
|
+
adapter_id: `${this.config.tool}-agent-sdk`,
|
|
116
|
+
sync: false,
|
|
117
|
+
});
|
|
118
|
+
editSeqs.push(result.seq);
|
|
119
|
+
}
|
|
120
|
+
await this.send('append', {
|
|
121
|
+
actor: this.makeActor(),
|
|
122
|
+
body: {
|
|
123
|
+
type: 'TxnCommit',
|
|
124
|
+
txn_id: txn.txnId,
|
|
125
|
+
event_seqs: editSeqs,
|
|
126
|
+
},
|
|
127
|
+
tier: 'T0',
|
|
128
|
+
adapter_id: `${this.config.tool}-agent-sdk`,
|
|
129
|
+
sync: true,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
async abortTxn(txn, reason) {
|
|
133
|
+
await this.send('append', {
|
|
134
|
+
actor: this.makeActor(),
|
|
135
|
+
body: { type: 'TxnAbort', txn_id: txn.txnId, reason },
|
|
136
|
+
tier: 'T0',
|
|
137
|
+
adapter_id: `${this.config.tool}-agent-sdk`,
|
|
138
|
+
sync: false,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
// ─── High-level wrapper ───────────────────────────────────────────────────
|
|
142
|
+
/**
|
|
143
|
+
* Wrap a single file write with automatic txn, pre/post hashing, and exact splice.
|
|
144
|
+
* The `write` callback receives the resolved absolute path and should perform the write.
|
|
145
|
+
*/
|
|
146
|
+
async withEdit(relPath, newContent, write) {
|
|
147
|
+
const absPath = path.join(this.config.workspace, relPath);
|
|
148
|
+
const preHash = hashFile(absPath);
|
|
149
|
+
// Read BEFORE write so delete_len reflects actual prior content (Day 1 fix: §1.2)
|
|
150
|
+
const oldContent = tryRead(absPath) ?? '';
|
|
151
|
+
const txn = await this.beginTxn([relPath]);
|
|
152
|
+
try {
|
|
153
|
+
await write(absPath, newContent);
|
|
154
|
+
const postHash = hashBytes(Buffer.from(newContent, 'utf-8'));
|
|
155
|
+
await this.commitTxn(txn, [{
|
|
156
|
+
path: relPath,
|
|
157
|
+
preHash,
|
|
158
|
+
postHash,
|
|
159
|
+
splices: [{ offset: 0, delete_len: Buffer.byteLength(oldContent, 'utf-8'), insert_text: newContent }],
|
|
160
|
+
}]);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
await this.abortTxn(txn, String(err));
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// ─── Prompt emission ──────────────────────────────────────────────────────
|
|
168
|
+
async emitPrompt(promptText, shareText = false) {
|
|
169
|
+
const hash = crypto.createHash('sha256').update(promptText).digest('hex');
|
|
170
|
+
await this.send('append', {
|
|
171
|
+
actor: this.makeActor(),
|
|
172
|
+
body: {
|
|
173
|
+
type: 'PromptCapture',
|
|
174
|
+
session_id: this.config.sessionId,
|
|
175
|
+
prompt_id: hash.slice(0, 32),
|
|
176
|
+
prompt_hash: hash,
|
|
177
|
+
prompt_bytes: Buffer.byteLength(promptText, 'utf-8'),
|
|
178
|
+
...(shareText ? { prompt_text: promptText } : {}),
|
|
179
|
+
privacy_marks: detectPrivacyMarks(promptText),
|
|
180
|
+
client_scrubbed: false,
|
|
181
|
+
},
|
|
182
|
+
tier: 'T0',
|
|
183
|
+
adapter_id: `${this.config.tool}-agent-sdk`,
|
|
184
|
+
sync: false,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
// ─── Session close ────────────────────────────────────────────────────────
|
|
188
|
+
async end(reason = 'tool-exit') {
|
|
189
|
+
await this.send('append', {
|
|
190
|
+
actor: this.makeActor(),
|
|
191
|
+
body: { type: 'SessionEnded', session_id: this.config.sessionId, reason },
|
|
192
|
+
tier: 'T0',
|
|
193
|
+
adapter_id: `${this.config.tool}-agent-sdk`,
|
|
194
|
+
sync: true,
|
|
195
|
+
});
|
|
196
|
+
this.socket?.destroy();
|
|
197
|
+
this.socket = null;
|
|
198
|
+
}
|
|
199
|
+
// ─── Internals ────────────────────────────────────────────────────────────
|
|
200
|
+
makeActor() {
|
|
201
|
+
return {
|
|
202
|
+
kind: 'ai',
|
|
203
|
+
tool: this.config.tool,
|
|
204
|
+
model: this.config.model,
|
|
205
|
+
session_id: this.config.sessionId,
|
|
206
|
+
tool_pid: process.pid,
|
|
207
|
+
tool_ppid: process.ppid,
|
|
208
|
+
user: os.userInfo().username,
|
|
209
|
+
host: os.hostname(),
|
|
210
|
+
workspace: this.config.workspace,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
openSocket() {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
const s = net.createConnection(this.socketPath);
|
|
216
|
+
s.on('connect', () => {
|
|
217
|
+
this.socket = s;
|
|
218
|
+
resolve();
|
|
219
|
+
});
|
|
220
|
+
s.on('data', (chunk) => {
|
|
221
|
+
this.buf += chunk.toString('utf-8');
|
|
222
|
+
const lines = this.buf.split('\n');
|
|
223
|
+
this.buf = lines.pop() ?? '';
|
|
224
|
+
for (const line of lines) {
|
|
225
|
+
if (!line.trim())
|
|
226
|
+
continue;
|
|
227
|
+
try {
|
|
228
|
+
const reply = JSON.parse(line);
|
|
229
|
+
const handler = this.pending.get(reply.id);
|
|
230
|
+
if (!handler)
|
|
231
|
+
continue;
|
|
232
|
+
this.pending.delete(reply.id);
|
|
233
|
+
reply.ok ? handler.resolve(reply.payload) : handler.reject(new Error(reply.error));
|
|
234
|
+
}
|
|
235
|
+
catch { /* skip */ }
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
s.on('error', reject);
|
|
239
|
+
s.on('close', () => {
|
|
240
|
+
for (const { reject: rej } of this.pending.values())
|
|
241
|
+
rej(new Error('daemon disconnected'));
|
|
242
|
+
this.pending.clear();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
send(type, payload) {
|
|
247
|
+
const id = String(++this.idCounter);
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
249
|
+
if (!this.socket) {
|
|
250
|
+
reject(new Error('not connected'));
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
this.pending.set(id, { resolve, reject });
|
|
254
|
+
this.socket.write(JSON.stringify({ type, id, payload }) + '\n');
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
|
259
|
+
function getSocketPath(workspace) {
|
|
260
|
+
if (process.platform === 'win32')
|
|
261
|
+
return '\\\\.\\pipe\\omnitype-journal';
|
|
262
|
+
return path.join(workspace, '.omnitype', 'journal', 'daemon.sock');
|
|
263
|
+
}
|
|
264
|
+
export function hashFile(absPath) {
|
|
265
|
+
try {
|
|
266
|
+
return crypto.createHash('sha256').update(fs.readFileSync(absPath)).digest('hex');
|
|
267
|
+
}
|
|
268
|
+
catch {
|
|
269
|
+
return '0'.repeat(64);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export function hashBytes(buf) {
|
|
273
|
+
return crypto.createHash('sha256').update(buf).digest('hex');
|
|
274
|
+
}
|
|
275
|
+
function tryRead(absPath) {
|
|
276
|
+
try {
|
|
277
|
+
return fs.readFileSync(absPath, 'utf-8');
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function detectPrivacyMarks(text) {
|
|
284
|
+
const marks = [];
|
|
285
|
+
if (/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/.test(text))
|
|
286
|
+
marks.push('pii-suspected');
|
|
287
|
+
if (/\b(sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{36}|AKIA[A-Z0-9]{16})\b/.test(text))
|
|
288
|
+
marks.push('secret-detected');
|
|
289
|
+
return marks;
|
|
290
|
+
}
|
|
291
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AA6B9B,iFAAiF;AAEjF,MAAM,OAAO,aAAa;IAOL;IACA;IAPX,MAAM,GAAsB,IAAI,CAAC;IACjC,GAAG,GAAG,EAAE,CAAC;IACT,OAAO,GAAG,IAAI,GAAG,EAAyE,CAAC;IAC3F,SAAS,GAAG,CAAC,CAAC;IAEtB,YACmB,MAAmB,EACnB,UAAkB;QADlB,WAAM,GAAN,MAAM,CAAa;QACnB,eAAU,GAAV,UAAU,CAAQ;IAClC,CAAC;IAEJ,6EAA6E;IAE7E,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAmB;QACtC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACpD,MAAM,KAAK,CAAC,UAAU,EAAE,CAAC;QAEzB,8EAA8E;QAC9E,kFAAkF;QAClF,qBAAqB;QACrB,MAAM,KAAK,CAAC,IAAI,CAAC,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,EAAE,CAAC,CAAC;IACxB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,OAAO,CAAC,OAAe;IAC9B,IAAI,CAAC;QAAC,OAAO,EAAE,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;AAC1E,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAY;IACtC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,oDAAoD,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IACjG,IAAI,gEAAgE,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC/G,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@omnitype-code/agent-sdk",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "OmniType v2 — SDK for AI tools to emit T0 deterministic attribution events",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"prepublishOnly": "npm run build"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@omnitype-code/journal": "^2.0.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.0.0",
|
|
22
|
+
"typescript": "~5.9.3"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=20.0.0"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/omnitype-code/omnitype-v2"
|
|
34
|
+
},
|
|
35
|
+
"keywords": ["attribution", "ai-coding", "agent-sdk", "deterministic", "T0"]
|
|
36
|
+
}
|