@zq-silk/yui 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.
Files changed (138) hide show
  1. package/README.md +4 -0
  2. package/dist/cli/commandCatalog.js +318 -289
  3. package/dist/cli/commandDiscovery.js +72 -0
  4. package/dist/cli/completion.js +22 -227
  5. package/dist/cli/dynamicCompletion.js +12 -6
  6. package/dist/cli/invocationAuthority.js +2 -2
  7. package/dist/cli/invocationRouter.js +18 -7
  8. package/dist/cli.js +23 -3030
  9. package/dist/commands/capabilityCommands.js +5 -5
  10. package/dist/commands/globalRoleCommands.js +2 -1
  11. package/dist/commands/taskCommands.js +90 -21
  12. package/dist/commands/taskIntegrationCommands.js +3 -1
  13. package/dist/commands/taskUpstreamCommands.js +3 -1
  14. package/dist/context/runContextPack.js +132 -5
  15. package/dist/context/sourceRunContext.js +4 -2
  16. package/dist/context/taskContext.js +12 -3
  17. package/dist/controlPlaneCli.js +3092 -0
  18. package/dist/controller/fileSchedulerStoreAdapter.js +19 -6
  19. package/dist/controller/jobControl.js +21 -0
  20. package/dist/executor/agentExecutor.js +1 -1
  21. package/dist/executor/effectiveLaunch.js +18 -5
  22. package/dist/executor/fileRoleLaunchPlanner.js +15 -19
  23. package/dist/integration/gitIntegrationService.js +50 -15
  24. package/dist/kernel/accessAssessment.js +1 -0
  25. package/dist/kernel/builtinCapabilities.js +28 -1
  26. package/dist/kernel/capabilityRegistry.js +64 -19
  27. package/dist/message/messageContinuation.js +7 -2
  28. package/dist/nativeAgent/agent.js +275 -0
  29. package/dist/nativeAgent/cliDemo.js +37 -0
  30. package/dist/nativeAgent/codingTools.js +11 -0
  31. package/dist/nativeAgent/commandTool.js +215 -0
  32. package/dist/nativeAgent/compactionDemo.js +158 -0
  33. package/dist/nativeAgent/composition.js +71 -0
  34. package/dist/nativeAgent/context/budget.js +44 -0
  35. package/dist/nativeAgent/context/index.js +339 -0
  36. package/dist/nativeAgent/context/providerCompressor.js +103 -0
  37. package/dist/nativeAgent/contracts.js +1 -0
  38. package/dist/nativeAgent/demo.js +40 -0
  39. package/dist/nativeAgent/evaluation/cases.js +38 -0
  40. package/dist/nativeAgent/evaluation/checks.js +91 -0
  41. package/dist/nativeAgent/evaluation/demo.js +19 -0
  42. package/dist/nativeAgent/evaluation/files.js +54 -0
  43. package/dist/nativeAgent/evaluation/fixture.js +36 -0
  44. package/dist/nativeAgent/evaluation/index.js +239 -0
  45. package/dist/nativeAgent/executionOwner.js +209 -0
  46. package/dist/nativeAgent/filePatterns.js +170 -0
  47. package/dist/nativeAgent/fileToolsSupport.js +202 -0
  48. package/dist/nativeAgent/index.js +16 -0
  49. package/dist/nativeAgent/interaction/cli.js +358 -0
  50. package/dist/nativeAgent/interaction/contracts.js +1 -0
  51. package/dist/nativeAgent/interaction/index.js +3 -0
  52. package/dist/nativeAgent/interaction/memoryDemo.js +115 -0
  53. package/dist/nativeAgent/interaction/renderer.js +34 -0
  54. package/dist/nativeAgent/localSafety.js +258 -0
  55. package/dist/nativeAgent/mockProvider.js +43 -0
  56. package/dist/nativeAgent/model/anthropicMessages.js +204 -0
  57. package/dist/nativeAgent/model/chatCompletions.js +210 -0
  58. package/dist/nativeAgent/model/errors.js +47 -0
  59. package/dist/nativeAgent/model/gateway.js +423 -0
  60. package/dist/nativeAgent/model/index.js +7 -0
  61. package/dist/nativeAgent/model/observationAdapter.js +21 -0
  62. package/dist/nativeAgent/model/protocols.js +19 -0
  63. package/dist/nativeAgent/model/responses.js +263 -0
  64. package/dist/nativeAgent/model/types.js +1 -0
  65. package/dist/nativeAgent/model/wire.js +73 -0
  66. package/dist/nativeAgent/observability/index.js +220 -0
  67. package/dist/nativeAgent/product/catalog.js +82 -0
  68. package/dist/nativeAgent/product/config.js +295 -0
  69. package/dist/nativeAgent/product/facts.js +30 -0
  70. package/dist/nativeAgent/product/index.js +62 -0
  71. package/dist/nativeAgent/product/location.js +44 -0
  72. package/dist/nativeAgent/product/runtime.js +276 -0
  73. package/dist/nativeAgent/product/storage.js +49 -0
  74. package/dist/nativeAgent/product/tools.js +47 -0
  75. package/dist/nativeAgent/product/transport.js +54 -0
  76. package/dist/nativeAgent/projectGuidance/index.js +425 -0
  77. package/dist/nativeAgent/searchTools.js +305 -0
  78. package/dist/nativeAgent/session/backends.js +293 -0
  79. package/dist/nativeAgent/session/catalog.js +97 -0
  80. package/dist/nativeAgent/session/catalogDemo.js +87 -0
  81. package/dist/nativeAgent/session/contracts.js +1 -0
  82. package/dist/nativeAgent/session/format.js +269 -0
  83. package/dist/nativeAgent/session/index.js +5 -0
  84. package/dist/nativeAgent/session/location.js +36 -0
  85. package/dist/nativeAgent/session/sqliteFormat.js +134 -0
  86. package/dist/nativeAgent/session/store.js +248 -0
  87. package/dist/nativeAgent/textTools.js +293 -0
  88. package/dist/nativeAgent/toolManager/executor.js +290 -0
  89. package/dist/nativeAgent/toolManager/index.js +4 -0
  90. package/dist/nativeAgent/validation.js +95 -0
  91. package/dist/plugins/pluginService.js +98 -8
  92. package/dist/resources/projectResourceService.js +23 -1
  93. package/dist/runtime/managedIdentity.js +6 -0
  94. package/dist/surface/surfaceContributions.js +3 -0
  95. package/dist/task/taskAuthority.js +61 -10
  96. package/dist/web/assets/assetManifest.js +38 -22
  97. package/dist/web/assets/client/api.js +115 -0
  98. package/dist/web/assets/client/app.js +615 -862
  99. package/dist/web/assets/client/components.js +323 -897
  100. package/dist/web/assets/client/detail.js +333 -0
  101. package/dist/web/assets/client/dock.js +225 -0
  102. package/dist/web/assets/client/dom.js +55 -3
  103. package/dist/web/assets/client/evidence.js +172 -0
  104. package/dist/web/assets/client/format.js +25 -14
  105. package/dist/web/assets/client/forms.js +230 -0
  106. package/dist/web/assets/client/i18n.js +1024 -791
  107. package/dist/web/assets/client/overview.js +118 -0
  108. package/dist/web/assets/client/records.js +63 -0
  109. package/dist/web/assets/client/sections.js +313 -0
  110. package/dist/web/assets/client/sidebar.js +146 -0
  111. package/dist/web/assets/client/theme.js +61 -22
  112. package/dist/web/assets/icons.js +39 -0
  113. package/dist/web/assets/shell.js +125 -118
  114. package/dist/web/assets/styles/base.js +41 -0
  115. package/dist/web/assets/styles/components.js +169 -0
  116. package/dist/web/assets/styles/layout.js +56 -77
  117. package/dist/web/assets/styles/markdown.js +16 -24
  118. package/dist/web/assets/styles/responsive.js +41 -44
  119. package/dist/web/assets/styles/tokens.js +65 -89
  120. package/dist/web/assets/styles/views.js +292 -0
  121. package/dist/web/webServer.js +2 -1
  122. package/docs/agent-result-consumption.md +16 -0
  123. package/docs/agent-result-consumption.zh-CN.md +13 -0
  124. package/docs/examples/agent-offline.mjs +194 -0
  125. package/docs/native-agent.md +283 -0
  126. package/docs/release-workflow.md +61 -0
  127. package/docs/release-workflow.zh-CN.md +46 -0
  128. package/docs/roles-and-configuration.md +32 -0
  129. package/docs/roles-and-configuration.zh-CN.md +26 -0
  130. package/package.json +1 -1
  131. package/skills/yui-leader/SKILL.md +9 -0
  132. package/skills/yui-reviewer/SKILL.md +5 -0
  133. package/skills/yui-runtime/SKILL.md +33 -0
  134. package/dist/web/assets/client/taskSummary.js +0 -350
  135. package/dist/web/assets/client/taskSurface.js +0 -616
  136. package/dist/web/assets/client/view.js +0 -608
  137. package/dist/web/assets/styles/cards.js +0 -247
  138. package/dist/web/assets/styles/widgets.js +0 -168
