@harrylabsj/kiwi 0.7.9 → 0.7.11

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 (100) hide show
  1. package/contracts/commerce-intent/1.0/schema.json +124 -0
  2. package/contracts/delegation-policy/1.0/schema.json +143 -0
  3. package/contracts/effective-authorization/1.0/schema.json +167 -0
  4. package/contracts/kiwi-contracts.lock.json +1 -1
  5. package/contracts/manifest.json +25 -1
  6. package/contracts/persistent-task/1.0/schema.json +191 -0
  7. package/contracts/vectors/commerce-intent.invalid-no-items.json +7 -0
  8. package/contracts/vectors/commerce-intent.valid.json +32 -0
  9. package/contracts/vectors/delegation-policy.invalid-payment-auto.json +15 -0
  10. package/contracts/vectors/delegation-policy.valid.json +25 -0
  11. package/contracts/vectors/effective-authorization.invalid-deny-wins.json +20 -0
  12. package/contracts/vectors/effective-authorization.valid.json +23 -0
  13. package/contracts/vectors/persistent-task.invalid-no-idempotency.json +7 -0
  14. package/contracts/vectors/persistent-task.valid.json +45 -0
  15. package/dist/a2a/client/url-policy.js +52 -14
  16. package/dist/a2a/client/url-policy.js.map +1 -1
  17. package/dist/a2a/node.js +27 -1
  18. package/dist/a2a/node.js.map +1 -1
  19. package/dist/a2a/server/merchant-handler.d.ts +27 -0
  20. package/dist/a2a/server/merchant-handler.js +88 -10
  21. package/dist/a2a/server/merchant-handler.js.map +1 -1
  22. package/dist/a2a/signing-key.js +18 -0
  23. package/dist/a2a/signing-key.js.map +1 -1
  24. package/dist/buyer-core/a2a-knp.d.ts +71 -0
  25. package/dist/buyer-core/a2a-knp.js +139 -0
  26. package/dist/buyer-core/a2a-knp.js.map +1 -0
  27. package/dist/buyer-core/a2a-negotiator.d.ts +37 -0
  28. package/dist/buyer-core/a2a-negotiator.js +152 -0
  29. package/dist/buyer-core/a2a-negotiator.js.map +1 -0
  30. package/dist/buyer-core/a2a-quote-fetcher.d.ts +44 -0
  31. package/dist/buyer-core/a2a-quote-fetcher.js +178 -0
  32. package/dist/buyer-core/a2a-quote-fetcher.js.map +1 -0
  33. package/dist/buyer-core/build-service.d.ts +44 -0
  34. package/dist/buyer-core/build-service.js +76 -0
  35. package/dist/buyer-core/build-service.js.map +1 -0
  36. package/dist/buyer-core/errors.d.ts +31 -0
  37. package/dist/buyer-core/errors.js +52 -0
  38. package/dist/buyer-core/errors.js.map +1 -0
  39. package/dist/buyer-core/merchant-index.d.ts +64 -0
  40. package/dist/buyer-core/merchant-index.js +213 -0
  41. package/dist/buyer-core/merchant-index.js.map +1 -0
  42. package/dist/buyer-core/negotiator.d.ts +51 -0
  43. package/dist/buyer-core/negotiator.js +181 -0
  44. package/dist/buyer-core/negotiator.js.map +1 -0
  45. package/dist/buyer-core/quote-fetcher.d.ts +46 -0
  46. package/dist/buyer-core/quote-fetcher.js +166 -0
  47. package/dist/buyer-core/quote-fetcher.js.map +1 -0
  48. package/dist/buyer-core/service.d.ts +218 -0
  49. package/dist/buyer-core/service.js +558 -0
  50. package/dist/buyer-core/service.js.map +1 -0
  51. package/dist/buyer-core/store.d.ts +84 -0
  52. package/dist/buyer-core/store.js +256 -0
  53. package/dist/buyer-core/store.js.map +1 -0
  54. package/dist/cli.js +25 -0
  55. package/dist/cli.js.map +1 -1
  56. package/dist/config/profile.d.ts +9 -0
  57. package/dist/config/profile.js +23 -0
  58. package/dist/config/profile.js.map +1 -1
  59. package/dist/contracts/northbound-schema.d.ts +27 -0
  60. package/dist/contracts/northbound-schema.js +102 -0
  61. package/dist/contracts/northbound-schema.js.map +1 -0
  62. package/dist/handoff/destination.js +16 -5
  63. package/dist/handoff/destination.js.map +1 -1
  64. package/dist/http/cli.d.ts +16 -0
  65. package/dist/http/cli.js +123 -0
  66. package/dist/http/cli.js.map +1 -0
  67. package/dist/http/server.d.ts +39 -0
  68. package/dist/http/server.js +297 -0
  69. package/dist/http/server.js.map +1 -0
  70. package/dist/mcp/cli.d.ts +70 -0
  71. package/dist/mcp/cli.js +147 -0
  72. package/dist/mcp/cli.js.map +1 -0
  73. package/dist/mcp/server.d.ts +41 -0
  74. package/dist/mcp/server.js +141 -0
  75. package/dist/mcp/server.js.map +1 -0
  76. package/dist/mcp/tools.d.ts +28 -0
  77. package/dist/mcp/tools.js +299 -0
  78. package/dist/mcp/tools.js.map +1 -0
  79. package/dist/mcp/types.d.ts +107 -0
  80. package/dist/mcp/types.js +52 -0
  81. package/dist/mcp/types.js.map +1 -0
  82. package/dist/merchant/decision-backend.d.ts +82 -0
  83. package/dist/merchant/decision-backend.js +275 -0
  84. package/dist/merchant/decision-backend.js.map +1 -0
  85. package/dist/merchant/ops.d.ts +80 -0
  86. package/dist/merchant/ops.js +75 -0
  87. package/dist/merchant/ops.js.map +1 -0
  88. package/dist/merchant/ucp-profile.d.ts +39 -0
  89. package/dist/merchant/ucp-profile.js +55 -0
  90. package/dist/merchant/ucp-profile.js.map +1 -0
  91. package/dist/product-cli.d.ts +1 -1
  92. package/dist/product-cli.js +1 -1
  93. package/dist/product-cli.js.map +1 -1
  94. package/dist/trust/identity/auth-verifier.js +19 -1
  95. package/dist/trust/identity/auth-verifier.js.map +1 -1
  96. package/dist/trust/identity/message-signature.js +14 -8
  97. package/dist/trust/identity/message-signature.js.map +1 -1
  98. package/examples/profiles/merchant.deepseek.yaml +5 -0
  99. package/examples/profiles/merchant.fake.yaml +4 -0
  100. package/package.json +4 -2
