@hupan56/wlkj 3.1.30 → 3.1.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hupan56/wlkj",
3
- "version": "3.1.30",
3
+ "version": "3.1.31",
4
4
  "description": "AI Product R&D Workflow - PRD/Prototype/Search/Task/Report",
5
5
  "bin": {
6
6
  "wlkj": "bin/cli.js"
@@ -352,11 +352,11 @@ def configure_git_identity(name):
352
352
  return False
353
353
 
354
354
  # 5. 交互式收集 git 账号
355
- print('\n 配置你的团队 git 账号 (用于提交代码和团队协作):')
355
+ print('\n 配置 git 账号 (仅用于标识谁提交了代码, 不需要注册/登录):')
356
356
  while True:
357
357
  try:
358
358
  git_name = input(f' git 用户名 [{existing_name or name}]: ').strip() or existing_name or name
359
- git_email = input(' git 邮箱 (团队邮箱): ').strip()
359
+ git_email = input(f' git 邮箱 (填你的邮箱即可, 不需要注册): ').strip()
360
360
  if not git_email or '@' not in git_email:
361
361
  print(' 邮箱格式不对 (需含 @), 重试。')
362
362
  continue
@@ -300,6 +300,106 @@ def fetch_workbench(include_closed=False, kind=None):
300
300
  return {'ok': True, 'data': data, 'meta': meta}, 0
301
301
 
302
302
 
303
+ # ============================================================
304
+ # 写操作 (v0.3): 面板按钮触发的禅道状态流转
305
+ # 设计对齐 MCP server 的 _assert_owner: 写前校验归属, 防误改队友。
306
+ # 任务: start/pause/finish/log_effort; Bug: confirm/resolve
307
+ # ============================================================
308
+
309
+ def _check_owner(client, my_account, kind, item_id):
310
+ """写前归属校验 (对齐 mcp server _assert_owner)。
311
+ task 只认 assignedTo==我; bug 认 assignedTo==我 OR openedBy==我。
312
+ 返回 None=放行, 字符串=拒绝原因。"""
313
+ r = client.api('GET', '/%ss/%s' % (kind, item_id))
314
+ if r.status_code not in (200, 201):
315
+ return None # 查询失败不阻塞 (禅道权限兜底)
316
+ data = r.json()
317
+ asg = ZentaoClient.assignee_account(data)
318
+ allow = (asg == my_account)
319
+ if kind == 'bug' and not allow:
320
+ allow = (ZentaoClient.openedby_account(data) == my_account)
321
+ if not allow:
322
+ return '这条%s指派给 %s, 不是你(%s), 已拒绝改。' % (kind, asg or '空', my_account)
323
+ return None
324
+
325
+
326
+ # 禅道写操作的 HTTP 调度表: action -> (method, path_tpl, payload_builder, ok_msg)
327
+ # payload_builder(args_dict) -> payload_dict
328
+ def _do_action(client, my_account, action, item_id, params):
329
+ """执行单个写操作。返回 (result_dict, exit_code)。"""
330
+ developer = get_developer()
331
+ my_account = my_account or (_resolve_my_account(developer)[0] if developer else None)
332
+ if not my_account:
333
+ return {'ok': False, 'error': '未识别禅道身份, 无法校验归属。请配 member.json 的 zentao_account。'}, 3
334
+
335
+ # action 分派
336
+ ACTIONS = {
337
+ # 任务类 (kind=task)
338
+ 'start_task': ('task', 'POST', '/tasks/%s/start', {'left': 'left'}),
339
+ 'pause_task': ('task', 'POST', '/tasks/%s/pause', {}),
340
+ 'finish_task': ('task', 'POST', '/tasks/%s/finish', {'left': 'left', 'consumed': 'consumed'}),
341
+ 'log_effort': ('task', 'POST', '/tasks/%s/estimate', {'consumed': 'consumed', 'left': 'left'}),
342
+ # Bug 类 (kind=bug)
343
+ 'confirm_bug': ('bug', 'POST', '/bugs/%s/confirm', {}),
344
+ 'resolve_bug': ('bug', 'POST', '/bugs/%s/resolve', {'resolution': 'resolution', 'comment': 'comment'}),
345
+ }
346
+ if action not in ACTIONS:
347
+ return {'ok': False, 'error': '未知操作: %s。支持: %s' % (action, ', '.join(ACTIONS.keys()))}, 3
348
+
349
+ kind, method, path_tpl, fields = ACTIONS[action]
350
+ path = path_tpl % item_id
351
+
352
+ # ① 归属校验 (防误改队友)
353
+ guard = _check_owner(client, my_account, kind, item_id)
354
+ if guard:
355
+ return {'ok': False, 'error': guard}, 4
356
+
357
+ # ② 拼 payload (只取该操作关心的字段, 缺省给合理默认)
358
+ payload = {}
359
+ for pkey, fkey in fields.items():
360
+ v = params.get(fkey)
361
+ if v is not None and v != '':
362
+ try:
363
+ payload[pkey] = float(v) if fkey in ('left', 'consumed') else v
364
+ except (ValueError, TypeError):
365
+ payload[pkey] = v
366
+ # finish 强制 left=0 (完成=没剩余工时); log_effort 的 consumed 必填兜底
367
+ if action == 'finish_task' and 'left' not in payload:
368
+ payload['left'] = 0
369
+ if action == 'resolve_bug' and 'resolution' not in payload:
370
+ payload['resolution'] = 'fixed'
371
+
372
+ # ③ 调禅道
373
+ r = client.api(method, path, payload)
374
+ if r.status_code in (200, 201):
375
+ label = {
376
+ 'start_task': '已开始', 'pause_task': '已暂停', 'finish_task': '已完成',
377
+ 'log_effort': '已记工时', 'confirm_bug': '已确认', 'resolve_bug': '已解决',
378
+ }[action]
379
+ return {'ok': True, 'data': {'action': action, 'id': item_id, 'message': '%s #%s %s' % (kind, item_id, label)}}, 0
380
+ return {'ok': False, 'error': '操作失败 (HTTP %s): %s。可能权限不足或当前状态不允许。' % (
381
+ r.status_code, ZentaoClient.err_text(r))}, 5
382
+
383
+
384
+ def perform_action(action, item_id, params=None):
385
+ """写操作入口。返回 (result_dict, exit_code)。"""
386
+ params = params or {}
387
+ client = _zentao_creds()
388
+ if client is None:
389
+ return {'ok': False, 'error': '禅道凭据未配置。'}, 3
390
+ ok, msg = client.credentials_ok()
391
+ if not ok:
392
+ return {'ok': False, 'error': '禅道凭据不完整: %s' % msg}, 3
393
+ ok, msg = client.check_intranet()
394
+ if not ok:
395
+ return {'ok': False, 'error': '连不上禅道内网: %s' % msg}, 5
396
+ developer = get_developer()
397
+ my_account, err = _resolve_my_account(developer) if developer else (None, '未识别开发者身份')
398
+ if err and not my_account:
399
+ return {'ok': False, 'error': err}, 3
400
+ return _do_action(client, my_account, action, item_id, params)
401
+
402
+
303
403
  def main():
304
404
  parser = argparse.ArgumentParser(description='禅道任务面板数据接口 (输出 JSON 供 VS Code 扩展消费)')
305
405
  parser.add_argument('--json', action='store_true', help='JSON 输出 (面板默认用这个)')
@@ -307,21 +407,41 @@ def main():
307
407
  parser.add_argument('--kind', choices=['tasks', 'bugs', 'stories'],
308
408
  help='只取某一域 (默认三域全取)')
309
409
  parser.add_argument('--pretty', action='store_true', help='JSON 美化缩进 (默认紧凑, 面板解析更快)')
410
+ # 写操作子命令 (v0.3)
411
+ parser.add_argument('--action', choices=['start_task', 'pause_task', 'finish_task',
412
+ 'log_effort', 'confirm_bug', 'resolve_bug'],
413
+ help='执行禅道写操作 (面板按钮触发)')
414
+ parser.add_argument('--id', type=int, help='写操作的目标 task/bug ID')
415
+ parser.add_argument('--left', help='剩余工时 (start/finish/log_effort)')
416
+ parser.add_argument('--consumed', help='消耗工时 (finish/log_effort)')
417
+ parser.add_argument('--resolution', help='Bug 解决方式 (resolve_bug): fixed/bydesign/duplicate/notrepro/postpone')
418
+ parser.add_argument('--comment', help='Bug 解决备注 (resolve_bug)')
310
419
  args = parser.parse_args()
311
420
 
312
- result, code = fetch_workbench(include_closed=args.include_closed, kind=args.kind)
421
+ # 写操作分支
422
+ if args.action:
423
+ if not args.id:
424
+ result = {'ok': False, 'error': '写操作必须提供 --id'}
425
+ code = 3
426
+ else:
427
+ params = {'left': args.left, 'consumed': args.consumed,
428
+ 'resolution': args.resolution, 'comment': args.comment}
429
+ result, code = perform_action(args.action, args.id, params)
430
+ else:
431
+ result, code = fetch_workbench(include_closed=args.include_closed, kind=args.kind)
313
432
 
314
433
  if args.json or not sys.stdout.isatty():
315
- # 面板/管道场景: 一律 JSON (成功/失败统一结构, 扩展端好解析)
316
434
  indent = 2 if args.pretty else None
317
435
  print(json.dumps(result, ensure_ascii=False, default=str, indent=indent))
318
436
  else:
319
- # 人类可读 (终端直接跑时, 兜底; 正常都用 --json)
320
437
  if result.get('ok'):
321
- d, m = result['data'], result['meta']
322
- print('📋 %s 的禅道工作台 — 任务 %d · 需求 %d · Bug %d (更新于 %s)' % (
323
- d['account'], m['counts']['tasks'], m['counts']['stories'], m['counts']['bugs'],
324
- m['fetched_at']))
438
+ if args.action:
439
+ print(' %s' % result['data'].get('message', '操作成功'))
440
+ else:
441
+ d, m = result['data'], result['meta']
442
+ print('📋 %s 的禅道工作台 — 任务 %d · 需求 %d · Bug %d (更新于 %s)' % (
443
+ d['account'], m['counts']['tasks'], m['counts']['stories'], m['counts']['bugs'],
444
+ m['fetched_at']))
325
445
  else:
326
446
  print('❌ %s' % result.get('error', '未知错误'))
327
447
  sys.exit(code)