@canonmsg/backend-contracts 2.0.0 → 2.2.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/canon-verb-wire.schema.json +367 -0
- package/dist/canon-verbs.limits.json +70 -0
- package/dist/canon-verbs.schema.json +1744 -0
- package/dist/cjs/diffRedaction.js +73 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/message.js +44 -1
- package/dist/cjs/verbContract.js +288 -0
- package/dist/cjs/verbSchemas.js +1144 -0
- package/dist/cjs/verbWire.js +634 -0
- package/dist/diffRedaction.d.ts +6 -0
- package/dist/diffRedaction.js +68 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/message.d.ts +31 -1
- package/dist/message.js +44 -1
- package/dist/verbContract.d.ts +760 -0
- package/dist/verbContract.js +283 -0
- package/dist/verbSchemas.d.ts +1460 -0
- package/dist/verbSchemas.js +1139 -0
- package/dist/verbWire.d.ts +405 -0
- package/dist/verbWire.js +628 -0
- package/package.json +8 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Sensitive-content protection for approval diffs.
|
|
2
|
+
//
|
|
3
|
+
// Approval diffs include PRE-IMAGE context lines and ride on a message readable
|
|
4
|
+
// by every conversation member, so a secret-bearing file would leak existing
|
|
5
|
+
// secrets. The emitting host applies this before sending (it owns the file
|
|
6
|
+
// context); the server (@canonmsg/functions) mirrors the same suppression
|
|
7
|
+
// defensively. Single-sourced here in the zero-dependency backend-contracts
|
|
8
|
+
// leaf so @canonmsg/core (client-side sanitizer) and Functions (server mirror)
|
|
9
|
+
// share one implementation — Functions deliberately does not depend on core.
|
|
10
|
+
//
|
|
11
|
+
// Two deliberately narrow mechanisms so ordinary code diffs stay readable:
|
|
12
|
+
// 1. Path suppression — files whose path screams "secret store" lose their
|
|
13
|
+
// hunk text entirely; entry/status/counts survive.
|
|
14
|
+
// 2. High-confidence token redaction — prefix-anchored credential shapes
|
|
15
|
+
// (AWS/GitHub/Slack/Google/OpenAI-style keys, JWTs) are replaced with
|
|
16
|
+
// `[redacted]` inside remaining hunks. Private-key blocks suppress the
|
|
17
|
+
// whole file (redacting a PEM body line-by-line is fragile).
|
|
18
|
+
const SENSITIVE_DIFF_BASENAME_PATTERNS = [
|
|
19
|
+
/^\.env(\..+)?$/i,
|
|
20
|
+
/^\.npmrc$/i,
|
|
21
|
+
/^\.netrc$/i,
|
|
22
|
+
/^\.pgpass$/i,
|
|
23
|
+
/^\.git-credentials$/i,
|
|
24
|
+
/^\.htpasswd$/i,
|
|
25
|
+
/\.(pem|key|p12|pfx|keystore|jks|tfvars)$/i,
|
|
26
|
+
/^id_(rsa|dsa|ecdsa|ed25519)(\..+)?$/i,
|
|
27
|
+
// Word-bounded so "secrets.json" and "client_secret.yaml" match but
|
|
28
|
+
// "secretary.ts" does not.
|
|
29
|
+
/(^|[-_.])(credentials?|secrets?)([-_.]|$)/i,
|
|
30
|
+
/^serviceaccount.*\.json$/i,
|
|
31
|
+
/^kubeconfig(\..+)?$/i,
|
|
32
|
+
];
|
|
33
|
+
// Directory components that mark everything beneath them sensitive
|
|
34
|
+
// (~/.ssh/config, .aws/credentials, infra/secrets/db.yaml, …).
|
|
35
|
+
const SENSITIVE_DIFF_SEGMENT_PATTERNS = [
|
|
36
|
+
/^\.ssh$/i,
|
|
37
|
+
/^\.aws$/i,
|
|
38
|
+
/^\.gnupg$/i,
|
|
39
|
+
/^\.kube$/i,
|
|
40
|
+
/^secrets?$/i,
|
|
41
|
+
/^credentials?$/i,
|
|
42
|
+
];
|
|
43
|
+
const SECRET_TOKEN_PATTERNS = [
|
|
44
|
+
/AKIA[0-9A-Z]{16}/g,
|
|
45
|
+
/gh[pousr]_[A-Za-z0-9]{36,255}/g,
|
|
46
|
+
/github_pat_[A-Za-z0-9_]{22,255}/g,
|
|
47
|
+
/xox[baprs]-[A-Za-z0-9-]{10,250}/g,
|
|
48
|
+
/AIza[0-9A-Za-z_-]{35}/g,
|
|
49
|
+
/sk-[A-Za-z0-9_-]{20,250}/g,
|
|
50
|
+
/eyJ[A-Za-z0-9_-]{10,}\.eyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
|
|
51
|
+
];
|
|
52
|
+
/** Matches the header line of a PEM private-key block. */
|
|
53
|
+
export const PRIVATE_KEY_BLOCK = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY( BLOCK)?-----/;
|
|
54
|
+
/** True when a diff file path (or rename source) matches the sensitive list. */
|
|
55
|
+
export function isSensitiveDiffPath(path) {
|
|
56
|
+
const segments = path.split('/').filter(Boolean);
|
|
57
|
+
const basename = segments.pop() ?? path;
|
|
58
|
+
return SENSITIVE_DIFF_BASENAME_PATTERNS.some((pattern) => pattern.test(basename))
|
|
59
|
+
|| segments.some((segment) => SENSITIVE_DIFF_SEGMENT_PATTERNS.some((pattern) => pattern.test(segment)));
|
|
60
|
+
}
|
|
61
|
+
/** Replace high-confidence credential shapes inside hunk text with `[redacted]`. */
|
|
62
|
+
export function redactSecretTokens(text) {
|
|
63
|
+
let redacted = text;
|
|
64
|
+
for (const pattern of SECRET_TOKEN_PATTERNS) {
|
|
65
|
+
redacted = redacted.replace(pattern, '[redacted]');
|
|
66
|
+
}
|
|
67
|
+
return redacted;
|
|
68
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './diffRedaction.js';
|
|
1
2
|
export * from './media.js';
|
|
2
3
|
export * from './message.js';
|
|
3
4
|
export * from './runtimeCardFields.js';
|
|
@@ -5,3 +6,6 @@ export * from './runtimeCardStorage.js';
|
|
|
5
6
|
export * from './turnProtocol.js';
|
|
6
7
|
export * from './agentBehaviorPolicy.js';
|
|
7
8
|
export * from './contactRequest.js';
|
|
9
|
+
export * from './verbContract.js';
|
|
10
|
+
export * from './verbSchemas.js';
|
|
11
|
+
export * from './verbWire.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './diffRedaction.js';
|
|
1
2
|
export * from './media.js';
|
|
2
3
|
export * from './message.js';
|
|
3
4
|
export * from './runtimeCardFields.js';
|
|
@@ -5,3 +6,6 @@ export * from './runtimeCardStorage.js';
|
|
|
5
6
|
export * from './turnProtocol.js';
|
|
6
7
|
export * from './agentBehaviorPolicy.js';
|
|
7
8
|
export * from './contactRequest.js';
|
|
9
|
+
export * from './verbContract.js';
|
|
10
|
+
export * from './verbSchemas.js';
|
|
11
|
+
export * from './verbWire.js';
|
package/dist/message.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MediaAttachment } from './media.js';
|
|
2
2
|
export type SerializedSenderType = 'human' | 'ai_agent';
|
|
3
3
|
export type SerializedAgentClientType = 'claude-code' | 'openclaw' | 'codex' | 'hermes' | 'generic';
|
|
4
|
-
export type SerializedContentType = 'text' | 'image' | 'audio' | 'video' | 'file' | 'contact_card';
|
|
4
|
+
export type SerializedContentType = 'text' | 'image' | 'audio' | 'video' | 'file' | 'contact_card' | 'interaction';
|
|
5
5
|
export interface ForwardedFrom {
|
|
6
6
|
sourceConversationId: string;
|
|
7
7
|
messageId: string;
|
|
@@ -40,8 +40,38 @@ export interface SerializedMessage {
|
|
|
40
40
|
contactCard?: SerializedContactCard;
|
|
41
41
|
/** Durable canon.card.v1 runtime card content, passed through opaquely. */
|
|
42
42
|
runtimeCard?: Record<string, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Plaintext, server-authorized interaction envelope for `contentType:
|
|
45
|
+
* 'interaction'` messages (card / input / approval / plan / contact). The
|
|
46
|
+
* authorization contract (`response`) and preview live here; the opaque
|
|
47
|
+
* request payload rides in `body`.
|
|
48
|
+
*/
|
|
49
|
+
interaction?: SerializedInteraction;
|
|
50
|
+
/** Opaque interaction payload (JSON string or ciphertext); never parsed here. */
|
|
51
|
+
body?: string;
|
|
43
52
|
reactions?: SerializedReactions;
|
|
44
53
|
}
|
|
54
|
+
export type SerializedInteractionKind = 'contact' | 'approval' | 'input' | 'plan' | 'card';
|
|
55
|
+
export interface SerializedInteraction {
|
|
56
|
+
kind: SerializedInteractionKind;
|
|
57
|
+
requestId: string;
|
|
58
|
+
interactive: boolean;
|
|
59
|
+
responseUserId?: string;
|
|
60
|
+
expiresAt?: string;
|
|
61
|
+
schemaVersion?: string;
|
|
62
|
+
preview?: {
|
|
63
|
+
title?: string;
|
|
64
|
+
blockKinds?: string[];
|
|
65
|
+
};
|
|
66
|
+
response?: {
|
|
67
|
+
actionIds?: string[];
|
|
68
|
+
actionFields?: Record<string, unknown>;
|
|
69
|
+
questions?: Array<{
|
|
70
|
+
id: string;
|
|
71
|
+
sensitive?: boolean;
|
|
72
|
+
}>;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
45
75
|
export interface SerializeMessageInput {
|
|
46
76
|
id: string;
|
|
47
77
|
data: Record<string, unknown>;
|
package/dist/message.js
CHANGED
|
@@ -58,7 +58,8 @@ function normalizeContentType(value) {
|
|
|
58
58
|
|| value === 'audio'
|
|
59
59
|
|| value === 'video'
|
|
60
60
|
|| value === 'file'
|
|
61
|
-
|| value === 'contact_card'
|
|
61
|
+
|| value === 'contact_card'
|
|
62
|
+
|| value === 'interaction') {
|
|
62
63
|
return value;
|
|
63
64
|
}
|
|
64
65
|
throw new Error('Message is missing canonical contentType');
|
|
@@ -107,6 +108,41 @@ function normalizeContactCard(value) {
|
|
|
107
108
|
card.lifecycleState = value.lifecycleState;
|
|
108
109
|
return card;
|
|
109
110
|
}
|
|
111
|
+
const INTERACTION_KINDS = [
|
|
112
|
+
'contact', 'approval', 'input', 'plan', 'card',
|
|
113
|
+
];
|
|
114
|
+
function normalizeInteraction(value) {
|
|
115
|
+
if (!isRecord(value))
|
|
116
|
+
return undefined;
|
|
117
|
+
if (!INTERACTION_KINDS.includes(value.kind))
|
|
118
|
+
return undefined;
|
|
119
|
+
if (typeof value.requestId !== 'string' || value.requestId.length === 0)
|
|
120
|
+
return undefined;
|
|
121
|
+
const envelope = {
|
|
122
|
+
kind: value.kind,
|
|
123
|
+
requestId: value.requestId,
|
|
124
|
+
interactive: value.interactive === true,
|
|
125
|
+
};
|
|
126
|
+
if (typeof value.responseUserId === 'string')
|
|
127
|
+
envelope.responseUserId = value.responseUserId;
|
|
128
|
+
if (typeof value.expiresAt === 'string')
|
|
129
|
+
envelope.expiresAt = value.expiresAt;
|
|
130
|
+
if (typeof value.schemaVersion === 'string')
|
|
131
|
+
envelope.schemaVersion = value.schemaVersion;
|
|
132
|
+
if (isRecord(value.preview)) {
|
|
133
|
+
const preview = {};
|
|
134
|
+
if (typeof value.preview.title === 'string')
|
|
135
|
+
preview.title = value.preview.title;
|
|
136
|
+
if (Array.isArray(value.preview.blockKinds)) {
|
|
137
|
+
preview.blockKinds = value.preview.blockKinds.filter((entry) => typeof entry === 'string');
|
|
138
|
+
}
|
|
139
|
+
envelope.preview = preview;
|
|
140
|
+
}
|
|
141
|
+
if (isRecord(value.response)) {
|
|
142
|
+
envelope.response = value.response;
|
|
143
|
+
}
|
|
144
|
+
return envelope;
|
|
145
|
+
}
|
|
110
146
|
export function serializeStoredMessage(input) {
|
|
111
147
|
const { data } = input;
|
|
112
148
|
const attachments = data.attachments === undefined
|
|
@@ -150,6 +186,13 @@ export function serializeStoredMessage(input) {
|
|
|
150
186
|
if (runtimeCard) {
|
|
151
187
|
result.runtimeCard = runtimeCard;
|
|
152
188
|
}
|
|
189
|
+
const interaction = normalizeInteraction(data.interaction);
|
|
190
|
+
if (interaction) {
|
|
191
|
+
result.interaction = interaction;
|
|
192
|
+
}
|
|
193
|
+
if (typeof data.body === 'string') {
|
|
194
|
+
result.body = data.body;
|
|
195
|
+
}
|
|
153
196
|
const reactions = normalizeReactions(data.reactions);
|
|
154
197
|
if (reactions) {
|
|
155
198
|
result.reactions = reactions;
|