@@ -0,0 +1,210 @@
1
+ import { ModelGatewayError, object, parse, protocol } from './errors.js';
2
+ import { sseFrames } from './wire.js';
3
+ const maxResponse = 512 * 1024;
4
+ const maxArguments = 64 * 1024;
5
+ function text(value) { if (typeof value !== 'string')
6
+ return protocol(); return value; }
7
+ function id(value) { const s = text(value); if (!s.trim())
8
+ return protocol(); return s; }
9
+ function json(value, depth = 0) {
10
+ if (depth > 32)
11
+ return false;
12
+ if (value === null || typeof value === 'string' || typeof value === 'boolean')
13
+ return true;
14
+ if (typeof value === 'number')
15
+ return Number.isFinite(value);
16
+ if (typeof value !== 'object')
17
+ return false;
18
+ return Object.values(value).every(v => json(v, depth + 1));
19
+ }
20
+ function usage(value) {
21
+ if (value === undefined || value === null)
22
+ return undefined;
23
+ const u = object(value);
24
+ const values = [u.prompt_tokens, u.completion_tokens, u.total_tokens];
25
+ if (!values.every(n => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0))
26
+ return protocol();
27
+ return { inputTokens: u.prompt_tokens, outputTokens: u.completion_tokens, totalTokens: u.total_tokens };
28
+ }
29
+ function finish(content, rawCalls, reason) {
30
+ if (reason !== 'stop' && reason !== 'tool_calls')
31
+ throw new ModelGatewayError('incomplete');
32
+ const list = rawCalls ?? [];
33
+ if (!Array.isArray(list) || list.length > 8 || (reason === 'stop') !== (list.length === 0))
34
+ return protocol();
35
+ const calls = list.map(raw => {
36
+ const c = object(raw), f = object(c.function);
37
+ if (c.type !== 'function')
38
+ return protocol();
39
+ const encoded = text(f.arguments);
40
+ if (Buffer.byteLength(encoded) > maxArguments)
41
+ return protocol();
42
+ const args = object(parse(encoded));
43
+ if (!json(args) || Buffer.byteLength(JSON.stringify(args)) > maxArguments)
44
+ return protocol();
45
+ return { id: id(c.id), name: id(f.name), arguments: args };
46
+ });
47
+ if (new Set(calls.map(c => c.id)).size !== calls.length)
48
+ return protocol();
49
+ const response = calls.length ? { kind: 'tool_calls', content, calls } : { kind: 'final', content };
50
+ if (Buffer.byteLength(JSON.stringify(response)) > maxResponse)
51
+ return protocol();
52
+ return response;
53
+ }
54
+ function messageFields(m) {
55
+ // Refusal/legacy calls and other modalities must not silently become an empty success.
56
+ if (m.refusal != null || m.function_call != null || m.audio != null)
57
+ return protocol();
58
+ if (m.role !== undefined && m.role !== 'assistant')
59
+ return protocol();
60
+ }
61
+ export function createChatCompletionsAdapter() {
62
+ return {
63
+ protocol: 'chat-completions',
64
+ encode(request, model, stream, options) {
65
+ return {
66
+ model, stream, store: false, n: 1,
67
+ ...(options?.maxOutputTokens !== undefined ? { max_completion_tokens: options.maxOutputTokens } : {}),
68
+ ...(stream ? { stream_options: { include_usage: true } } : {}),
69
+ messages: request.messages.map(m => {
70
+ if (m.role === 'tool')
71
+ return { role: 'tool', tool_call_id: m.toolCallId, content: JSON.stringify(m.outcome) };
72
+ if (m.role === 'assistant')
73
+ return {
74
+ role: m.role, content: m.content,
75
+ ...(m.toolCalls.length ? { tool_calls: m.toolCalls.map(c => ({
76
+ id: c.id, type: 'function', function: { name: c.name, arguments: JSON.stringify(c.arguments) },
77
+ })) } : {}),
78
+ };
79
+ return { role: m.role, content: m.content };
80
+ }),
81
+ ...(request.tools.length ? { tools: request.tools.map(t => ({
82
+ type: 'function', function: { name: t.name, description: t.description, parameters: t.inputSchema },
83
+ })) } : {}),
84
+ };
85
+ },
86
+ classify(status, body) {
87
+ if (status === 401 || status === 403)
88
+ return 'authentication';
89
+ const e = body && typeof body === 'object' ? body.error : undefined;
90
+ const fields = e && typeof e === 'object' ? e : {};
91
+ if (fields.code === 'insufficient_quota' || fields.type === 'insufficient_quota')
92
+ return 'quota';
93
+ if (['invalid_api_key', 'authentication_error', 'permission_error'].includes(String(fields.code))
94
+ || ['authentication_error', 'permission_error'].includes(String(fields.type)))
95
+ return 'authentication';
96
+ // Status alone is insufficient; never infer temporary from a free-form message.
97
+ return status === 429 && fields.code === 'rate_limit_exceeded'
98
+ && [undefined, null, 'rate_limit_error', 'tokens', 'requests'].includes(fields.type)
99
+ ? 'rate_limit' : 'http';
100
+ },
101
+ async decode(body, streaming, emit) {
102
+ if (!streaming) {
103
+ let source = '';
104
+ for await (const part of body)
105
+ source += part;
106
+ const root = object(parse(source));
107
+ if (root.error != null || !Array.isArray(root.choices) || root.choices.length !== 1)
108
+ return protocol();
109
+ const c = object(root.choices[0]), m = object(c.message);
110
+ if (c.index !== 0 || m.role !== 'assistant')
111
+ return protocol();
112
+ messageFields(m);
113
+ const response = finish(m.content === null ? '' : text(m.content), m.tool_calls, c.finish_reason);
114
+ const reported = usage(root.usage);
115
+ return { response, ...(reported ? { usage: reported } : {}) };
116
+ }
117
+ let content = '', reason, reported;
118
+ let responseId, responseModel;
119
+ const calls = new Map();
120
+ for await (const { data: frame } of sseFrames(body)) {
121
+ if (frame === '[DONE]') {
122
+ if (reason === undefined)
123
+ throw new ModelGatewayError('incomplete');
124
+ const ordered = [...calls.entries()].sort(([a], [b]) => a - b);
125
+ if (ordered.some(([index], i) => index !== i))
126
+ return protocol();
127
+ return { response: finish(content, ordered.map(([, c]) => c), reason), ...(reported ? { usage: reported } : {}) };
128
+ }
129
+ const root = object(parse(frame));
130
+ if (root.error != null || !Array.isArray(root.choices) || root.choices.length > 1)
131
+ return protocol();
132
+ if (root.id !== undefined) {
133
+ const current = id(root.id);
134
+ if (responseId !== undefined && current !== responseId)
135
+ return protocol();
136
+ responseId = current;
137
+ }
138
+ if (root.model !== undefined) {
139
+ const current = id(root.model);
140
+ if (responseModel !== undefined && current !== responseModel)
141
+ return protocol();
142
+ responseModel = current;
143
+ }
144
+ if (root.usage != null) {
145
+ if (reported)
146
+ return protocol();
147
+ reported = usage(root.usage);
148
+ if (reported)
149
+ emit({ type: 'usage', usage: reported });
150
+ }
151
+ if (root.choices.length === 0)
152
+ continue;
153
+ if (reason !== undefined)
154
+ return protocol();
155
+ const c = object(root.choices[0]), delta = object(c.delta);
156
+ if (c.index !== 0)
157
+ return protocol();
158
+ messageFields(delta);
159
+ if (delta.content != null) {
160
+ const piece = text(delta.content);
161
+ content += piece;
162
+ emit({ type: 'text_delta', text: piece });
163
+ }
164
+ if (delta.tool_calls != null) {
165
+ if (!Array.isArray(delta.tool_calls))
166
+ return protocol();
167
+ for (const raw of delta.tool_calls) {
168
+ const d = object(raw), i = d.index;
169
+ if (typeof i !== 'number' || !Number.isInteger(i) || i < 0 || i >= 8)
170
+ return protocol();
171
+ const prior = calls.get(i) ?? { id: '', type: '', function: { name: '', arguments: '' } };
172
+ if (d.type !== undefined) {
173
+ if (d.type !== 'function' || (prior.type && prior.type !== d.type))
174
+ return protocol();
175
+ prior.type = 'function';
176
+ }
177
+ if (d.id !== undefined) {
178
+ if (prior.id)
179
+ return protocol();
180
+ prior.id = id(d.id);
181
+ }
182
+ const f = d.function === undefined ? {} : object(d.function);
183
+ const progress = { type: 'tool_delta', index: i };
184
+ if (d.id !== undefined)
185
+ progress.id = prior.id;
186
+ if (f.name !== undefined) {
187
+ const piece = text(f.name);
188
+ prior.function.name += piece;
189
+ progress.name = piece;
190
+ }
191
+ if (f.arguments !== undefined) {
192
+ const piece = text(f.arguments);
193
+ prior.function.arguments += piece;
194
+ progress.arguments = piece;
195
+ if (Buffer.byteLength(prior.function.arguments) > maxArguments)
196
+ return protocol();
197
+ }
198
+ calls.set(i, prior);
199
+ emit(progress);
200
+ }
201
+ }
202
+ if (Buffer.byteLength(content) > maxResponse)
203
+ return protocol();
204
+ if (c.finish_reason != null)
205
+ reason = c.finish_reason;
206
+ }
207
+ throw new ModelGatewayError('incomplete');
208
+ },
209
+ };
210
+ }
@@ -0,0 +1,47 @@
1
+ const messages = {
2
+ configuration: 'Invalid explicit model configuration',
3
+ request: 'Invalid or oversized model request',
4
+ protocol: 'Invalid or oversized model response',
5
+ incomplete: 'Model response did not finish completely',
6
+ authentication: 'Model request authentication or access rejected',
7
+ quota: 'Model account quota rejected',
8
+ rate_limit: 'Temporary model rate limit rejection',
9
+ http: 'Model HTTP request failed; not eligible for automatic replay',
10
+ transport: 'Model transport failed; remote effects unknown',
11
+ cancelled: 'Model request cancelled; remote cancellation is not rollback',
12
+ deadline: 'Model request deadline exceeded; remote effects may be unknown',
13
+ };
14
+ /** No raw cause, URL, request/response bodies, headers, credentials or provider message. */
15
+ export class ModelGatewayError extends Error {
16
+ code;
17
+ effect;
18
+ stopReason;
19
+ requestId;
20
+ source = 'live';
21
+ attempts;
22
+ constructor(code, effect = 'unknown', attempts = [], stopReason, requestId) {
23
+ super(messages[code]);
24
+ this.code = code;
25
+ this.effect = effect;
26
+ this.stopReason = stopReason;
27
+ this.requestId = requestId;
28
+ this.name = 'ModelGatewayError';
29
+ this.attempts = Object.freeze(attempts.map(a => Object.freeze({
30
+ ...a, ...(a.usage ? { usage: Object.freeze({ ...a.usage }) } : {}),
31
+ })));
32
+ }
33
+ }
34
+ export function protocol() { throw new ModelGatewayError('protocol'); }
35
+ export function object(value) {
36
+ if (!value || typeof value !== 'object' || Array.isArray(value))
37
+ return protocol();
38
+ return value;
39
+ }
40
+ export function parse(text) {
41
+ try {
42
+ return JSON.parse(text);
43
+ }
44
+ catch {
45
+ return protocol();
46
+ }
47
+ }