@jayyuen66/dsh-dir-prep-organize 0.1.4 → 0.1.6
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/CHANGELOG.md +117 -0
- package/LICENSE +1 -1
- package/README.md +209 -104
- package/README.zh-CN.md +209 -102
- package/agents/academic/academic-statistician.md +143 -0
- package/agents/design/design-inclusive-visuals-specialist.md +4 -3
- package/agents/design/design-ui-designer.md +6 -3
- package/agents/design/design-ux-architect.md +20 -7
- package/agents/design/design-whimsy-injector.md +23 -1
- package/agents/engineering/engineering-autonomous-optimization-architect.md +31 -22
- package/agents/engineering/engineering-backend-architect.md +43 -54
- package/agents/engineering/engineering-data-engineer.md +21 -6
- package/agents/engineering/engineering-database-optimizer.md +22 -10
- package/agents/engineering/engineering-devops-automator.md +12 -3
- package/agents/engineering/engineering-email-intelligence-engineer.md +41 -4
- package/agents/engineering/engineering-embedded-firmware-engineer.md +27 -5
- package/agents/engineering/engineering-feishu-integration-developer.md +10 -2
- package/agents/engineering/engineering-frontend-developer.md +24 -18
- package/agents/engineering/engineering-git-workflow-master.md +16 -4
- package/agents/engineering/engineering-incident-response-commander.md +3 -3
- package/agents/engineering/engineering-prompt-engineer.md +7 -2
- package/agents/engineering/engineering-rapid-prototyper.md +7 -3
- package/agents/engineering/engineering-security-engineer.md +2 -0
- package/agents/engineering/engineering-solidity-smart-contract-engineer.md +1 -1
- package/agents/engineering/engineering-technical-writer.md +4 -4
- package/agents/engineering/engineering-threat-detection-engineer.md +2 -0
- package/agents/engineering/engineering-voice-ai-integration-engineer.md +39 -16
- package/agents/engineering/engineering-wechat-mini-program-developer.md +7 -2
- package/agents/game-development/blender/blender-addon-engineer.md +12 -3
- package/agents/game-development/economy-designer.md +155 -0
- package/agents/game-development/godot/godot-gameplay-scripter.md +4 -0
- package/agents/game-development/godot/godot-multiplayer-engineer.md +6 -2
- package/agents/game-development/godot/godot-shader-developer.md +4 -3
- package/agents/game-development/roblox-studio/roblox-experience-designer.md +7 -6
- package/agents/game-development/roblox-studio/roblox-systems-scripter.md +7 -0
- package/agents/game-development/technical-artist.md +4 -0
- package/agents/game-development/unity/unity-multiplayer-engineer.md +67 -0
- package/agents/game-development/unreal-engine/unreal-multiplayer-architect.md +82 -31
- package/agents/game-development/unreal-engine/unreal-systems-engineer.md +13 -1
- package/agents/marketing/marketing-agentic-search-optimizer.md +50 -87
- package/agents/marketing/marketing-carousel-growth-engine.md +49 -35
- package/agents/marketing/marketing-private-domain-operator.md +2 -2
- package/agents/marketing/marketing-seo-specialist.md +22 -0
- package/agents/product/product-behavioral-nudge-engine.md +3 -0
- package/agents/project-management/project-management-jira-workflow-steward.md +5 -2
- package/agents/security/security-appsec-engineer.md +75 -43
- package/agents/security/security-threat-detection-engineer.md +6 -0
- package/agents/security/security-threat-intelligence-analyst.md +32 -15
- package/agents/specialized/accounts-payable-agent.md +39 -45
- package/agents/specialized/grant-writer.md +2 -2
- package/agents/specialized/healthcare-aging-parent-care-companion.md +396 -0
- package/agents/specialized/identity-graph-operator.md +24 -3
- package/agents/specialized/lsp-index-engineer.md +17 -15
- package/agents/specialized/recruitment-specialist.md +17 -11
- package/agents/specialized/specialized-developer-advocate.md +4 -4
- package/agents/specialized/specialized-fedramp-rmf-compliance.md +379 -0
- package/agents/specialized/specialized-focus-music-architect.md +176 -0
- package/agents/specialized/specialized-french-consulting-market.md +17 -15
- package/agents/specialized/specialized-model-qa.md +78 -34
- package/agents/specialized/specialized-salesforce-architect.md +17 -15
- package/agents/specialized/specialized-workflow-architect.md +2 -2
- package/agents/supply-chain/supply-chain-strategist.md +12 -3
- package/agents/support/support-analytics-reporter.md +48 -30
- package/agents/support/support-finance-tracker.md +36 -18
- package/agents/support/support-infrastructure-maintainer.md +2 -2
- package/agents/support/support-support-responder.md +43 -26
- package/agents/testing/testing-api-tester.md +37 -27
- package/agents/testing/testing-performance-benchmarker.md +82 -47
- package/agents/testing/testing-test-results-analyzer.md +37 -18
- package/agents/testing/testing-tool-evaluator.md +30 -10
- package/client.js +209 -141
- package/cordis.patch.yml +4 -23
- package/host.js +98 -68
- package/package.json +53 -44
- package/templates.data.mjs +9 -10
- package/types/host.d.ts +29 -21
- package/types/src/client-timeouts.d.ts +4 -4
- package/types/src/host-messages.d.ts +5 -3
- package/types/src/remote.d.ts +12 -3
- package/types/src/templates.d.ts +3 -3
- package/types/src/ui-messages.d.ts +22 -14
|
@@ -225,7 +225,7 @@ body {
|
|
|
225
225
|
// 主题管理系统
|
|
226
226
|
class ThemeManager {
|
|
227
227
|
constructor() {
|
|
228
|
-
this.currentTheme = this.getStoredTheme() ||
|
|
228
|
+
this.currentTheme = this.getStoredTheme() || 'system';
|
|
229
229
|
this.applyTheme(this.currentTheme);
|
|
230
230
|
this.initializeToggle();
|
|
231
231
|
}
|
|
@@ -235,17 +235,26 @@ class ThemeManager {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
getStoredTheme() {
|
|
238
|
-
|
|
238
|
+
try {
|
|
239
|
+
const stored = localStorage.getItem('theme');
|
|
240
|
+
return stored === 'dark' || stored === 'light' ? stored : null;
|
|
241
|
+
} catch {
|
|
242
|
+
return null; // 在沙箱或受限环境中,存储可能不可用。
|
|
243
|
+
}
|
|
239
244
|
}
|
|
240
245
|
|
|
241
246
|
applyTheme(theme) {
|
|
242
247
|
if (theme === 'system') {
|
|
243
248
|
// 跟随系统时移除手动设置
|
|
244
249
|
document.documentElement.removeAttribute('data-theme');
|
|
245
|
-
localStorage.removeItem('theme');
|
|
246
250
|
} else {
|
|
247
251
|
document.documentElement.setAttribute('data-theme', theme);
|
|
248
|
-
|
|
252
|
+
}
|
|
253
|
+
try {
|
|
254
|
+
if (theme === 'system') localStorage.removeItem('theme');
|
|
255
|
+
else localStorage.setItem('theme', theme);
|
|
256
|
+
} catch {
|
|
257
|
+
// 即使浏览器存储不可用,也要应用所选的主题。
|
|
249
258
|
}
|
|
250
259
|
this.currentTheme = theme;
|
|
251
260
|
this.updateToggleUI();
|
|
@@ -255,9 +264,13 @@ class ThemeManager {
|
|
|
255
264
|
const toggle = document.querySelector('.theme-toggle');
|
|
256
265
|
if (toggle) {
|
|
257
266
|
toggle.addEventListener('click', (e) => {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
267
|
+
const option = e.target instanceof Element
|
|
268
|
+
? e.target.closest('.theme-toggle-option') : null;
|
|
269
|
+
if (option && toggle.contains(option)) {
|
|
270
|
+
const newTheme = option.dataset.theme;
|
|
271
|
+
if (['system', 'light', 'dark'].includes(newTheme)) {
|
|
272
|
+
this.applyTheme(newTheme);
|
|
273
|
+
}
|
|
261
274
|
}
|
|
262
275
|
});
|
|
263
276
|
}
|
|
@@ -199,6 +199,24 @@ color: pink
|
|
|
199
199
|
50% { transform: translateX(-50%) translateY(-20px) scale(1.5); opacity: 1; }
|
|
200
200
|
100% { transform: translateX(-50%) translateY(-30px) scale(1); opacity: 0; }
|
|
201
201
|
}
|
|
202
|
+
|
|
203
|
+
/* 尊重用户在系统/浏览器中设置的减少动效偏好,同时保留可见的反馈。 */
|
|
204
|
+
@media (prefers-reduced-motion: reduce) {
|
|
205
|
+
.btn-whimsy,
|
|
206
|
+
.btn-whimsy::before,
|
|
207
|
+
.loading-whimsy .dot,
|
|
208
|
+
.form-field-success::after,
|
|
209
|
+
.easter-egg-zone,
|
|
210
|
+
.easter-egg-zone:hover,
|
|
211
|
+
.progress-celebration.completed::after {
|
|
212
|
+
animation: none;
|
|
213
|
+
transition: none;
|
|
214
|
+
}
|
|
215
|
+
.btn-whimsy:hover,
|
|
216
|
+
.btn-whimsy:active {
|
|
217
|
+
transform: none;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
202
220
|
```
|
|
203
221
|
|
|
204
222
|
### 趣味文案库
|
|
@@ -318,7 +336,11 @@ class EasterEggManager {
|
|
|
318
336
|
// 基于点击的彩蛋
|
|
319
337
|
let clickSequence = [];
|
|
320
338
|
document.addEventListener('click', (e) => {
|
|
321
|
-
|
|
339
|
+
// 区域内的图标和文字会把点击从它们自己的元素冒泡上来。
|
|
340
|
+
const zone = e.target instanceof Element
|
|
341
|
+
? e.target.closest('.easter-egg-zone')
|
|
342
|
+
: null;
|
|
343
|
+
if (zone) {
|
|
322
344
|
clickSequence.push(Date.now());
|
|
323
345
|
// 只保留 2 秒内的点击
|
|
324
346
|
clickSequence = clickSequence.filter(time => Date.now() - time < 2000);
|
|
@@ -43,40 +43,49 @@ color: "#673AB7"
|
|
|
43
43
|
export async function optimizeAndRoute(
|
|
44
44
|
serviceTask: string,
|
|
45
45
|
providers: Provider[],
|
|
46
|
-
securityLimits: { maxRetries:
|
|
46
|
+
securityLimits: { maxRetries: number, maxCostPerRun: number }
|
|
47
47
|
) {
|
|
48
|
-
|
|
48
|
+
if (!Number.isInteger(securityLimits.maxRetries) || securityLimits.maxRetries < 0 ||
|
|
49
|
+
!Number.isFinite(securityLimits.maxCostPerRun) || securityLimits.maxCostPerRun <= 0) {
|
|
50
|
+
throw new Error('重试次数必须是非负整数,预算必须是有限的正数');
|
|
51
|
+
}
|
|
49
52
|
const rankedProviders = rankByHistoricalPerformance(providers);
|
|
53
|
+
let attempts = 0;
|
|
54
|
+
let spentCost = 0;
|
|
50
55
|
|
|
51
56
|
for (const provider of rankedProviders) {
|
|
52
57
|
if (provider.circuitBreakerTripped) continue;
|
|
53
|
-
|
|
58
|
+
if (attempts >= securityLimits.maxRetries + 1) break;
|
|
59
|
+
attempts += 1;
|
|
60
|
+
let result;
|
|
54
61
|
try {
|
|
55
|
-
|
|
56
|
-
const cost = calculateCost(provider, result.tokens);
|
|
57
|
-
|
|
58
|
-
if (cost > securityLimits.maxCostPerRun) {
|
|
59
|
-
triggerAlert('WARNING', `供应商超出成本上限,正在切换路由。`);
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 后台自学习:异步用更便宜的模型测试输出,
|
|
64
|
-
// 看看后续能否进一步优化。
|
|
65
|
-
shadowTestAgainstAlternative(serviceTask, result, getCheapestProvider(providers));
|
|
66
|
-
|
|
67
|
-
return result;
|
|
68
|
-
|
|
62
|
+
result = await provider.executeWithTimeout(5000);
|
|
69
63
|
} catch (error) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
logFailure(provider);
|
|
65
|
+
if (provider.failures > securityLimits.maxRetries) tripCircuitBreaker(provider);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 费用已经产生。停止路由;不要为了掩盖超支而再花一次钱。
|
|
70
|
+
const cost = calculateCost(provider, result.tokens);
|
|
71
|
+
if (!Number.isFinite(cost) || cost < 0) {
|
|
72
|
+
throw new Error('供应商费用未知或无效,停止路由');
|
|
74
73
|
}
|
|
74
|
+
spentCost += cost;
|
|
75
|
+
if (spentCost > securityLimits.maxCostPerRun) {
|
|
76
|
+
triggerAlert('WARNING', '本次运行超出预算,停止继续尝试供应商。');
|
|
77
|
+
throw new Error('本次运行超出预算');
|
|
78
|
+
}
|
|
79
|
+
// 影子评估需要单独预留的预算;返回生产结果之后,
|
|
80
|
+
// 这个路由循环不会再启动额外的付费工作。
|
|
81
|
+
return result;
|
|
75
82
|
}
|
|
76
|
-
throw new Error('
|
|
83
|
+
throw new Error('在重试预算内没有供应商成功。');
|
|
77
84
|
}
|
|
78
85
|
```
|
|
79
86
|
|
|
87
|
+
这是"扣费之后才停止",并不能证明存在一个预付式的硬性成本上限。在调用付费供应商之前,先为每次尝试预留一个保守的 token/费用上限;把失败或超时产生的费用也记入供应商账本,并在下一次尝试之前核对清楚未知的费用。可选的影子评估要有单独、明确的预算和队列。仅靠 5 秒超时并不能取消远端的计费。
|
|
88
|
+
|
|
80
89
|
## 工作流程
|
|
81
90
|
|
|
82
91
|
1. **第一阶段:基线与边界**:确认当前生产模型,让开发者设定硬限制:"每次执行你最多愿意花多少钱?"
|
|
@@ -128,60 +128,49 @@ CREATE INDEX idx_products_name_search ON products USING gin(to_tsvector('english
|
|
|
128
128
|
```
|
|
129
129
|
|
|
130
130
|
### API 设计规范
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
res.json({
|
|
177
|
-
data: user,
|
|
178
|
-
meta: { timestamp: new Date().toISOString() }
|
|
179
|
-
});
|
|
180
|
-
} catch (error) {
|
|
181
|
-
next(error);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
);
|
|
131
|
+
```yaml
|
|
132
|
+
# 独立的 API 契约示例
|
|
133
|
+
openapi: 3.1.0
|
|
134
|
+
info:
|
|
135
|
+
title: User Service API
|
|
136
|
+
version: 1.0.0
|
|
137
|
+
paths:
|
|
138
|
+
/api/users/{id}:
|
|
139
|
+
get:
|
|
140
|
+
operationId: getUserById
|
|
141
|
+
security:
|
|
142
|
+
- oauth2: [users:read]
|
|
143
|
+
parameters:
|
|
144
|
+
- name: id
|
|
145
|
+
in: path
|
|
146
|
+
required: true
|
|
147
|
+
schema:
|
|
148
|
+
type: string
|
|
149
|
+
format: uuid
|
|
150
|
+
- name: X-Correlation-ID
|
|
151
|
+
in: header
|
|
152
|
+
required: false
|
|
153
|
+
schema:
|
|
154
|
+
type: string
|
|
155
|
+
responses:
|
|
156
|
+
'200':
|
|
157
|
+
description: User found
|
|
158
|
+
'404':
|
|
159
|
+
description: User not found
|
|
160
|
+
'429':
|
|
161
|
+
description: Rate limit exceeded
|
|
162
|
+
'503':
|
|
163
|
+
description: Dependency unavailable
|
|
164
|
+
components:
|
|
165
|
+
securitySchemes:
|
|
166
|
+
oauth2:
|
|
167
|
+
type: oauth2
|
|
168
|
+
flows:
|
|
169
|
+
authorizationCode:
|
|
170
|
+
authorizationUrl: https://auth.example.com/authorize
|
|
171
|
+
tokenUrl: https://auth.example.com/token
|
|
172
|
+
scopes:
|
|
173
|
+
users:read: Read user profiles
|
|
185
174
|
```
|
|
186
175
|
|
|
187
176
|
## 你的沟通风格
|
|
@@ -65,11 +65,12 @@ color: orange
|
|
|
65
65
|
|
|
66
66
|
## 技术交付物
|
|
67
67
|
|
|
68
|
-
### Spark
|
|
68
|
+
### Spark 管线(开源 PySpark + Delta Lake)
|
|
69
69
|
|
|
70
70
|
```python
|
|
71
|
+
from datetime import date
|
|
71
72
|
from pyspark.sql import SparkSession
|
|
72
|
-
from pyspark.sql.functions import col, current_timestamp, sha2, concat_ws, lit
|
|
73
|
+
from pyspark.sql.functions import col, current_timestamp, sha2, concat_ws, lit, input_file_name
|
|
73
74
|
from delta.tables import DeltaTable
|
|
74
75
|
|
|
75
76
|
spark = SparkSession.builder \
|
|
@@ -82,7 +83,7 @@ def ingest_bronze(source_path: str, bronze_table: str, source_system: str) -> in
|
|
|
82
83
|
df = spark.read.format("json").option("inferSchema", "true").load(source_path)
|
|
83
84
|
df = df.withColumn("_ingested_at", current_timestamp()) \
|
|
84
85
|
.withColumn("_source_system", lit(source_system)) \
|
|
85
|
-
.withColumn("_source_file",
|
|
86
|
+
.withColumn("_source_file", input_file_name())
|
|
86
87
|
df.write.format("delta").mode("append").option("mergeSchema", "true").save(bronze_table)
|
|
87
88
|
return df.count()
|
|
88
89
|
|
|
@@ -106,8 +107,18 @@ def upsert_silver(bronze_table: str, silver_table: str, pk_cols: list[str]) -> N
|
|
|
106
107
|
source.write.format("delta").mode("overwrite").save(silver_table)
|
|
107
108
|
|
|
108
109
|
# ── Gold:业务聚合指标 ─────────────────────────────────────────
|
|
109
|
-
def build_gold_daily_revenue(
|
|
110
|
-
|
|
110
|
+
def build_gold_daily_revenue(
|
|
111
|
+
silver_orders: str, gold_table: str, start_date: date, end_date: date
|
|
112
|
+
) -> None:
|
|
113
|
+
# 重新计算一个明确的左闭右开日期窗口,包括没有销售的日期。
|
|
114
|
+
# 如果从已完成的行推导边界,没有数据的那一天会残留过期的收入。
|
|
115
|
+
if start_date >= end_date:
|
|
116
|
+
raise ValueError("start_date must be earlier than end_date")
|
|
117
|
+
predicate = (
|
|
118
|
+
f"order_date >= '{start_date.isoformat()}' "
|
|
119
|
+
f"AND order_date < '{end_date.isoformat()}'"
|
|
120
|
+
)
|
|
121
|
+
df = spark.read.format("delta").load(silver_orders).filter(predicate)
|
|
111
122
|
gold = df.filter(col("status") == "completed") \
|
|
112
123
|
.groupBy("order_date", "region", "product_category") \
|
|
113
124
|
.agg({"revenue": "sum", "order_id": "count"}) \
|
|
@@ -115,10 +126,14 @@ def build_gold_daily_revenue(silver_orders: str, gold_table: str) -> None:
|
|
|
115
126
|
.withColumnRenamed("count(order_id)", "order_count") \
|
|
116
127
|
.withColumn("_refreshed_at", current_timestamp())
|
|
117
128
|
gold.write.format("delta").mode("overwrite") \
|
|
118
|
-
.option("replaceWhere",
|
|
129
|
+
.option("replaceWhere", predicate) \
|
|
119
130
|
.save(gold_table)
|
|
120
131
|
```
|
|
121
132
|
|
|
133
|
+
`_source_file` 必须记录 Spark 实际读取的文件,而不是数据里一个名叫 `_metadata.file_path` 的字段。这个开源 Spark 示例使用 [PySpark `input_file_name`](https://spark.apache.org/docs/3.5.6/api/python/reference/pyspark.sql/api/pyspark.sql.functions.input_file_name.html),这样即使源 JSON 里含有 `_metadata`,也无法冒充物理文件的 URI。请按你实际部署的运行环境调整来源记录方式;[Databricks 文件元数据 API](https://docs.databricks.com/aws/en/ingestion/file-metadata-column) 也说明了它与源数据中名为 `_metadata` 的列之间的冲突。
|
|
134
|
+
|
|
135
|
+
针对请求的日期窗口,要基于完整的 Silver 快照刷新 Gold 层,而不是一批不完整的事件。Delta 的 `replaceWhere` 即使在聚合结果为空时,也会精确地替换这个窗口;窗口之外的日期必须保持不变。保持它默认开启的谓词约束检查。例如,一笔订单退款后刷新 `[2026-09-01, 2026-09-02)`,必须移除 9 月 1 日的旧收入,同时保留 9 月 2 日及之后的结果。参见 [Delta 选择性覆盖写入](https://docs.delta.io/delta-batch/#selective-overwrite)。
|
|
136
|
+
|
|
122
137
|
### dbt 数据质量契约
|
|
123
138
|
|
|
124
139
|
```yaml
|
|
@@ -72,16 +72,23 @@ SELECT * FROM comments WHERE post_id = ?;
|
|
|
72
72
|
EXPLAIN ANALYZE
|
|
73
73
|
SELECT
|
|
74
74
|
p.id, p.title, p.content,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
COALESCE(
|
|
76
|
+
json_agg(json_build_object(
|
|
77
|
+
'id', c.id,
|
|
78
|
+
'content', c.content,
|
|
79
|
+
'author', c.author
|
|
80
|
+
) ORDER BY c.id) FILTER (WHERE c.id IS NOT NULL),
|
|
81
|
+
'[]'::json
|
|
82
|
+
) AS comments
|
|
80
83
|
FROM posts p
|
|
81
84
|
LEFT JOIN comments c ON c.post_id = p.id
|
|
82
85
|
WHERE p.user_id = 123
|
|
83
86
|
GROUP BY p.id;
|
|
84
87
|
|
|
88
|
+
-- 回归用例:没有评论 => [];两条评论 => 两个按顺序排列的对象。
|
|
89
|
+
-- FILTER 去掉 LEFT JOIN 产生的那一行全为 NULL 的合成行;COALESCE 让空聚合
|
|
90
|
+
-- 返回和有数据时相同形状的数组。
|
|
91
|
+
|
|
85
92
|
-- 检查查询计划:
|
|
86
93
|
-- 关注:Seq Scan(差)、Index Scan(好)、Bitmap Heap Scan(尚可)
|
|
87
94
|
-- 对比:实际时间 vs 预估时间,实际行数 vs 预估行数
|
|
@@ -152,11 +159,16 @@ const supabase = createClient(
|
|
|
152
159
|
}
|
|
153
160
|
);
|
|
154
161
|
|
|
155
|
-
// Serverless
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
);
|
|
162
|
+
// Serverless 场景使用服务商提供的事务模式连接池连接串。
|
|
163
|
+
// 只有当服务商使用相同的主机/凭据、且端口为 6543 时才这样做:
|
|
164
|
+
// 修改的是 URL 的端口,绝不能替换凭据或数据库名里恰好匹配的子串。
|
|
165
|
+
function transactionPoolUrl(connectionString?: string): string | undefined {
|
|
166
|
+
if (!connectionString) return undefined;
|
|
167
|
+
const url = new URL(connectionString);
|
|
168
|
+
url.port = '6543';
|
|
169
|
+
return url.toString();
|
|
170
|
+
}
|
|
171
|
+
const pooledUrl = transactionPoolUrl(process.env.DATABASE_URL);
|
|
160
172
|
```
|
|
161
173
|
|
|
162
174
|
## 关键规则
|
|
@@ -89,9 +89,10 @@ jobs:
|
|
|
89
89
|
needs: test
|
|
90
90
|
runs-on: ubuntu-latest
|
|
91
91
|
steps:
|
|
92
|
+
- uses: actions/checkout@v3
|
|
92
93
|
- name: Build and Push
|
|
93
94
|
run: |
|
|
94
|
-
docker build -t app:${{ github.sha }} .
|
|
95
|
+
docker build -t registry/app:${{ github.sha }} .
|
|
95
96
|
docker push registry/app:${{ github.sha }}
|
|
96
97
|
|
|
97
98
|
deploy:
|
|
@@ -170,15 +171,23 @@ resource "aws_cloudwatch_metric_alarm" "high_cpu" {
|
|
|
170
171
|
comparison_operator = "GreaterThanThreshold"
|
|
171
172
|
evaluation_periods = "2"
|
|
172
173
|
metric_name = "CPUUtilization"
|
|
173
|
-
namespace = "AWS/
|
|
174
|
-
|
|
174
|
+
namespace = "AWS/EC2"
|
|
175
|
+
dimensions = {
|
|
176
|
+
AutoScalingGroupName = aws_autoscaling_group.app.name
|
|
177
|
+
}
|
|
178
|
+
# 与 EC2 基础监控每五分钟发布一次数据的间隔保持一致。
|
|
179
|
+
period = "300"
|
|
175
180
|
statistic = "Average"
|
|
176
181
|
threshold = "80"
|
|
182
|
+
# 缺失的遥测数据是"未知",不能当作 CPU 正常的证据。
|
|
183
|
+
treat_missing_data = "missing"
|
|
177
184
|
|
|
178
185
|
alarm_actions = [aws_sns_topic.alerts.arn]
|
|
179
186
|
}
|
|
180
187
|
```
|
|
181
188
|
|
|
189
|
+
在启用告警之前,先对照实际发布的数据点,确认它的命名空间、指标名、维度和采集频率。`CPUUtilization` 属于 [AWS/EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/viewing_metrics_with_cloudwatch.html) 命名空间,`AutoScalingGroupName` 用来选中这个应用的实例。`AWS/ApplicationELB` 发布的是负载均衡器的指标,而不是实例的 CPU。EC2 基础监控每五分钟发布一次数据;如果需要一分钟级别的检测,要显式开启详细监控。把缺失的数据视为未知,并单独监控遥测数据的丢失。
|
|
190
|
+
|
|
182
191
|
### 监控与告警配置
|
|
183
192
|
```yaml
|
|
184
193
|
# Prometheus 配置
|
|
@@ -98,8 +98,14 @@ def fetch_thread(imap_conn, thread_ids):
|
|
|
98
98
|
"""获取并解析原始消息,保留完整 MIME 结构。"""
|
|
99
99
|
messages = []
|
|
100
100
|
for msg_id in thread_ids:
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
status, data = imap_conn.fetch(msg_id, "(RFC822)")
|
|
102
|
+
if status != 'OK':
|
|
103
|
+
raise RuntimeError(f'IMAP fetch failed for message {msg_id}: {status}')
|
|
104
|
+
raw = next((item[1] for item in data or []
|
|
105
|
+
if isinstance(item, tuple) and len(item) == 2
|
|
106
|
+
and isinstance(item[1], bytes)), None)
|
|
107
|
+
if raw is None:
|
|
108
|
+
raise RuntimeError(f'IMAP returned no RFC822 body for message {msg_id}')
|
|
103
109
|
parsed = email.message_from_bytes(raw, policy=policy.default)
|
|
104
110
|
messages.append({
|
|
105
111
|
"message_id": parsed["Message-ID"],
|
|
@@ -127,7 +133,28 @@ def reconstruct_thread(messages):
|
|
|
127
133
|
- 引用回复导致内容重复(20 条消息的线程约产生 4-5 倍 token 膨胀)
|
|
128
134
|
- 当不同人回复链中不同消息时,线程会产生分叉
|
|
129
135
|
"""
|
|
130
|
-
#
|
|
136
|
+
# 在构建或修改回复图之前,先拒绝身份不明确的消息。
|
|
137
|
+
# 缺失或重复的 Message-ID 必须进入隔离/人工处理流程;
|
|
138
|
+
# 悄悄使用 None(或被重复使用的 ID)会覆盖掉一条不相关的消息。
|
|
139
|
+
messages = list(messages) # 继续支持只能遍历一次的消息迭代器
|
|
140
|
+
message_ids = [msg.get("message_id") for msg in messages]
|
|
141
|
+
if any(not isinstance(mid, str) or not mid.strip() for mid in message_ids):
|
|
142
|
+
raise ValueError("Every message needs a nonempty Message-ID")
|
|
143
|
+
if len(set(message_ids)) != len(message_ids):
|
|
144
|
+
raise ValueError("Duplicate Message-ID: resolve identity before reconstruction")
|
|
145
|
+
|
|
146
|
+
parents = {msg["message_id"]: msg["in_reply_to"] for msg in messages}
|
|
147
|
+
checked = set()
|
|
148
|
+
for start in parents:
|
|
149
|
+
path = set()
|
|
150
|
+
current = start
|
|
151
|
+
while current in parents and current not in checked:
|
|
152
|
+
if current in path:
|
|
153
|
+
raise ValueError("Cyclic In-Reply-To headers: quarantine before reconstruction")
|
|
154
|
+
path.add(current)
|
|
155
|
+
current = parents[current]
|
|
156
|
+
checked.update(path)
|
|
157
|
+
|
|
131
158
|
graph = {}
|
|
132
159
|
for msg in messages:
|
|
133
160
|
parent_id = msg["in_reply_to"]
|
|
@@ -160,6 +187,12 @@ def strip_quoted_content(body, parent_bodies):
|
|
|
160
187
|
- Outlook XML 引用:带特定 class 的嵌套 <div> 块
|
|
161
188
|
"""
|
|
162
189
|
lines = body.split("\n")
|
|
190
|
+
parent_lines = {
|
|
191
|
+
line.strip()
|
|
192
|
+
for parent in parent_bodies
|
|
193
|
+
for line in parent.splitlines()
|
|
194
|
+
if line.strip()
|
|
195
|
+
}
|
|
163
196
|
unique_lines = []
|
|
164
197
|
in_quote_block = False
|
|
165
198
|
|
|
@@ -170,7 +203,11 @@ def strip_quoted_content(body, parent_bodies):
|
|
|
170
203
|
if in_quote_block and not line.strip():
|
|
171
204
|
in_quote_block = False
|
|
172
205
|
continue
|
|
173
|
-
if not in_quote_block
|
|
206
|
+
if not in_quote_block:
|
|
207
|
+
# 新出现的引用仍然是这封邮件自己的证据。只有当带前缀的
|
|
208
|
+
# 引用行内容与某条父消息重复时,才把它去掉。
|
|
209
|
+
if line.startswith(">") and line[1:].strip() in parent_lines:
|
|
210
|
+
continue
|
|
174
211
|
unique_lines.append(line)
|
|
175
212
|
|
|
176
213
|
return "\n".join(unique_lines)
|
|
@@ -65,20 +65,42 @@ static void sensor_task(void *arg) {
|
|
|
65
65
|
|
|
66
66
|
void app_main(void) {
|
|
67
67
|
sensor_queue = xQueueCreate(8, sizeof(sensor_data_t));
|
|
68
|
-
|
|
68
|
+
if (sensor_queue == NULL) {
|
|
69
|
+
// 绝不启动一个会向无效队列发送数据的任务。
|
|
70
|
+
return; // 通过应用的故障处理路径上报内存分配失败。
|
|
71
|
+
}
|
|
72
|
+
if (xTaskCreate(sensor_task, "sensor", TASK_STACK_SIZE, NULL,
|
|
73
|
+
TASK_PRIORITY, NULL) != pdPASS) {
|
|
74
|
+
vQueueDelete(sensor_queue);
|
|
75
|
+
sensor_queue = NULL;
|
|
76
|
+
return; // 没有任务持有这个队列;上报故障之前先释放它。
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
79
|
```
|
|
71
80
|
|
|
72
|
-
### STM32 LL SPI
|
|
81
|
+
### STM32 LL SPI 传输(有超时的轮询,在任务上下文中调用)
|
|
73
82
|
|
|
74
83
|
```c
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
#include <stdbool.h>
|
|
85
|
+
#include <stdint.h>
|
|
86
|
+
|
|
87
|
+
// 适用于带 TXE/BSY 标志位的 STM32 SPI(例如 STM32F4);这不是可在中断里调用的 API,也不是非阻塞的。
|
|
88
|
+
// 轮询期间 HAL_GetTick 必须持续递增。两次等待共用同一个截止时间。
|
|
89
|
+
bool spi_write_byte(SPI_TypeDef *spi, uint8_t data, uint32_t timeout_ms) {
|
|
90
|
+
const uint32_t started = HAL_GetTick();
|
|
91
|
+
while (!LL_SPI_IsActiveFlag_TXE(spi)) {
|
|
92
|
+
if ((uint32_t)(HAL_GetTick() - started) >= timeout_ms) return false;
|
|
93
|
+
}
|
|
77
94
|
LL_SPI_TransmitData8(spi, data);
|
|
78
|
-
while (LL_SPI_IsActiveFlag_BSY(spi))
|
|
95
|
+
while (LL_SPI_IsActiveFlag_BSY(spi)) {
|
|
96
|
+
if ((uint32_t)(HAL_GetTick() - started) >= timeout_ms) return false;
|
|
97
|
+
}
|
|
98
|
+
return true;
|
|
79
99
|
}
|
|
80
100
|
```
|
|
81
101
|
|
|
102
|
+
如果在写入发送数据之后返回 `false`,说明传输是否完成是未知的:重试之前,要依照目标 MCU 的参考手册和勘误表恢复外设,不要盲目重发。调用方必须保持非阻塞时,改用中断或 DMA。
|
|
103
|
+
|
|
82
104
|
### Nordic nRF BLE 广播(nRF Connect SDK / Zephyr)
|
|
83
105
|
|
|
84
106
|
```c
|
|
@@ -472,7 +472,7 @@ async function createApprovalInstance(params: {
|
|
|
472
472
|
// 查询审批实例详情
|
|
473
473
|
async function getApprovalInstance(instanceCode: string) {
|
|
474
474
|
const resp = await client.approval.instance.get({
|
|
475
|
-
|
|
475
|
+
path: { instance_id: instanceCode },
|
|
476
476
|
});
|
|
477
477
|
|
|
478
478
|
if (resp.code !== 0) {
|
|
@@ -510,9 +510,17 @@ router.get('/login/feishu', (req, res) => {
|
|
|
510
510
|
router.get('/callback/feishu', async (req, res) => {
|
|
511
511
|
const { code, state } = req.query;
|
|
512
512
|
|
|
513
|
-
|
|
513
|
+
const expectedState = req.session?.oauthState;
|
|
514
|
+
if (typeof code !== 'string' || !code ||
|
|
515
|
+
typeof state !== 'string' || !state ||
|
|
516
|
+
typeof expectedState !== 'string' || !expectedState ||
|
|
517
|
+
state !== expectedState) {
|
|
514
518
|
return res.status(403).json({ error: 'state 不匹配,可能存在 CSRF 攻击' });
|
|
515
519
|
}
|
|
520
|
+
// 在第一个 await 之前,就消费掉本次请求绑定的 state。
|
|
521
|
+
// 如果回调可能加载到各自独立的会话副本,还要在共享的会话存储中原子地让 state 失效;
|
|
522
|
+
// 仅删除这个对象做不到这一点。
|
|
523
|
+
delete req.session!.oauthState;
|
|
516
524
|
|
|
517
525
|
const tokenResp = await client.authen.oidcAccessToken.create({
|
|
518
526
|
data: {
|
|
@@ -95,24 +95,30 @@ export const DataTable = memo<DataTableProps>(({ data, columns, onRowClick }) =>
|
|
|
95
95
|
role="table"
|
|
96
96
|
aria-label="Data table"
|
|
97
97
|
>
|
|
98
|
-
{rowVirtualizer.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
<div role="rowgroup" style={{ height: rowVirtualizer.getTotalSize(), position: 'relative' }}>
|
|
99
|
+
{rowVirtualizer.getVirtualItems().map((virtualItem) => {
|
|
100
|
+
const row = data[virtualItem.index];
|
|
101
|
+
return (
|
|
102
|
+
<div
|
|
103
|
+
key={virtualItem.key}
|
|
104
|
+
className="flex items-center border-b hover:bg-gray-50 cursor-pointer"
|
|
105
|
+
style={{
|
|
106
|
+
position: 'absolute', top: 0, left: 0, width: '100%',
|
|
107
|
+
height: virtualItem.size, transform: `translateY(${virtualItem.start}px)`,
|
|
108
|
+
}}
|
|
109
|
+
onClick={() => handleRowClick(row)}
|
|
110
|
+
role="row"
|
|
111
|
+
tabIndex={0}
|
|
112
|
+
>
|
|
113
|
+
{columns.map((column) => (
|
|
114
|
+
<div key={column.key} className="px-4 py-2 flex-1" role="cell">
|
|
115
|
+
{row[column.key]}
|
|
116
|
+
</div>
|
|
117
|
+
))}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
})}
|
|
121
|
+
</div>
|
|
116
122
|
</div>
|
|
117
123
|
);
|
|
118
124
|
});
|
|
@@ -63,16 +63,28 @@ release/1.3 ──────────────●────●──
|
|
|
63
63
|
### 开始工作
|
|
64
64
|
```bash
|
|
65
65
|
git fetch origin
|
|
66
|
-
git
|
|
67
|
-
#
|
|
68
|
-
git
|
|
66
|
+
git switch --no-track -c feat/my-feature origin/main
|
|
67
|
+
# 推送功能分支,并显式设置它的上游:
|
|
68
|
+
git push -u origin feat/my-feature
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
+
并行开发时,用下面的方式**代替**在当前检出中创建分支。Git 不能在两个工作树中检出同一个分支:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
git fetch origin
|
|
75
|
+
git worktree add --no-track -b feat/my-feature ../my-feature origin/main
|
|
76
|
+
cd ../my-feature
|
|
77
|
+
git push -u origin feat/my-feature
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`--no-track` 防止新的功能分支把 `origin/main` 继承为自己的上游。第一次推送之后,它的上游就是 `origin/feat/my-feature`。
|
|
81
|
+
|
|
71
82
|
### PR 前清理
|
|
72
83
|
```bash
|
|
73
84
|
git fetch origin
|
|
74
85
|
git rebase -i origin/main # 合并 fixup,修改提交信息
|
|
75
|
-
|
|
86
|
+
# 只改写你自己的功能分支,并且要征得协作者同意:
|
|
87
|
+
git push --force-with-lease origin HEAD:feat/my-feature
|
|
76
88
|
```
|
|
77
89
|
|
|
78
90
|
### 完成分支
|