@ctliz/agent-intercom-claude 0.12.0-connect.3
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/.claude-plugin/plugin.json +26 -0
- package/.mcp.json +10 -0
- package/CHANGELOG.md +62 -0
- package/COPYRIGHT +6 -0
- package/LICENSE +661 -0
- package/LICENSE_TRANSITION.md +25 -0
- package/README.md +506 -0
- package/THIRD_PARTY_NOTICES.md +25 -0
- package/broker/access-credential.ts +76 -0
- package/broker/access-registry.ts +460 -0
- package/broker/audit.ts +60 -0
- package/broker/authorization.ts +125 -0
- package/broker/boss-contracts.ts +267 -0
- package/broker/broker.ts +2028 -0
- package/broker/client.ts +1048 -0
- package/broker/framing.ts +87 -0
- package/broker/ownership.ts +61 -0
- package/broker/paths.ts +161 -0
- package/broker/spawn.ts +463 -0
- package/broker/validation.ts +132 -0
- package/claude/cci.ts +512 -0
- package/claude/ccim.ts +31 -0
- package/claude/cli-runner.ts +220 -0
- package/claude/contact.ts +33 -0
- package/claude/inbox-monitor.ts +49 -0
- package/claude/inbox.ts +77 -0
- package/claude/mcp-protocol.ts +253 -0
- package/claude/native-bridge.ts +219 -0
- package/claude/native-protocol.ts +346 -0
- package/claude/permission-policy.ts +287 -0
- package/claude/runtime.ts +510 -0
- package/claude/server.ts +69 -0
- package/claude/team.ts +348 -0
- package/claude/transport.ts +97 -0
- package/claude/worker-config.ts +198 -0
- package/claude/worker-daemon.ts +418 -0
- package/commands/intercom-id.md +9 -0
- package/commands/intercom.md +8 -0
- package/config.ts +195 -0
- package/dist/broker.mjs +2530 -0
- package/dist/cci.mjs +3607 -0
- package/dist/ccim.mjs +3621 -0
- package/dist/claude-server.mjs +2730 -0
- package/dist/inbox-monitor.mjs +68 -0
- package/dist/worker-daemon.mjs +2797 -0
- package/durable-json.ts +25 -0
- package/licenses/MIT-pi-claude-link.txt +21 -0
- package/licenses/MIT-pi-intercom.txt +21 -0
- package/monitors/monitors.json +8 -0
- package/outbound-outbox.ts +116 -0
- package/package.json +93 -0
- package/protocol-v4/contract.ts +45 -0
- package/provider/protected-service.ts +162 -0
- package/provider/provider.mjs +34 -0
- package/scripts/build.mjs +71 -0
- package/scripts/verify-core-provenance.mjs +64 -0
- package/scripts/verify-packed-runtime.mjs +140 -0
- package/skills/claude-intercom/SKILL.md +90 -0
- package/types.ts +212 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BOSS_CAPABILITY_FEATURE_DIGEST,
|
|
3
|
+
BOSS_POLICY_SEMANTICS_HASH,
|
|
4
|
+
BOSS_RUN_FEATURE,
|
|
5
|
+
BOSS_RUN_FEATURE_CONTRACT,
|
|
6
|
+
INTERCOM_BASE_PROTOCOL_VERSION,
|
|
7
|
+
evaluateBrokerCompatibility,
|
|
8
|
+
parseBossControlEnvelope,
|
|
9
|
+
parseBossParticipantBinding,
|
|
10
|
+
parseBossParticipantCredentialEnvelope,
|
|
11
|
+
parseBossPolicyPrincipal,
|
|
12
|
+
parseBossRunFeatureContract,
|
|
13
|
+
parseBrokerCapabilityAdvertisement,
|
|
14
|
+
isTerminalParticipantState,
|
|
15
|
+
parseParticipantState,
|
|
16
|
+
parseWorkerIdentityV2,
|
|
17
|
+
type BossControlEnvelope,
|
|
18
|
+
type BossControlKind,
|
|
19
|
+
type BossControlType,
|
|
20
|
+
type BossPrivatePrincipal,
|
|
21
|
+
type BrokerCapabilityAdvertisement,
|
|
22
|
+
} from "@ctliz/agent-intercom-core/boss";
|
|
23
|
+
import {
|
|
24
|
+
ContractValidationError,
|
|
25
|
+
assertExactKeys,
|
|
26
|
+
assertRecord,
|
|
27
|
+
readHexDigest,
|
|
28
|
+
} from "@ctliz/agent-intercom-core/canonical";
|
|
29
|
+
import type {
|
|
30
|
+
BossRegistrationRequest,
|
|
31
|
+
BossSessionMetadata,
|
|
32
|
+
SessionInfo,
|
|
33
|
+
} from "../types.ts";
|
|
34
|
+
import { assertPlainDataGraph } from "./validation.ts";
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Stage B deliberately does not advertise boss-run-v1. The protected provider,
|
|
38
|
+
* signed identity, credential lifecycle, transition journal, and coordinated
|
|
39
|
+
* health predicates must land before this can become true.
|
|
40
|
+
*/
|
|
41
|
+
export const BOSS_ADVERTISEMENT_ENABLED = false as const;
|
|
42
|
+
|
|
43
|
+
export function brokerCapabilityAdvertisement(): BrokerCapabilityAdvertisement {
|
|
44
|
+
return parseBrokerCapabilityAdvertisement({
|
|
45
|
+
baseProtocolVersion: INTERCOM_BASE_PROTOCOL_VERSION,
|
|
46
|
+
features: [],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function assertCompatibleOrdinaryAdvertisement(value: unknown): BrokerCapabilityAdvertisement {
|
|
51
|
+
assertPlainDataGraph(value, "$.capabilities");
|
|
52
|
+
const advertisement = parseBrokerCapabilityAdvertisement(value);
|
|
53
|
+
const decision = evaluateBrokerCompatibility({
|
|
54
|
+
clientKind: "ordinary",
|
|
55
|
+
supportedBaseProtocolVersions: [INTERCOM_BASE_PROTOCOL_VERSION],
|
|
56
|
+
}, advertisement);
|
|
57
|
+
if (!decision.compatible || decision.mode !== "ordinary") {
|
|
58
|
+
throw new ContractValidationError("$.capabilities", "broker does not support exact base protocol v3");
|
|
59
|
+
}
|
|
60
|
+
return advertisement;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function assertCompatibleBossAdvertisement(value: unknown): BrokerCapabilityAdvertisement {
|
|
64
|
+
assertPlainDataGraph(value, "$.capabilities");
|
|
65
|
+
const advertisement = parseBrokerCapabilityAdvertisement(value);
|
|
66
|
+
if (
|
|
67
|
+
advertisement.baseProtocolVersion !== INTERCOM_BASE_PROTOCOL_VERSION
|
|
68
|
+
|| !advertisement.features.some((feature) => feature.feature === BOSS_RUN_FEATURE)
|
|
69
|
+
) {
|
|
70
|
+
throw new ContractValidationError("$.capabilities", "broker did not negotiate the exact required Boss feature");
|
|
71
|
+
}
|
|
72
|
+
return advertisement;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function parseBossRegistrationRequest(value: unknown): BossRegistrationRequest {
|
|
76
|
+
assertPlainDataGraph(value, "$.boss");
|
|
77
|
+
assertRecord(value, "$.boss");
|
|
78
|
+
assertExactKeys(value, ["featureContract", "capabilityDigest", "credential"], [], "$.boss");
|
|
79
|
+
const featureContract = parseBossRunFeatureContract(value.featureContract);
|
|
80
|
+
const capabilityDigest = readHexDigest(value.capabilityDigest, "$.boss.capabilityDigest");
|
|
81
|
+
if (
|
|
82
|
+
featureContract.feature !== BOSS_RUN_FEATURE_CONTRACT.feature
|
|
83
|
+
|| featureContract.version !== BOSS_RUN_FEATURE_CONTRACT.version
|
|
84
|
+
|| featureContract.baseProtocolVersion !== INTERCOM_BASE_PROTOCOL_VERSION
|
|
85
|
+
|| featureContract.semanticsHash !== BOSS_RUN_FEATURE_CONTRACT.semanticsHash
|
|
86
|
+
|| featureContract.controlEnvelopeVersion !== BOSS_RUN_FEATURE_CONTRACT.controlEnvelopeVersion
|
|
87
|
+
|| capabilityDigest !== BOSS_CAPABILITY_FEATURE_DIGEST
|
|
88
|
+
) {
|
|
89
|
+
throw new ContractValidationError("$.boss", "Boss registration diverges from the canonical feature contract");
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
featureContract,
|
|
93
|
+
capabilityDigest,
|
|
94
|
+
credential: parseBossParticipantCredentialEnvelope(value.credential),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function parseBossSessionMetadata(value: unknown, sessionId?: string): BossSessionMetadata {
|
|
99
|
+
assertPlainDataGraph(value, "$.boss");
|
|
100
|
+
assertRecord(value, "$.boss");
|
|
101
|
+
assertExactKeys(value, [
|
|
102
|
+
"binding",
|
|
103
|
+
"principal",
|
|
104
|
+
"liveWorker",
|
|
105
|
+
"featureContract",
|
|
106
|
+
"policySemanticsHash",
|
|
107
|
+
"capabilityDigest",
|
|
108
|
+
"brokerIdentityVerified",
|
|
109
|
+
], [], "$.boss");
|
|
110
|
+
const binding = parseBossParticipantBinding(value.binding);
|
|
111
|
+
const parsedPrincipal = parseBossPolicyPrincipal(value.principal);
|
|
112
|
+
if (parsedPrincipal.principalClass !== "boss-private") {
|
|
113
|
+
throw new ContractValidationError("$.boss.principal", "must be a Boss-private principal");
|
|
114
|
+
}
|
|
115
|
+
const principal: BossPrivatePrincipal = parsedPrincipal;
|
|
116
|
+
assertRecord(value.liveWorker, "$.boss.liveWorker");
|
|
117
|
+
assertExactKeys(value.liveWorker, ["identity", "state"], [], "$.boss.liveWorker");
|
|
118
|
+
const liveWorkerIdentity = parseWorkerIdentityV2(value.liveWorker.identity);
|
|
119
|
+
const liveWorkerState = parseParticipantState(value.liveWorker.state, "$.boss.liveWorker.state");
|
|
120
|
+
const featureContract = parseBossRunFeatureContract(value.featureContract);
|
|
121
|
+
const policySemanticsHash = readHexDigest(value.policySemanticsHash, "$.boss.policySemanticsHash");
|
|
122
|
+
const capabilityDigest = readHexDigest(value.capabilityDigest, "$.boss.capabilityDigest");
|
|
123
|
+
if (value.brokerIdentityVerified !== true) {
|
|
124
|
+
throw new ContractValidationError("$.boss.brokerIdentityVerified", "must be true for a live Boss session");
|
|
125
|
+
}
|
|
126
|
+
if (sessionId !== undefined && binding.sessionId !== sessionId) {
|
|
127
|
+
throw new ContractValidationError("$.boss.binding.sessionId", "must match the registered session ID");
|
|
128
|
+
}
|
|
129
|
+
if (sessionId !== undefined && principal.principalId !== sessionId) {
|
|
130
|
+
throw new ContractValidationError("$.boss.principal.principalId", "must match the registered session ID");
|
|
131
|
+
}
|
|
132
|
+
if (
|
|
133
|
+
!("bossRunId" in liveWorkerIdentity)
|
|
134
|
+
|| (sessionId !== undefined && liveWorkerIdentity.workerId !== sessionId)
|
|
135
|
+
|| liveWorkerIdentity.bossRunId !== binding.bossRunId
|
|
136
|
+
|| liveWorkerIdentity.participantId !== binding.participantId
|
|
137
|
+
|| liveWorkerIdentity.bindingEpoch !== binding.bindingEpoch
|
|
138
|
+
|| isTerminalParticipantState(liveWorkerState)
|
|
139
|
+
) {
|
|
140
|
+
throw new ContractValidationError(
|
|
141
|
+
"$.boss.liveWorker",
|
|
142
|
+
"must attest the same live Boss worker identity and binding as the registered session",
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (
|
|
146
|
+
binding.state !== "active"
|
|
147
|
+
|| principal.state !== "active"
|
|
148
|
+
|| binding.bossRunId !== principal.bossRunId
|
|
149
|
+
|| binding.participantId !== principal.participantId
|
|
150
|
+
|| binding.role !== principal.role
|
|
151
|
+
|| binding.bindingEpoch !== principal.bindingEpoch
|
|
152
|
+
|| binding.assignedManagerParticipantId !== principal.assignedManagerParticipantId
|
|
153
|
+
) {
|
|
154
|
+
throw new ContractValidationError("$.boss", "binding and policy principal are not the same active participant");
|
|
155
|
+
}
|
|
156
|
+
if (
|
|
157
|
+
featureContract.semanticsHash !== BOSS_RUN_FEATURE_CONTRACT.semanticsHash
|
|
158
|
+
|| policySemanticsHash !== BOSS_POLICY_SEMANTICS_HASH
|
|
159
|
+
|| capabilityDigest !== BOSS_CAPABILITY_FEATURE_DIGEST
|
|
160
|
+
) {
|
|
161
|
+
throw new ContractValidationError("$.boss", "Boss session attestation diverges from Core");
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
binding,
|
|
165
|
+
principal,
|
|
166
|
+
liveWorker: { identity: liveWorkerIdentity, state: liveWorkerState },
|
|
167
|
+
featureContract,
|
|
168
|
+
policySemanticsHash,
|
|
169
|
+
capabilityDigest,
|
|
170
|
+
brokerIdentityVerified: true,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function assertBossRegistrationEcho(
|
|
175
|
+
requestValue: unknown,
|
|
176
|
+
metadataValue: unknown,
|
|
177
|
+
sessionId: string,
|
|
178
|
+
): BossSessionMetadata {
|
|
179
|
+
const request = parseBossRegistrationRequest(requestValue);
|
|
180
|
+
const metadata = parseBossSessionMetadata(metadataValue, sessionId);
|
|
181
|
+
const credential = request.credential;
|
|
182
|
+
const binding = metadata.binding;
|
|
183
|
+
if (
|
|
184
|
+
credential.bossRunId !== binding.bossRunId
|
|
185
|
+
|| credential.participantId !== binding.participantId
|
|
186
|
+
|| credential.role !== binding.role
|
|
187
|
+
|| credential.communicationProfile !== binding.communicationProfile
|
|
188
|
+
|| credential.bindingEpoch !== binding.bindingEpoch
|
|
189
|
+
|| request.featureContract.feature !== metadata.featureContract.feature
|
|
190
|
+
|| request.featureContract.version !== metadata.featureContract.version
|
|
191
|
+
|| request.featureContract.baseProtocolVersion !== metadata.featureContract.baseProtocolVersion
|
|
192
|
+
|| request.featureContract.semanticsHash !== metadata.featureContract.semanticsHash
|
|
193
|
+
|| request.featureContract.controlEnvelopeVersion !== metadata.featureContract.controlEnvelopeVersion
|
|
194
|
+
|| request.capabilityDigest !== metadata.capabilityDigest
|
|
195
|
+
) {
|
|
196
|
+
throw new ContractValidationError("$.boss", "broker-owned Boss registration echo does not match the requested participant binding");
|
|
197
|
+
}
|
|
198
|
+
return metadata;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export const BOSS_CONTROL_KIND_BY_TYPE = {
|
|
202
|
+
"boss.assignment.created": "assignment_request",
|
|
203
|
+
"boss.assignment.accepted": "assignment_response",
|
|
204
|
+
"boss.assignment.checkpoint": "assignment_response",
|
|
205
|
+
"boss.assignment.submitted": "assignment_response",
|
|
206
|
+
"boss.assignment.rejected": "assignment_response",
|
|
207
|
+
"boss.assignment.cancelled": "lifecycle",
|
|
208
|
+
"boss.staffing.requested": "staffing",
|
|
209
|
+
"boss.staffing.resolved": "staffing",
|
|
210
|
+
"boss.review.requested": "review_request",
|
|
211
|
+
"boss.review.submitted": "review_result",
|
|
212
|
+
"boss.council.requested": "review_request",
|
|
213
|
+
"boss.council.submitted": "review_result",
|
|
214
|
+
"boss.proof.submitted": "proof",
|
|
215
|
+
"boss.worker.health": "health",
|
|
216
|
+
"boss.worker.blocked": "health",
|
|
217
|
+
"boss.worker.failed": "health",
|
|
218
|
+
"boss.worker.notice": "lifecycle",
|
|
219
|
+
"boss.worker.notice_delivery_failed": "lifecycle",
|
|
220
|
+
"boss.decision.required": "decision",
|
|
221
|
+
} as const satisfies Readonly<Record<BossControlType, BossControlKind>>;
|
|
222
|
+
|
|
223
|
+
export function bossControlKind(envelope: BossControlEnvelope): BossControlKind {
|
|
224
|
+
return BOSS_CONTROL_KIND_BY_TYPE[envelope.type];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface BossControlDispatchDenial {
|
|
228
|
+
allowed: false;
|
|
229
|
+
code: "CONTROL_DISPATCH_UNAVAILABLE";
|
|
230
|
+
reason: string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* This adapter has no protected Controller dispatch/ACK authority. Keep the
|
|
235
|
+
* production control surface closed for every target spelling; callers must
|
|
236
|
+
* apply this gate before ordinary name/prefix resolution.
|
|
237
|
+
*/
|
|
238
|
+
export function bossControlDispatchDenial(_target: string): BossControlDispatchDenial {
|
|
239
|
+
return {
|
|
240
|
+
allowed: false,
|
|
241
|
+
code: "CONTROL_DISPATCH_UNAVAILABLE",
|
|
242
|
+
reason: "Typed Boss control dispatch is unavailable without authoritative correlation and durable dispatch",
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export function parseCorrelatedBossControl(value: unknown, messageId?: string): BossControlEnvelope {
|
|
247
|
+
assertPlainDataGraph(value, "$.control");
|
|
248
|
+
const envelope = parseBossControlEnvelope(value);
|
|
249
|
+
if (messageId !== undefined && envelope.messageId !== messageId) {
|
|
250
|
+
throw new ContractValidationError("$.control.messageId", "must match the transport message ID");
|
|
251
|
+
}
|
|
252
|
+
return envelope;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function assertBossControlSender(session: SessionInfo, envelopeValue: unknown, messageId: string): BossControlEnvelope {
|
|
256
|
+
const envelope = parseCorrelatedBossControl(envelopeValue, messageId);
|
|
257
|
+
const metadata = session.boss === undefined ? undefined : parseBossSessionMetadata(session.boss, session.id);
|
|
258
|
+
if (
|
|
259
|
+
metadata === undefined
|
|
260
|
+
|| envelope.bossRunId !== metadata.binding.bossRunId
|
|
261
|
+
|| envelope.participantId !== metadata.binding.participantId
|
|
262
|
+
|| envelope.bindingEpoch !== metadata.binding.bindingEpoch
|
|
263
|
+
) {
|
|
264
|
+
throw new ContractValidationError("$.control", "control identity is not bound to the sending session");
|
|
265
|
+
}
|
|
266
|
+
return envelope;
|
|
267
|
+
}
|