MCPcopy
hub / github.com/cft0808/edict / cmd_create

Function cmd_create

scripts/kanban_update.py:290–323  ·  view source on GitHub ↗

新建任务(收旨时立即调用)

(task_id, title, state, org, official, remark=None)

Source from the content-addressed store, hash-verified

288
289
290def cmd_create(task_id, title, state, org, official, remark=None):
291 """新建任务(收旨时立即调用)"""
292 # 清洗标题(剥离元数据)
293 title = _sanitize_title(title)
294 # 旨意标题校验
295 valid, reason = _is_valid_task_title(title)
296 if not valid:
297 log.warning(f'⚠️ 拒绝创建 {task_id}:{reason}')
298 print(f'[看板] 拒绝创建:{reason}', flush=True)
299 return
300 actual_org = STATE_ORG_MAP.get(state, org)
301 clean_remark = _sanitize_remark(remark) if remark else f"下旨:{title}"
302 def modifier(tasks):
303 existing = next((t for t in tasks if t.get('id') == task_id), None)
304 if existing:
305 if existing.get('state') in ('Done', 'Cancelled'):
306 log.warning(f'⚠️ 任务 {task_id} 已完结 (state={existing["state"]}),不可覆盖')
307 return tasks
308 if existing.get('state') not in (None, '', 'Inbox', 'Pending'):
309 log.warning(f'任务 {task_id} 已存在 (state={existing["state"]}),将被覆盖')
310 tasks = [t for t in tasks if t.get('id') != task_id]
311 tasks.insert(0, {
312 "id": task_id, "title": title, "official": official,
313 "org": actual_org, "state": state,
314 "now": clean_remark[:60] if remark else f"已下旨,等待{actual_org}接旨",
315 "eta": "-", "block": "无", "output": "", "ac": "",
316 "flow_log": [{"at": now_iso(), "from": "皇上", "to": actual_org, "remark": clean_remark}],
317 "updatedAt": now_iso()
318 })
319 return tasks
320 atomic_json_update(TASKS_FILE, modifier, [])
321 _trigger_refresh()
322 log.info(f'✅ 创建 {task_id} | {title[:30]} | state={state}')
323 _append_audit(task_id, _infer_agent_id_from_runtime(), 'create', None, state, title)
324
325
326# ── 状态流转合法性校验 ──

Callers 10

test_dirty_title_cleanedFunction · 0.90
test_pure_path_rejectedFunction · 0.90
test_normal_titleFunction · 0.90
test_flow_remark_cleanedFunction · 0.90
test_prefix_strippedFunction · 0.90
test_state_updateFunction · 0.90
test_doneFunction · 0.90
kanban_update.pyFile · 0.70

Calls 7

atomic_json_updateFunction · 0.90
_append_auditFunction · 0.85
_sanitize_titleFunction · 0.70
_is_valid_task_titleFunction · 0.70
_sanitize_remarkFunction · 0.70
_trigger_refreshFunction · 0.70

Tested by 9

test_dirty_title_cleanedFunction · 0.72
test_pure_path_rejectedFunction · 0.72
test_normal_titleFunction · 0.72
test_flow_remark_cleanedFunction · 0.72
test_prefix_strippedFunction · 0.72
test_state_updateFunction · 0.72
test_doneFunction · 0.72