@@ -0,0 +1,124 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kiwi.harrylabsj.com/schemas/commerce-intent/1.0/schema.json",
4
+ "title": "Kiwi CommerceIntent v0.1",
5
+ "description": "统一所有宿主 Agent 的 Sourcing 委托(战略 v2.5 §5.2)。CommerceIntent 是 Northbound 稳定契约,表达 sourcing intent 而非 UCP transaction payload。宿主(Hermes/Kimi/Codex/OpenClaw/企业 Agent)把自然语言需求映射为同一结构;Kiwi 再把商品检索/交易部分转换为 UCP 调用,把询报价与磋商部分转换为 KNP 流程。context_projection 承载最小商业披露(§5.4):只投影完成当前交易必需的字段;Principal Memory、原始对话历史与宿主私有工具不得默认进入远程上下文。",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "intent_id",
10
+ "intent_type",
11
+ "items"
12
+ ],
13
+ "properties": {
14
+ "intent_id": {
15
+ "$ref": "#/$defs/identifier"
16
+ },
17
+ "intent_type": {
18
+ "type": "string",
19
+ "enum": ["purchase", "procurement", "inquiry"]
20
+ },
21
+ "items": {
22
+ "type": "array",
23
+ "minItems": 1,
24
+ "items": { "$ref": "#/$defs/intent_item" }
25
+ },
26
+ "constraints": {
27
+ "$ref": "#/$defs/constraints"
28
+ },
29
+ "preferences": {
30
+ "$ref": "#/$defs/preferences"
31
+ },
32
+ "context_projection": {
33
+ "$ref": "#/$defs/context_projection"
34
+ }
35
+ },
36
+ "$defs": {
37
+ "identifier": {
38
+ "description": "对端 opaque 标识符(同 KNP/1.0 §6):非空、≤256、无首尾空白、无控制字符。",
39
+ "type": "string",
40
+ "minLength": 1,
41
+ "maxLength": 256,
42
+ "pattern": "^\\S(.*\\S)?$"
43
+ },
44
+ "timestamp": {
45
+ "description": "RFC 3339 时间戳(同 KNP/1.0 §7.3)。",
46
+ "type": "string",
47
+ "format": "date-time"
48
+ },
49
+ "currency": {
50
+ "type": "string",
51
+ "pattern": "^[A-Z]{3}$"
52
+ },
53
+ "money": {
54
+ "description": "金额用最小单位整数(同 KNP/1.0 §7.1)。",
55
+ "type": "object",
56
+ "additionalProperties": true,
57
+ "required": ["currency", "amount_minor"],
58
+ "properties": {
59
+ "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
60
+ "amount_minor": { "type": "integer", "minimum": 0 }
61
+ }
62
+ },
63
+ "quantity": {
64
+ "description": "数量(同 KNP/1.0 §7.2):value 为正数。",
65
+ "type": "object",
66
+ "additionalProperties": true,
67
+ "required": ["value", "unit"],
68
+ "properties": {
69
+ "value": { "type": "number", "exclusiveMinimum": 0 },
70
+ "unit": { "type": "string", "minLength": 1 }
71
+ }
72
+ },
73
+ "intent_item": {
74
+ "description": "单个采购条目:query / sku / attributes 至少其一表达商品语义,quantity 可选。",
75
+ "type": "object",
76
+ "additionalProperties": true,
77
+ "required": ["query"],
78
+ "properties": {
79
+ "query": { "type": "string", "minLength": 1 },
80
+ "sku": { "type": "string", "minLength": 1 },
81
+ "attributes": { "type": "object" },
82
+ "quantity": { "$ref": "#/$defs/quantity" }
83
+ }
84
+ },
85
+ "constraints": {
86
+ "description": "硬约束:预算/目标单价/币种/交付地点/期限/强制要求。",
87
+ "type": "object",
88
+ "additionalProperties": true,
89
+ "properties": {
90
+ "budget": { "$ref": "#/$defs/money" },
91
+ "target_unit_price": { "$ref": "#/$defs/money" },
92
+ "currency": { "$ref": "#/$defs/currency" },
93
+ "delivery_location": { "type": "string", "minLength": 1 },
94
+ "deadline": { "$ref": "#/$defs/timestamp" },
95
+ "mandatory_requirements": {
96
+ "type": "array",
97
+ "items": { "type": "string", "minLength": 1 }
98
+ }
99
+ }
100
+ },
101
+ "preferences": {
102
+ "description": "偏好:品牌/质量/服务优先级,不构成硬约束。",
103
+ "type": "object",
104
+ "additionalProperties": true,
105
+ "properties": {
106
+ "brands": { "type": "array", "items": { "type": "string", "minLength": 1 } },
107
+ "quality": { "type": "string", "minLength": 1 },
108
+ "service_priorities": { "type": "array", "items": { "type": "string", "minLength": 1 } }
109
+ }
110
+ },
111
+ "context_projection": {
112
+ "description": "最小商业披露(§5.4):宿主只把完成当前交易必需的字段投影给远程 Merchant。Principal Memory、原始对话历史和宿主私有工具不得默认进入远程上下文。disclosure_boundary 固定为 commerce_required。",
113
+ "type": "object",
114
+ "additionalProperties": true,
115
+ "properties": {
116
+ "disclosure_boundary": { "const": "commerce_required" },
117
+ "projected_fields": {
118
+ "type": "array",
119
+ "items": { "type": "string", "minLength": 1 }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,143 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kiwi.harrylabsj.com/schemas/delegation-policy/1.0/schema.json",
4
+ "title": "Kiwi DelegationPolicy v0.1",
5
+ "description": "Principal 对每一类商业动作的委托边界(战略 v2.5 §5.3)。商业 Agent 的真正风险不在『能不能调用工具』,而在『被授权做到哪一步』。每个动作映射为 AUTO / ASK / NEVER 之一,并支持价格、数量、时间、商家范围等硬限制。默认映射(§5.3):discover=auto,inquiry_rfq=auto,compare_offers=auto,counter_offer=auto/受限,accept_nonbinding=ask,handoff=ask,payment=never。payment 恒为 never(KNP 不进入支付/资金托管,属硬不变量)。Host 许可只是 EffectiveAuthorization 的一层(§5.5),不得通过宿主 UI 提升本策略。",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "policy_id",
10
+ "version",
11
+ "principal",
12
+ "actions",
13
+ "expires_at"
14
+ ],
15
+ "properties": {
16
+ "policy_id": {
17
+ "$ref": "#/$defs/identifier"
18
+ },
19
+ "version": {
20
+ "type": "string",
21
+ "const": "1.0"
22
+ },
23
+ "principal": {
24
+ "description": "授权主体(human/company)opaque 标识,对 Merchant 只投影为可验证 Buyer Session,不泄露完整宿主身份(§8.1)。",
25
+ "type": "string",
26
+ "minLength": 1
27
+ },
28
+ "created_at": {
29
+ "$ref": "#/$defs/timestamp"
30
+ },
31
+ "expires_at": {
32
+ "description": "委托有效期:过期后 Enter 可解释状态,可重新生成,不留幽灵 pending。",
33
+ "$ref": "#/$defs/timestamp"
34
+ },
35
+ "actions": {
36
+ "type": "object",
37
+ "additionalProperties": false,
38
+ "required": [
39
+ "discover",
40
+ "inquiry_rfq",
41
+ "compare_offers",
42
+ "counter_offer",
43
+ "accept_nonbinding",
44
+ "handoff",
45
+ "payment"
46
+ ],
47
+ "properties": {
48
+ "discover": { "$ref": "#/$defs/action_policy" },
49
+ "inquiry_rfq": { "$ref": "#/$defs/action_policy" },
50
+ "compare_offers": { "$ref": "#/$defs/action_policy" },
51
+ "counter_offer": { "$ref": "#/$defs/action_policy" },
52
+ "accept_nonbinding": { "$ref": "#/$defs/action_policy" },
53
+ "handoff": { "$ref": "#/$defs/action_policy" },
54
+ "payment": { "$ref": "#/$defs/payment_policy" }
55
+ }
56
+ },
57
+ "limits": {
58
+ "$ref": "#/$defs/limits"
59
+ }
60
+ },
61
+ "$defs": {
62
+ "identifier": {
63
+ "description": "对端 opaque 标识符(同 KNP/1.0 §6):非空、≤256、无首尾空白、无控制字符。",
64
+ "type": "string",
65
+ "minLength": 1,
66
+ "maxLength": 256,
67
+ "pattern": "^\\S(.*\\S)?$"
68
+ },
69
+ "timestamp": {
70
+ "description": "RFC 3339 时间戳(同 KNP/1.0 §7.3)。",
71
+ "type": "string",
72
+ "format": "date-time"
73
+ },
74
+ "currency": {
75
+ "type": "string",
76
+ "pattern": "^[A-Z]{3}$"
77
+ },
78
+ "money": {
79
+ "description": "金额用最小单位整数(同 KNP/1.0 §7.1)。",
80
+ "type": "object",
81
+ "additionalProperties": true,
82
+ "required": ["currency", "amount_minor"],
83
+ "properties": {
84
+ "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
85
+ "amount_minor": { "type": "integer", "minimum": 0 }
86
+ }
87
+ },
88
+ "quantity": {
89
+ "description": "数量(同 KNP/1.0 §7.2):value 为正数。",
90
+ "type": "object",
91
+ "additionalProperties": true,
92
+ "required": ["value", "unit"],
93
+ "properties": {
94
+ "value": { "type": "number", "exclusiveMinimum": 0 },
95
+ "unit": { "type": "string", "minLength": 1 }
96
+ }
97
+ },
98
+ "mode": {
99
+ "type": "string",
100
+ "enum": ["auto", "ask", "never"]
101
+ },
102
+ "action_policy": {
103
+ "description": "单类商业动作的委托模式 + 可选说明。",
104
+ "type": "object",
105
+ "additionalProperties": false,
106
+ "required": ["mode"],
107
+ "properties": {
108
+ "mode": { "$ref": "#/$defs/mode" },
109
+ "note": { "type": "string", "maxLength": 1024 }
110
+ }
111
+ },
112
+ "payment_policy": {
113
+ "description": "支付/资金托管(§10 产品边界):KNP 不进入支付与资金托管,恒为 never。",
114
+ "type": "object",
115
+ "additionalProperties": false,
116
+ "required": ["mode"],
117
+ "properties": {
118
+ "mode": { "const": "never" },
119
+ "note": { "type": "string", "maxLength": 1024 }
120
+ }
121
+ },
122
+ "limits": {
123
+ "description": "AUTO/ASK 的硬边界:金额、数量、商家范围、币种、轮次、期限。",
124
+ "type": "object",
125
+ "additionalProperties": true,
126
+ "properties": {
127
+ "max_total_price": { "$ref": "#/$defs/money" },
128
+ "max_unit_price": { "$ref": "#/$defs/money" },
129
+ "max_quantity": { "$ref": "#/$defs/quantity" },
130
+ "max_rounds": { "type": "integer", "minimum": 0 },
131
+ "allowed_merchants": {
132
+ "type": "array",
133
+ "items": { "type": "string", "minLength": 1 }
134
+ },
135
+ "allowed_currencies": {
136
+ "type": "array",
137
+ "items": { "$ref": "#/$defs/currency" }
138
+ },
139
+ "deadline": { "$ref": "#/$defs/timestamp" }
140
+ }
141
+ }
142
+ }
143
+ }
@@ -0,0 +1,167 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kiwi.harrylabsj.com/schemas/effective-authorization/1.0/schema.json",
4
+ "title": "Kiwi EffectiveAuthorization v0.1",
5
+ "description": "EffectiveAuthorization = PackageTrust ∩ HostToolPolicy ∩ RuntimeApproval ∩ KiwiDelegationPolicy ∩ MerchantHardPolicy(战略 v2.5 §5.5)。五个相互独立边界的交集;任意一层拒绝即拒绝(deny 优先);任何宿主 UI 的『允许』都不能提升 Kiwi/Merchant 的硬策略。AcceptNonbinding、handoff 以及超出默认披露范围的信息必须写入持久 approval_id;重启后仍可验证授权主体、范围、版本、过期时间与被批准 candidate digest。本 schema 把『granted ⇔ 五层全部 allowed』与『任一层 denied ⇒ denied』编码为可机检不变量。",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "authorization_id",
10
+ "action",
11
+ "subject",
12
+ "layers",
13
+ "effective_decision",
14
+ "decided_at"
15
+ ],
16
+ "properties": {
17
+ "authorization_id": {
18
+ "$ref": "#/$defs/identifier"
19
+ },
20
+ "task_id": {
21
+ "$ref": "#/$defs/identifier"
22
+ },
23
+ "candidate_id": {
24
+ "$ref": "#/$defs/identifier"
25
+ },
26
+ "action": {
27
+ "type": "string",
28
+ "enum": [
29
+ "discover",
30
+ "inquiry_rfq",
31
+ "compare_offers",
32
+ "counter_offer",
33
+ "accept_nonbinding",
34
+ "handoff",
35
+ "payment"
36
+ ]
37
+ },
38
+ "subject": {
39
+ "description": "授权主体:Merchant 只需要知道这是哪个可验证 Buyer Session、由什么 Principal/组织授权、授权范围、何时过期(§8.1)。",
40
+ "type": "object",
41
+ "additionalProperties": false,
42
+ "required": ["buyer_agent_id", "session_id", "delegation_id", "expires_at"],
43
+ "properties": {
44
+ "buyer_agent_id": { "$ref": "#/$defs/identifier" },
45
+ "session_id": { "$ref": "#/$defs/identifier" },
46
+ "delegation_id": { "$ref": "#/$defs/identifier" },
47
+ "expires_at": { "$ref": "#/$defs/timestamp" }
48
+ }
49
+ },
50
+ "layers": {
51
+ "type": "object",
52
+ "additionalProperties": false,
53
+ "required": [
54
+ "package_trust",
55
+ "host_tool_policy",
56
+ "runtime_approval",
57
+ "kiwi_delegation_policy",
58
+ "merchant_hard_policy"
59
+ ],
60
+ "properties": {
61
+ "package_trust": {
62
+ "description": "插件/包是否来自可信来源、签名与版本是否允许(§6.11)。不可信包不得获得商业写能力。",
63
+ "$ref": "#/$defs/layer_decision"
64
+ },
65
+ "host_tool_policy": {
66
+ "description": "宿主 Agent 是否允许调用该工具/暴露相关字段。宿主只可收紧,不可放宽下游策略。",
67
+ "$ref": "#/$defs/layer_decision"
68
+ },
69
+ "runtime_approval": {
70
+ "description": "当前 task/candidate 的持久审批记录。AcceptNonbinding、handoff、敏感 disclosure 必须可审计。",
71
+ "$ref": "#/$defs/layer_decision"
72
+ },
73
+ "kiwi_delegation_policy": {
74
+ "description": "Principal 对金额、数量、商家、轮次、期限的委托边界(AUTO/ASK/NEVER + 硬约束)。",
75
+ "$ref": "#/$defs/layer_decision"
76
+ },
77
+ "merchant_hard_policy": {
78
+ "description": "商家底价、MOQ、区域、客户等级、合规与人工审核。Merchant 最终商业硬边界。",
79
+ "$ref": "#/$defs/layer_decision"
80
+ }
81
+ }
82
+ },
83
+ "effective_decision": {
84
+ "type": "string",
85
+ "enum": ["granted", "denied"]
86
+ },
87
+ "approval_id": {
88
+ "description": "AcceptNonbinding / handoff / 敏感 disclosure 必须绑定持久 approval_id。",
89
+ "$ref": "#/$defs/identifier"
90
+ },
91
+ "expires_at": {
92
+ "$ref": "#/$defs/timestamp"
93
+ },
94
+ "decided_at": {
95
+ "$ref": "#/$defs/timestamp"
96
+ }
97
+ },
98
+ "allOf": [
99
+ {
100
+ "description": "deny 优先:任一独立层 denied ⇒ effective_decision 必须为 denied。",
101
+ "if": {
102
+ "anyOf": [
103
+ { "type": "object", "properties": { "layers": { "type": "object", "properties": { "package_trust": { "type": "object", "properties": { "status": { "const": "denied" } } } } } } },
104
+ { "type": "object", "properties": { "layers": { "type": "object", "properties": { "host_tool_policy": { "type": "object", "properties": { "status": { "const": "denied" } } } } } } },
105
+ { "type": "object", "properties": { "layers": { "type": "object", "properties": { "runtime_approval": { "type": "object", "properties": { "status": { "const": "denied" } } } } } } },
106
+ { "type": "object", "properties": { "layers": { "type": "object", "properties": { "kiwi_delegation_policy": { "type": "object", "properties": { "status": { "const": "denied" } } } } } } },
107
+ { "type": "object", "properties": { "layers": { "type": "object", "properties": { "merchant_hard_policy": { "type": "object", "properties": { "status": { "const": "denied" } } } } } } }
108
+ ]
109
+ },
110
+ "then": {
111
+ "type": "object",
112
+ "properties": {
113
+ "effective_decision": { "const": "denied" }
114
+ }
115
+ }
116
+ },
117
+ {
118
+ "description": "granted ⇒ 五层必须全部 allowed(交集语义;不是『多数层允许』)。",
119
+ "if": {
120
+ "type": "object",
121
+ "properties": { "effective_decision": { "const": "granted" } }
122
+ },
123
+ "then": {
124
+ "type": "object",
125
+ "properties": {
126
+ "layers": {
127
+ "type": "object",
128
+ "properties": {
129
+ "package_trust": { "type": "object", "properties": { "status": { "enum": ["allowed"] } } },
130
+ "host_tool_policy": { "type": "object", "properties": { "status": { "enum": ["allowed"] } } },
131
+ "runtime_approval": { "type": "object", "properties": { "status": { "enum": ["allowed"] } } },
132
+ "kiwi_delegation_policy": { "type": "object", "properties": { "status": { "enum": ["allowed"] } } },
133
+ "merchant_hard_policy": { "type": "object", "properties": { "status": { "enum": ["allowed"] } } }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ ],
140
+ "$defs": {
141
+ "identifier": {
142
+ "description": "对端 opaque 标识符(同 KNP/1.0 §6):非空、≤256、无首尾空白、无控制字符。",
143
+ "type": "string",
144
+ "minLength": 1,
145
+ "maxLength": 256,
146
+ "pattern": "^\\S(.*\\S)?$"
147
+ },
148
+ "timestamp": {
149
+ "description": "RFC 3339 时间戳(同 KNP/1.0 §7.3)。",
150
+ "type": "string",
151
+ "format": "date-time"
152
+ },
153
+ "layer_decision": {
154
+ "description": "单层授权判定:allowed / denied。本 schema 不含 not_applicable——交集语义要求五层全部 allowed 才 granted。",
155
+ "type": "object",
156
+ "additionalProperties": false,
157
+ "required": ["status"],
158
+ "properties": {
159
+ "status": {
160
+ "type": "string",
161
+ "enum": ["allowed", "denied"]
162
+ },
163
+ "reason": { "type": "string", "maxLength": 1024 }
164
+ }
165
+ }
166
+ }
167
+ }
@@ -2,6 +2,6 @@
2
2
  "lock_version": 1,
3
3
  "source_repository": "harrylabsj/kiwi",
4
4
  "source_commit": "009bc25cdae2668c8fd19ccedcc4e0c64a34f6be",
5
- "bundle_sha256": "2dbbc52a1113dc5c05dc544802571ee188b44e1567d6bfb0cd8ccd87ea7f4998",
5
+ "bundle_sha256": "2350ecaacebb791cd980cc2886511359e356378a6f18cdecc1ac6331c31b0e70",
6
6
  "contracts_manifest": "contracts/manifest.json"
7
7
  }
@@ -1,8 +1,32 @@
1
1
  {
2
2
  "manifest_version": 1,
3
3
  "authority": "kiwi/contracts",
4
- "bundle_sha256": "2dbbc52a1113dc5c05dc544802571ee188b44e1567d6bfb0cd8ccd87ea7f4998",
4
+ "bundle_sha256": "2350ecaacebb791cd980cc2886511359e356378a6f18cdecc1ac6331c31b0e70",
5
5
  "contracts": [
6
+ {
7
+ "id": "commerce-intent",
8
+ "version": "1.0",
9
+ "path": "contracts/commerce-intent/1.0/schema.json",
10
+ "sha256": "58e24c3d41dab8d582c7e74b540546ccad601b0e219ea1f988eca21c9107a7fb"
11
+ },
12
+ {
13
+ "id": "delegation-policy",
14
+ "version": "1.0",
15
+ "path": "contracts/delegation-policy/1.0/schema.json",
16
+ "sha256": "62a146055a68f9a1014c99ed58d6ba02160e17441f9577de0fd134023c038341"
17
+ },
18
+ {
19
+ "id": "effective-authorization",
20
+ "version": "1.0",
21
+ "path": "contracts/effective-authorization/1.0/schema.json",
22
+ "sha256": "7a04d97de2c5b2777766ee260ca8a8a2bce5024e2bff817a64ad6ff327856aa1"
23
+ },
24
+ {
25
+ "id": "persistent-task",
26
+ "version": "1.0",
27
+ "path": "contracts/persistent-task/1.0/schema.json",
28
+ "sha256": "f01c7df2dd439350daddbc272985bf4caa3db50b9c741cd1454799fdad1afdcc"
29
+ },
6
30
  {
7
31
  "id": "candidate-agent-dto",
8
32
  "version": "1.0",
@@ -0,0 +1,191 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://kiwi.harrylabsj.com/schemas/persistent-task/1.0/schema.json",
4
+ "title": "Kiwi Persistent Task / Approval v0.1",
5
+ "description": "跨进程、跨审批、跨 Merchant 操作必须落到持久任务模型(战略 v2.5 §6.2)。『只有 5—7 个高层工具』不能替代任务生命周期设计:插件和 MCP 连接断开后,Kiwi 仍能解释任务现在在哪里、为什么停住、是否可重试、是否已失效。稳定标识 task_id / candidate_id / approval_id / agreement_id 重启后仍可解析,不得依赖进程内对象或宿主 session 作为权威标识。所有写操作显式携带 idempotency_key;定义 retry、timeout、cancel、resume 与 crash recovery。Offer/candidate/approval/delegation 均有 expires_at,过期后进入可解释状态,可重新生成,不留幽灵 pending。多 Merchant fan-out 允许部分成功(status=partial_success),每个结果保留 provenance、失败分类与 retryability。Buyer Core 持久存储是 task/pending/approval 的唯一权威;Plugin、MCP App、Host UI 只投影状态,不保存第二套状态机。",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": [
9
+ "task_id",
10
+ "task_kind",
11
+ "status",
12
+ "idempotency_key",
13
+ "created_at",
14
+ "updated_at"
15
+ ],
16
+ "properties": {
17
+ "task_id": {
18
+ "$ref": "#/$defs/identifier"
19
+ },
20
+ "task_kind": {
21
+ "type": "string",
22
+ "enum": ["search", "request_quotes", "negotiate", "accept_agreement", "handoff"]
23
+ },
24
+ "status": {
25
+ "type": "string",
26
+ "enum": [
27
+ "pending",
28
+ "in_progress",
29
+ "awaiting_approval",
30
+ "partial_success",
31
+ "succeeded",
32
+ "failed",
33
+ "expired",
34
+ "cancelled"
35
+ ]
36
+ },
37
+ "idempotency_key": {
38
+ "description": "写操作幂等键:相同 key 的重复提交返回原任务结果,不产生重复写入。",
39
+ "$ref": "#/$defs/identifier"
40
+ },
41
+ "intent_id": {
42
+ "$ref": "#/$defs/identifier"
43
+ },
44
+ "delegation_policy_id": {
45
+ "$ref": "#/$defs/identifier"
46
+ },
47
+ "created_at": {
48
+ "$ref": "#/$defs/timestamp"
49
+ },
50
+ "updated_at": {
51
+ "$ref": "#/$defs/timestamp"
52
+ },
53
+ "expires_at": {
54
+ "description": "任务整体过期时间;过期后进入 expired 可解释状态。",
55
+ "$ref": "#/$defs/timestamp"
56
+ },
57
+ "resumable": {
58
+ "description": "crash 后是否可从持久 checkpoint 恢复。",
59
+ "type": "boolean"
60
+ },
61
+ "resumed_from_task_id": {
62
+ "$ref": "#/$defs/identifier"
63
+ },
64
+ "candidates": {
65
+ "description": "多 Merchant fan-out 的每个子结果;允许部分失败。",
66
+ "type": "array",
67
+ "items": { "$ref": "#/$defs/candidate_record" }
68
+ },
69
+ "intent": {
70
+ "description": "本任务操作的 CommerceIntent(§5.2);由 intent_id 关联,随任务记录持久化。",
71
+ "type": "object",
72
+ "additionalProperties": true
73
+ },
74
+ "steps": {
75
+ "description": "磋商步骤记录(counter_offer / clarification),受 DelegationPolicy 轮次限制。",
76
+ "type": "array",
77
+ "items": {
78
+ "type": "object",
79
+ "additionalProperties": true,
80
+ "required": ["round", "action"],
81
+ "properties": {
82
+ "round": { "type": "integer", "minimum": 1 },
83
+ "action": { "type": "string", "enum": ["counter_offer", "clarification"] },
84
+ "summary": { "type": "string" }
85
+ }
86
+ }
87
+ },
88
+ "approval": {
89
+ "$ref": "#/$defs/approval_record"
90
+ },
91
+ "agreement_id": {
92
+ "$ref": "#/$defs/identifier"
93
+ },
94
+ "handoff_ref": {
95
+ "$ref": "#/$defs/handoff_ref"
96
+ }
97
+ },
98
+ "$defs": {
99
+ "identifier": {
100
+ "description": "对端 opaque 标识符(同 KNP/1.0 §6):非空、≤256、无首尾空白、无控制字符。",
101
+ "type": "string",
102
+ "minLength": 1,
103
+ "maxLength": 256,
104
+ "pattern": "^\\S(.*\\S)?$"
105
+ },
106
+ "timestamp": {
107
+ "description": "RFC 3339 时间戳(同 KNP/1.0 §7.3)。",
108
+ "type": "string",
109
+ "format": "date-time"
110
+ },
111
+ "digest": {
112
+ "description": "内容摘要(同 KNP/1.0 §19):sha256:<64 位小写十六进制>。",
113
+ "type": "string",
114
+ "pattern": "^sha256:[0-9a-f]{64}$"
115
+ },
116
+ "candidate_record": {
117
+ "description": "单个 Merchant 的 fan-out 子任务结果。",
118
+ "type": "object",
119
+ "additionalProperties": false,
120
+ "required": ["candidate_id", "merchant_id", "status"],
121
+ "properties": {
122
+ "candidate_id": { "$ref": "#/$defs/identifier" },
123
+ "merchant_id": { "type": "string", "minLength": 1 },
124
+ "status": {
125
+ "type": "string",
126
+ "enum": ["pending", "succeeded", "failed", "expired", "pending_approval"]
127
+ },
128
+ "provenance": { "$ref": "#/$defs/provenance" },
129
+ "failure": { "$ref": "#/$defs/failure" },
130
+ "expires_at": { "$ref": "#/$defs/timestamp" },
131
+ "retryable": { "type": "boolean" }
132
+ }
133
+ },
134
+ "provenance": {
135
+ "description": "结果来源:Merchant 外部回复/协商标识,用于 Verified Agreement 审计(§12)。",
136
+ "type": "object",
137
+ "additionalProperties": true,
138
+ "properties": {
139
+ "merchant_reply_id": { "type": "string", "minLength": 1 },
140
+ "negotiation_id": { "$ref": "#/$defs/identifier" },
141
+ "offer_id": { "$ref": "#/$defs/identifier" },
142
+ "source": { "type": "string", "minLength": 1 }
143
+ }
144
+ },
145
+ "failure": {
146
+ "type": "object",
147
+ "additionalProperties": false,
148
+ "required": ["classification"],
149
+ "properties": {
150
+ "classification": {
151
+ "type": "string",
152
+ "enum": ["timeout", "rejected", "unreachable", "protocol_error", "expired", "other"]
153
+ },
154
+ "retryable": { "type": "boolean" },
155
+ "detail": { "type": "string", "maxLength": 4096 }
156
+ }
157
+ },
158
+ "approval_record": {
159
+ "description": "持久审批记录:AcceptNonbinding / handoff / 敏感 disclosure 必须写入持久 approval_id,重启后仍可验证授权主体、范围、版本、过期时间与被批准的 candidate digest。",
160
+ "type": "object",
161
+ "additionalProperties": false,
162
+ "required": ["approval_id", "action", "status"],
163
+ "properties": {
164
+ "approval_id": { "$ref": "#/$defs/identifier" },
165
+ "action": {
166
+ "type": "string",
167
+ "enum": ["accept_nonbinding", "handoff", "sensitive_disclosure"]
168
+ },
169
+ "status": {
170
+ "type": "string",
171
+ "enum": ["pending", "approved", "denied", "expired"]
172
+ },
173
+ "candidate_digest": { "$ref": "#/$defs/digest" },
174
+ "approved_authorization_id": { "$ref": "#/$defs/identifier" },
175
+ "expires_at": { "$ref": "#/$defs/timestamp" },
176
+ "decided_at": { "$ref": "#/$defs/timestamp" }
177
+ }
178
+ },
179
+ "handoff_ref": {
180
+ "description": "Agreement → UCP Checkout / merchant transaction endpoint 的 handoff 引用(§5.3/KTH)。",
181
+ "type": "object",
182
+ "additionalProperties": false,
183
+ "required": ["handoff_id", "destination_type"],
184
+ "properties": {
185
+ "handoff_id": { "$ref": "#/$defs/identifier" },
186
+ "destination_type": { "type": "string", "minLength": 1 },
187
+ "url": { "type": "string" }
188
+ }
189
+ }
190
+ }
191
+ }