ylcwf 0.6.1 → 0.6.2

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/dist/index.js CHANGED
@@ -11062,7 +11062,59 @@ const TASK_TYPE_GROUPS = [
11062
11062
  'backend'
11063
11063
  ];
11064
11064
  const SUPPORTED_SCHEMA_VERSION = 1;
11065
+ const SCOPE_SEPARATOR = '、';
11066
+ const PLAN_SOURCE_FIELDS = [
11067
+ 'files',
11068
+ 'plan',
11069
+ 'selfTest',
11070
+ 'testForms',
11071
+ 'regression',
11072
+ 'notes'
11073
+ ];
11074
+ const RENDERER_BY_PLAN_FIELD = {
11075
+ files: 'code-change-list',
11076
+ selfTest: 'command-result-list',
11077
+ plan: 'list',
11078
+ testForms: 'list',
11079
+ regression: 'list',
11080
+ notes: 'inline'
11081
+ };
11065
11082
  const SCHEMA_FILENAME = 'schema.json';
11083
+ const REQUIRED_REQUIREMENT_KEYS = [
11084
+ 'id',
11085
+ 'title',
11086
+ 'terminal',
11087
+ 'status',
11088
+ 'progress',
11089
+ 'updatedAt'
11090
+ ];
11091
+ const REQUIRED_TASK_KEYS = [
11092
+ 'id',
11093
+ 'requirement',
11094
+ 'name',
11095
+ 'type',
11096
+ 'scope',
11097
+ 'terminal',
11098
+ 'dependencies',
11099
+ 'selfTest',
11100
+ 'acceptance',
11101
+ 'status',
11102
+ 'updatedAt'
11103
+ ];
11104
+ const REQUIRED_ENUMS = [
11105
+ 'requirementStatus',
11106
+ 'taskStatus',
11107
+ 'selfTest',
11108
+ 'acceptance'
11109
+ ];
11110
+ const ALLOWED_FORMATS = [
11111
+ 'percent',
11112
+ 'minute'
11113
+ ];
11114
+ const BUILTIN_ENUM_REFS = [
11115
+ 'taskTypes',
11116
+ 'scopes'
11117
+ ];
11066
11118
  function docSchemaPath(docsRoot) {
11067
11119
  return external_node_path_join(docsRoot, SCHEMA_FILENAME);
11068
11120
  }
@@ -11091,127 +11143,274 @@ function parseDocSchema(raw, docsRoot) {
11091
11143
  if (version > SUPPORTED_SCHEMA_VERSION) fail(docsRoot, `schemaVersion ${version} 高于当前 ylcwf 支持的 ${SUPPORTED_SCHEMA_VERSION},请升级 ylcwf`);
11092
11144
  const requirementTable = requireRecord(data.requirementTable, 'requirementTable', docsRoot);
11093
11145
  const taskTable = requireRecord(data.taskTable, 'taskTable', docsRoot);
11094
- const REQUIRED_REQUIREMENT_KEYS = [
11095
- 'id',
11096
- 'status',
11097
- 'progress',
11098
- 'updatedAt'
11099
- ];
11100
- const REQUIRED_TASK_KEYS = [
11101
- 'id',
11102
- 'requirement',
11103
- 'name',
11104
- 'type',
11105
- 'scope',
11106
- 'terminal',
11107
- 'dependencies',
11108
- 'selfTest',
11109
- 'acceptance',
11110
- 'status',
11111
- 'updatedAt'
11112
- ];
11113
- const readKeys = (table, headers, required, where)=>{
11114
- const raw = table.keys;
11115
- if (void 0 === raw) fail(docsRoot, `${where}.keys 必须声明列语义`);
11116
- const record = requireRecord(raw, `${where}.keys`, docsRoot);
11117
- const result = {};
11118
- for (const semantic of required){
11119
- const value = record[semantic];
11120
- if ('string' != typeof value || 0 === value.trim().length) fail(docsRoot, `${where}.keys 缺少必需语义:${semantic}`);
11121
- if (!headers.includes(value)) fail(docsRoot, `${where}.keys.${semantic} 指向的列「${value}」不在 headers 中`);
11122
- result[semantic] = value;
11123
- }
11124
- for (const [semantic, value] of Object.entries(record))if (void 0 === result[semantic]) {
11125
- if ('string' == typeof value && 0 !== value.trim().length) {
11126
- if (!headers.includes(value)) fail(docsRoot, `${where}.keys.${semantic} 指向的列「${value}」不在 headers 中`);
11127
- result[semantic] = value;
11128
- }
11129
- }
11130
- return result;
11131
- };
11132
- const progressRaw = requirementTable.progressRange;
11133
- let progressRange = [
11134
- 0,
11135
- 100
11136
- ];
11137
- if (void 0 !== progressRaw) {
11138
- if (!Array.isArray(progressRaw) || 2 !== progressRaw.length) fail(docsRoot, 'requirementTable.progressRange 必须是 [最小值, 最大值]');
11139
- const [low, high] = progressRaw;
11140
- if ('number' != typeof low || 'number' != typeof high) fail(docsRoot, 'requirementTable.progressRange 必须是数字');
11141
- progressRange = [
11142
- low,
11143
- high
11144
- ];
11145
- }
11146
- const enumsRaw = requireRecord(data.enums, 'enums', docsRoot);
11147
- const taskTypesRaw = requireRecord(data.taskTypes, 'taskTypes', docsRoot);
11148
- const taskTypes = {};
11149
- for (const group of TASK_TYPE_GROUPS){
11150
- const items = taskTypesRaw[group];
11151
- if (!Array.isArray(items) || 0 === items.length) fail(docsRoot, `taskTypes.${group} 必须是非空数组`);
11152
- taskTypes[group] = items.map((item, index)=>{
11153
- const entry = requireRecord(item, `taskTypes.${group}[${index}]`, docsRoot);
11154
- return {
11155
- name: requireString(entry.name, `taskTypes.${group}[${index}].name`, docsRoot),
11156
- desc: requireString(entry.desc, `taskTypes.${group}[${index}].desc`, docsRoot)
11157
- };
11158
- });
11159
- }
11160
- for (const group of TASK_TYPE_GROUPS){
11161
- const seenInGroup = new Set();
11162
- for (const item of taskTypes[group]){
11163
- if (seenInGroup.has(item.name)) fail(docsRoot, `taskTypes.${group} 内任务类型重复:${item.name}`);
11164
- seenInGroup.add(item.name);
11165
- }
11166
- }
11167
- const rolesRaw = requireRecord(data.roles, 'roles', docsRoot);
11168
- const roles = {};
11169
- for (const [role, value] of Object.entries(rolesRaw)){
11170
- const where = `roles.${role}`;
11171
- const entry = requireRecord(value, where, docsRoot);
11172
- const groups = requireStringArray(entry.taskTypeGroups, `${where}.taskTypeGroups`, docsRoot);
11173
- for (const group of groups)if (!TASK_TYPE_GROUPS.includes(group)) fail(docsRoot, `${where}.taskTypeGroups 引用了未知分组:${group}`);
11174
- roles[role] = {
11175
- scope: requireString(entry.scope, `${where}.scope`, docsRoot),
11176
- scopeRequires: requireStringArray(entry.scopeRequires, `${where}.scopeRequires`, docsRoot),
11177
- detailFields: void 0 === entry.detailFields ? [] : requireStringArray(entry.detailFields, `${where}.detailFields`, docsRoot),
11178
- taskTypeGroups: groups
11179
- };
11180
- }
11181
- if (0 === Object.keys(roles).length) fail(docsRoot, 'roles 不能为空');
11182
- const scopeEnumRaw = taskTable.scopeEnum;
11183
- const scopeEnum = requireStringArray(scopeEnumRaw, 'taskTable.scopeEnum', docsRoot);
11184
- for (const value of scopeEnum){
11185
- const matched = Object.entries(roles).filter(([, config])=>config.scope === value);
11186
- if (1 !== matched.length) fail(docsRoot, `所属端「${value}」需唯一对应一个 roles.* 角色,实际匹配:${matched.length} 个`);
11187
- const owner = matched[0];
11188
- if (void 0 === owner || 0 === owner[1].detailFields.length) fail(docsRoot, `roles.${owner?.[0] ?? '?'} 负责所属端「${value}」,必须声明 detailFields`);
11189
- }
11190
- const requirementHeaders = requireStringArray(requirementTable.headers, 'requirementTable.headers', docsRoot);
11191
- const taskHeaders = requireStringArray(taskTable.headers, 'taskTable.headers', docsRoot);
11146
+ const requirementTableColumns = readColumns(requirementTable, REQUIRED_REQUIREMENT_KEYS, 'requirementTable', docsRoot);
11147
+ const taskTableColumns = readColumns(taskTable, REQUIRED_TASK_KEYS, 'taskTable', docsRoot);
11148
+ const progressRange = readProgressRange(requirementTable, docsRoot);
11149
+ const enumItems = readEnums(data.enums, docsRoot);
11150
+ const taskTypeItems = readTaskTypes(data.taskTypes, docsRoot);
11151
+ const roles = readRoles(data.roles, taskTableColumns.keys, docsRoot);
11152
+ const taskScopeEnum = derivedScopeEnum(roles, docsRoot);
11192
11153
  return {
11193
11154
  version,
11194
11155
  sections: requireStringArray(data.sections, 'sections', docsRoot),
11195
- iterationFields: requireStringArray(data.iterationFields, 'iterationFields', docsRoot),
11196
- requirementHeaders,
11197
- requirementKeys: readKeys(requirementTable, requirementHeaders, REQUIRED_REQUIREMENT_KEYS, 'requirementTable'),
11156
+ iterationFields: readIterationFields(data.iterationFields, docsRoot).map((item)=>item.label),
11157
+ iterationFieldItems: readIterationFields(data.iterationFields, docsRoot),
11158
+ requirementColumns: requirementTableColumns.columns,
11159
+ requirementHeaders: requirementTableColumns.headers,
11160
+ requirementKeys: requirementTableColumns.keys,
11198
11161
  requirementIdPattern: requireString(requirementTable.idPattern, 'requirementTable.idPattern', docsRoot),
11199
11162
  progressRange,
11200
- taskHeaders,
11201
- taskKeys: readKeys(taskTable, taskHeaders, REQUIRED_TASK_KEYS, 'taskTable'),
11163
+ taskColumns: taskTableColumns.columns,
11164
+ taskHeaders: taskTableColumns.headers,
11165
+ taskKeys: taskTableColumns.keys,
11202
11166
  taskIdPattern: requireString(taskTable.idPattern, 'taskTable.idPattern', docsRoot),
11203
- taskScopeEnum: requireStringArray(taskTable.scopeEnum, 'taskTable.scopeEnum', docsRoot),
11167
+ taskScopeEnum,
11204
11168
  enums: {
11205
- requirementStatus: requireStringArray(enumsRaw.requirementStatus, 'enums.requirementStatus', docsRoot),
11206
- taskStatus: requireStringArray(enumsRaw.taskStatus, 'enums.taskStatus', docsRoot),
11207
- selfTest: requireStringArray(enumsRaw.selfTest, 'enums.selfTest', docsRoot),
11208
- acceptance: requireStringArray(enumsRaw.acceptance, 'enums.acceptance', docsRoot)
11169
+ requirementStatus: enumValues(enumItems, 'requirementStatus', docsRoot),
11170
+ taskStatus: enumValues(enumItems, 'taskStatus', docsRoot),
11171
+ selfTest: enumValues(enumItems, 'selfTest', docsRoot),
11172
+ acceptance: enumValues(enumItems, 'acceptance', docsRoot)
11209
11173
  },
11210
- taskTypes,
11174
+ enumItems,
11175
+ taskTypes: {
11176
+ frontend: taskTypeItems.filter((item)=>item.sides.includes('frontend')),
11177
+ backend: taskTypeItems.filter((item)=>item.sides.includes('backend'))
11178
+ },
11179
+ taskTypeItems,
11211
11180
  updatedAtFormat: requireString(data.updatedAtFormat, 'updatedAtFormat', docsRoot),
11212
11181
  roles
11213
11182
  };
11214
11183
  }
11184
+ function readColumns(table, requiredKeys, where, docsRoot) {
11185
+ const raw = table.columns;
11186
+ if (!Array.isArray(raw) || 0 === raw.length) fail(docsRoot, `${where}.columns 必须是非空数组`);
11187
+ const columns = [];
11188
+ const seenKeys = new Set();
11189
+ const seenLabels = new Set();
11190
+ raw.forEach((item, index)=>{
11191
+ const at = `${where}.columns[${index}]`;
11192
+ const entry = requireRecord(item, at, docsRoot);
11193
+ const key = requireString(entry.key, `${at}.key`, docsRoot);
11194
+ const label = requireString(entry.label, `${at}.label`, docsRoot);
11195
+ if (seenKeys.has(key)) fail(docsRoot, `${where}.columns 内 key 重复:${key}`);
11196
+ if (seenLabels.has(label)) fail(docsRoot, `${where}.columns 内 label 重复:${label}`);
11197
+ seenKeys.add(key);
11198
+ seenLabels.add(label);
11199
+ if (void 0 !== entry.required && 'boolean' != typeof entry.required) fail(docsRoot, `${at}.required 必须是布尔值`);
11200
+ if (void 0 !== entry.enum) {
11201
+ const ref = requireString(entry.enum, `${at}.enum`, docsRoot);
11202
+ const available = [
11203
+ ...REQUIRED_ENUMS,
11204
+ ...BUILTIN_ENUM_REFS
11205
+ ];
11206
+ if (!available.includes(ref)) fail(docsRoot, `${at}.enum 引用了未知枚举:${ref}(可选:${available.join('、')})`);
11207
+ }
11208
+ if (void 0 !== entry.format) {
11209
+ const format = requireString(entry.format, `${at}.format`, docsRoot);
11210
+ if (!ALLOWED_FORMATS.includes(format)) fail(docsRoot, `${at}.format 必须是 ${ALLOWED_FORMATS.join(' / ')}`);
11211
+ }
11212
+ columns.push({
11213
+ key,
11214
+ label,
11215
+ required: true === entry.required,
11216
+ enum: void 0 === entry.enum ? void 0 : String(entry.enum),
11217
+ format: void 0 === entry.format ? void 0 : String(entry.format),
11218
+ ui: readColumnUi(entry.ui, `${at}.ui`, docsRoot)
11219
+ });
11220
+ });
11221
+ const missing = requiredKeys.filter((key)=>!seenKeys.has(key));
11222
+ if (missing.length > 0) fail(docsRoot, `${where}.columns 缺少工具依赖的列语义:${missing.join('、')}(新增列可自由命名,但这几项语义必须保留)`);
11223
+ return {
11224
+ columns,
11225
+ headers: columns.map((column)=>column.label),
11226
+ keys: Object.fromEntries(columns.map((column)=>[
11227
+ column.key,
11228
+ column.label
11229
+ ]))
11230
+ };
11231
+ }
11232
+ function readColumnUi(value, where, docsRoot) {
11233
+ if (void 0 === value) return {};
11234
+ const entry = requireRecord(value, where, docsRoot);
11235
+ const ui = {};
11236
+ for (const [key, raw] of Object.entries(entry))if ('board' === key || 'editable' === key) {
11237
+ if ('boolean' != typeof raw) fail(docsRoot, `${where}.${key} 必须是布尔值`);
11238
+ ui[key] = raw;
11239
+ } else if ('width' === key) {
11240
+ if ('number' != typeof raw || !Number.isInteger(raw) || raw <= 0) fail(docsRoot, `${where}.width 必须是正整数`);
11241
+ ui.width = raw;
11242
+ } else fail(docsRoot, `${where} 含未知属性:${key}(可选:board / width / editable)`);
11243
+ return ui;
11244
+ }
11245
+ function readProgressRange(table, docsRoot) {
11246
+ const raw = table.progressRange;
11247
+ if (void 0 === raw) return [
11248
+ 0,
11249
+ 100
11250
+ ];
11251
+ if (!Array.isArray(raw) || 2 !== raw.length) fail(docsRoot, 'requirementTable.progressRange 必须是 [最小值, 最大值]');
11252
+ const [low, high] = raw;
11253
+ if ('number' != typeof low || 'number' != typeof high) fail(docsRoot, 'requirementTable.progressRange 必须是数字');
11254
+ return [
11255
+ low,
11256
+ high
11257
+ ];
11258
+ }
11259
+ function readIterationFields(value, docsRoot) {
11260
+ if (!Array.isArray(value) || 0 === value.length) fail(docsRoot, 'iterationFields 必须是非空数组');
11261
+ const seenKeys = new Set();
11262
+ const seenLabels = new Set();
11263
+ return value.map((item, index)=>{
11264
+ const where = `iterationFields[${index}]`;
11265
+ const entry = requireRecord(item, where, docsRoot);
11266
+ const key = requireString(entry.key, `${where}.key`, docsRoot);
11267
+ const label = requireString(entry.label, `${where}.label`, docsRoot);
11268
+ if (seenKeys.has(key)) fail(docsRoot, `iterationFields 内 key 重复:${key}`);
11269
+ if (seenLabels.has(label)) fail(docsRoot, `iterationFields 内 label 重复:${label}`);
11270
+ seenKeys.add(key);
11271
+ seenLabels.add(label);
11272
+ if (void 0 !== entry.required && 'boolean' != typeof entry.required) fail(docsRoot, `${where}.required 必须是布尔值`);
11273
+ return {
11274
+ key,
11275
+ label,
11276
+ required: false !== entry.required,
11277
+ placeholder: void 0 === entry.placeholder ? void 0 : requireString(entry.placeholder, `${where}.placeholder`, docsRoot)
11278
+ };
11279
+ });
11280
+ }
11281
+ function readEnums(value, docsRoot) {
11282
+ const record = requireRecord(value, 'enums', docsRoot);
11283
+ return REQUIRED_ENUMS.map((key)=>{
11284
+ const entry = requireRecord(record[key], `enums.${key}`, docsRoot);
11285
+ const values = requireStringArray(entry.values, `enums.${key}.values`, docsRoot);
11286
+ return {
11287
+ key,
11288
+ label: requireString(entry.label, `enums.${key}.label`, docsRoot),
11289
+ values,
11290
+ desc: requireString(entry.desc, `enums.${key}.desc`, docsRoot),
11291
+ display: void 0 === entry.display ? void 0 : requireString(entry.display, `enums.${key}.display`, docsRoot)
11292
+ };
11293
+ });
11294
+ }
11295
+ function enumValues(items, key, docsRoot) {
11296
+ const found = items.find((item)=>item.key === key);
11297
+ if (void 0 === found) fail(docsRoot, `enums 缺少 ${key}`);
11298
+ return found.values;
11299
+ }
11300
+ function readTaskTypes(value, docsRoot) {
11301
+ if (!Array.isArray(value) || 0 === value.length) fail(docsRoot, 'taskTypes 必须是非空数组');
11302
+ const seen = new Set();
11303
+ return value.map((item, index)=>{
11304
+ const where = `taskTypes[${index}]`;
11305
+ const entry = requireRecord(item, where, docsRoot);
11306
+ const name = requireString(entry.name, `${where}.name`, docsRoot);
11307
+ if (seen.has(name)) fail(docsRoot, `taskTypes 内任务类型重复:${name}`);
11308
+ seen.add(name);
11309
+ const sides = requireStringArray(entry.sides, `${where}.sides`, docsRoot);
11310
+ for (const side of sides)if (!TASK_TYPE_GROUPS.includes(side)) fail(docsRoot, `${where}.sides 含未知分组:${side}(可选:${TASK_TYPE_GROUPS.join('、')})`);
11311
+ return {
11312
+ name,
11313
+ desc: requireString(entry.desc, `${where}.desc`, docsRoot),
11314
+ sides: sides
11315
+ };
11316
+ });
11317
+ }
11318
+ function roleOfScope(schema, scope) {
11319
+ for (const [role, config] of Object.entries(schema.roles))if (config.scope === scope) return role;
11320
+ return null;
11321
+ }
11322
+ function scopeRequiresOf(scope) {
11323
+ return scope.split(SCOPE_SEPARATOR).map((part)=>part.trim()).filter((part)=>part.length > 0);
11324
+ }
11325
+ function scopeOwners(roles) {
11326
+ const owners = {};
11327
+ for (const [role, config] of Object.entries(roles))if (0 !== config.detailFields.length) for (const scope of scopeRequiresOf(config.scope))owners[scope] = role;
11328
+ return owners;
11329
+ }
11330
+ function readRoles(value, taskKeys, docsRoot) {
11331
+ const record = requireRecord(value, 'roles', docsRoot);
11332
+ if (0 === Object.keys(record).length) fail(docsRoot, 'roles 不能为空');
11333
+ const partial = {};
11334
+ for (const [role, raw] of Object.entries(record)){
11335
+ const where = `roles.${role}`;
11336
+ const entry = requireRecord(raw, where, docsRoot);
11337
+ const scope = requireString(entry.scope, `${where}.scope`, docsRoot);
11338
+ const detailFields = [];
11339
+ const detailFieldItems = [];
11340
+ const mirrorFields = {};
11341
+ if (void 0 !== entry.detailFields) {
11342
+ if (!Array.isArray(entry.detailFields) || 0 === entry.detailFields.length) fail(docsRoot, `${where}.detailFields 必须是非空数组`);
11343
+ entry.detailFields.forEach((item, index)=>{
11344
+ const at = `${where}.detailFields[${index}]`;
11345
+ const field = requireRecord(item, at, docsRoot);
11346
+ const name = requireString(field.name, `${at}.name`, docsRoot);
11347
+ if (detailFields.includes(name)) fail(docsRoot, `${where}.detailFields 内字段重复:${name}`);
11348
+ detailFields.push(name);
11349
+ const decl = {
11350
+ name
11351
+ };
11352
+ const hasSource = void 0 !== field.source;
11353
+ const hasFrom = void 0 !== field.from;
11354
+ if (hasSource && hasFrom) fail(docsRoot, `${at}:source(来自任务表列)与 from(来自 plan 字段)不能同时声明`);
11355
+ if (hasSource) {
11356
+ const source = requireString(field.source, `${at}.source`, docsRoot);
11357
+ if (!source.startsWith('task.')) fail(docsRoot, `${at}.source 必须形如 task.<列语义>`);
11358
+ const semantic = source.slice(5);
11359
+ if (void 0 === taskKeys[semantic]) fail(docsRoot, `${at}.source 指向的任务列语义不存在:${semantic}`);
11360
+ const match = void 0 === field.match ? 'exact' : String(field.match);
11361
+ if ('exact' !== match && 'contains' !== match) fail(docsRoot, `${at}.match 必须是 exact / contains`);
11362
+ decl.source = semantic;
11363
+ decl.match = match;
11364
+ mirrorFields[name] = {
11365
+ source: semantic,
11366
+ match
11367
+ };
11368
+ }
11369
+ if (hasFrom) {
11370
+ const from = requireString(field.from, `${at}.from`, docsRoot);
11371
+ const planFields = PLAN_SOURCE_FIELDS;
11372
+ if (!planFields.includes(from)) fail(docsRoot, `${at}.from 必须是 ${planFields.join(' / ')} 之一`);
11373
+ const renderer = RENDERER_BY_PLAN_FIELD[from];
11374
+ if (void 0 !== field.as) {
11375
+ const declared = requireString(field.as, `${at}.as`, docsRoot);
11376
+ if (declared !== renderer) fail(docsRoot, `${at}.as 与 from 不匹配:from=${from} 只能是 ${renderer}`);
11377
+ }
11378
+ decl.from = from;
11379
+ decl.as = renderer;
11380
+ }
11381
+ if (void 0 !== field.placeholder) decl.placeholder = Array.isArray(field.placeholder) ? requireStringArray(field.placeholder, `${at}.placeholder`, docsRoot) : requireString(field.placeholder, `${at}.placeholder`, docsRoot);
11382
+ detailFieldItems.push(decl);
11383
+ });
11384
+ }
11385
+ partial[role] = {
11386
+ scope,
11387
+ scopeRequires: scopeRequiresOf(scope),
11388
+ detailFields,
11389
+ detailFieldItems,
11390
+ mirrorFields,
11391
+ taskTypeGroups: []
11392
+ };
11393
+ }
11394
+ for (const [role, config] of Object.entries(partial)){
11395
+ const sides = new Set([
11396
+ role
11397
+ ]);
11398
+ for (const scope of config.scopeRequires){
11399
+ const owner = scopeOwners(partial)[scope];
11400
+ if (void 0 !== owner) sides.add(owner);
11401
+ }
11402
+ config.taskTypeGroups = TASK_TYPE_GROUPS.filter((group)=>sides.has(group));
11403
+ }
11404
+ return partial;
11405
+ }
11406
+ function derivedScopeEnum(roles, docsRoot) {
11407
+ const values = [];
11408
+ for (const config of Object.values(roles))if (0 !== config.detailFields.length) {
11409
+ for (const scope of scopeRequiresOf(config.scope))if (!values.includes(scope)) values.push(scope);
11410
+ }
11411
+ if (0 === values.length) fail(docsRoot, '未从 roles.*.scope 派生出任何「所属端」');
11412
+ return values;
11413
+ }
11215
11414
  function loadDocSchema(docsRoot) {
11216
11415
  const target = docSchemaPath(docsRoot);
11217
11416
  let text;
@@ -11231,26 +11430,33 @@ function loadDocSchema(docsRoot) {
11231
11430
  function taskTypesOf(schema, role) {
11232
11431
  const config = schema.roles[role];
11233
11432
  if (void 0 === config) return [];
11234
- const names = [];
11235
- for (const group of config.taskTypeGroups)for (const item of schema.taskTypes[group])if (!names.includes(item.name)) names.push(item.name);
11236
- return names;
11237
- }
11238
- function roleOfScope(schema, scope) {
11239
- for (const [role, config] of Object.entries(schema.roles))if (config.scope === scope) return role;
11240
- return null;
11433
+ const sides = new Set([
11434
+ role,
11435
+ ...config.scopeRequires.map((scope)=>scopeOwners(schema.roles)[scope] ?? '')
11436
+ ]);
11437
+ return schema.taskTypeItems.filter((item)=>item.sides.some((side)=>sides.has(side))).map((item)=>item.name);
11241
11438
  }
11242
11439
  function detailFieldsOfScope(schema, scope) {
11243
11440
  const role = roleOfScope(schema, scope);
11244
11441
  if (null === role) return [];
11245
11442
  return schema.roles[role]?.detailFields ?? [];
11246
11443
  }
11444
+ function detailFieldDeclsOfScope(schema, scope) {
11445
+ const role = roleOfScope(schema, scope);
11446
+ if (null === role) return [];
11447
+ return schema.roles[role]?.detailFieldItems ?? [];
11448
+ }
11449
+ function mirrorFieldsOfScope(schema, scope) {
11450
+ const role = roleOfScope(schema, scope);
11451
+ if (null === role) return {};
11452
+ return schema.roles[role]?.mirrorFields ?? {};
11453
+ }
11247
11454
  function sideOfTypeName(schema, typeName) {
11248
- const inFront = schema.taskTypes.frontend.some((item)=>item.name === typeName);
11249
- const inBack = schema.taskTypes.backend.some((item)=>item.name === typeName);
11250
- if (inFront && inBack) return 'both';
11251
- if (inFront) return 'frontend';
11252
- if (inBack) return 'backend';
11253
- return null;
11455
+ const found = schema.taskTypeItems.find((item)=>item.name === typeName);
11456
+ if (void 0 === found) return null;
11457
+ const sides = TASK_TYPE_GROUPS.filter((group)=>found.sides.includes(group));
11458
+ if (sides.length > 1) return 'both';
11459
+ return sides[0] ?? null;
11254
11460
  }
11255
11461
  function buildRepoSideIndex(terminals) {
11256
11462
  const byName = new Map();
@@ -11381,15 +11587,13 @@ function parseDocPlan(raw, schema, role) {
11381
11587
  if (seenRequirements.has(requirement.code)) docplan_fail(`需求编号重复:${requirement.code}`);
11382
11588
  seenRequirements.add(requirement.code);
11383
11589
  }
11384
- const allowedTypes = new Set(taskTypesOf(schema, role));
11385
11590
  const scopeEnum = schema.taskScopeEnum;
11591
+ const ownedScopes = new Set(schema.roles[role]?.scopeRequires ?? scopeEnum);
11386
11592
  const tasks = raw.tasks.map((item, index)=>{
11387
11593
  const where = `tasks[${index}]`;
11388
11594
  if (!docplan_isRecord(item)) docplan_fail(`${where} 必须是对象`);
11389
11595
  const type = docplan_requireString(item.type, `${where}.type`);
11390
- if (allowedTypes.size > 0 && !allowedTypes.has(type)) docplan_fail(`${where}.type 非法:${type}(角色 ${role} 允许:${[
11391
- ...allowedTypes
11392
- ].join('、')})`);
11596
+ if (!schema.taskTypeItems.some((entry)=>entry.name === type)) docplan_fail(`${where}.type 非法:${type}(不在 schema 的任务类型定义中;当前角色可用:${taskTypesOf(schema, role).join('、')})`);
11393
11597
  const filesRaw = item.files;
11394
11598
  let files = [];
11395
11599
  if (null != filesRaw) {
@@ -11416,13 +11620,24 @@ function parseDocPlan(raw, schema, role) {
11416
11620
  };
11417
11621
  });
11418
11622
  }
11623
+ const declaredScope = optionalString(item.scope, `${where}.scope`)?.trim();
11624
+ let scope;
11625
+ if (void 0 !== declaredScope && declaredScope.length > 0) {
11626
+ if (!scopeEnum.includes(declaredScope)) docplan_fail(`${where}.scope 非法:${declaredScope}(允许值:${scopeEnum.join('、')})`);
11627
+ scope = declaredScope;
11628
+ } else {
11629
+ const side = sideOfTypeName(schema, type);
11630
+ const inferred = 'frontend' === side ? '前端' : 'backend' === side ? '后端' : void 0;
11631
+ if (void 0 === inferred) docplan_fail(`${where}.scope 必须显式指定:类型「${type}」两端都可用,无法自动判断(允许值:${scopeEnum.join('、')})`);
11632
+ scope = inferred;
11633
+ }
11419
11634
  let detailFields;
11420
11635
  if (void 0 !== item.detailFields && null !== item.detailFields) {
11421
11636
  if (!docplan_isRecord(item.detailFields)) docplan_fail(`${where}.detailFields 必须是对象`);
11422
- const allowed = new Set(schema.roles[role]?.detailFields ?? []);
11637
+ const allowed = new Set(detailFieldsOfScope(schema, scope));
11423
11638
  detailFields = {};
11424
11639
  for (const [key, value] of Object.entries(item.detailFields)){
11425
- if (allowed.size > 0 && !allowed.has(key)) docplan_fail(`${where}.detailFields 含未知字段「${key}」(角色 ${role} 允许:${[
11640
+ if (allowed.size > 0 && !allowed.has(key)) docplan_fail(`${where}.detailFields 含未知字段「${key}」(「${scope}」端允许:${[
11426
11641
  ...allowed
11427
11642
  ].join('、')};新增字段请先改 schema.json 与模板)`);
11428
11643
  if ('string' == typeof value) {
@@ -11436,20 +11651,17 @@ function parseDocPlan(raw, schema, role) {
11436
11651
  docplan_fail(`${where}.detailFields.${key} 必须是字符串或字符串数组`);
11437
11652
  }
11438
11653
  }
11439
- const declaredScope = optionalString(item.scope, `${where}.scope`)?.trim();
11440
- let scope;
11441
- if (void 0 !== declaredScope && declaredScope.length > 0) {
11442
- if (!scopeEnum.includes(declaredScope)) docplan_fail(`${where}.scope 非法:${declaredScope}(允许值:${scopeEnum.join('、')})`);
11443
- scope = declaredScope;
11444
- } else {
11445
- const side = sideOfTypeName(schema, type);
11446
- const inferred = 'frontend' === side ? '前端' : 'backend' === side ? '后端' : void 0;
11447
- if (void 0 === inferred) docplan_fail(`${where}.scope 必须显式指定:类型「${type}」两端都可用,无法自动判断(允许值:${scopeEnum.join('、')})`);
11448
- scope = inferred;
11449
- }
11450
11654
  const typeSide = sideOfTypeName(schema, type);
11451
11655
  const expectedScope = 'frontend' === typeSide ? '前端' : 'backend' === typeSide ? '后端' : void 0;
11452
11656
  if (void 0 !== expectedScope && scope !== expectedScope) docplan_fail(`${where}.type「${type}」属于${expectedScope},但 scope 填的是「${scope}」`);
11657
+ if (!ownedScopes.has(scope)) docplan_fail(`${where}:任务属于「${scope}」,但当前角色「${role}」的负责范围是${[
11658
+ ...ownedScopes
11659
+ ].join('、') || '(空)'}。\n ${scope}任务请交给负责该端的同事,或把 profile.role 改为 fullstack 后重试。`);
11660
+ const scopeRole = roleOfScope(schema, scope);
11661
+ const allowedTypes = new Set(null === scopeRole ? [] : taskTypesOf(schema, scopeRole));
11662
+ if (allowedTypes.size > 0 && !allowedTypes.has(type)) docplan_fail(`${where}.type 非法:${type}(「${scope}」端允许:${[
11663
+ ...allowedTypes
11664
+ ].join('、')})`);
11453
11665
  return {
11454
11666
  requirement: normalizeCode(docplan_requireString(item.requirement, `${where}.requirement`)),
11455
11667
  name: docplan_requireString(item.name, `${where}.name`),
@@ -11592,65 +11804,88 @@ function refreshRequirementRows(options) {
11592
11804
  changes
11593
11805
  };
11594
11806
  }
11807
+ const DETAIL_RENDERERS = {
11808
+ inline: (value)=>{
11809
+ if ('string' == typeof value) return {
11810
+ items: [
11811
+ value
11812
+ ],
11813
+ list: false
11814
+ };
11815
+ if (Array.isArray(value) && value.length > 0) return {
11816
+ items: value.map((item)=>String(item)),
11817
+ list: false
11818
+ };
11819
+ },
11820
+ list: (value)=>{
11821
+ if (!Array.isArray(value) || 0 === value.length) return;
11822
+ return {
11823
+ items: value.map((item)=>String(item)),
11824
+ list: true
11825
+ };
11826
+ },
11827
+ 'code-change-list': (value)=>{
11828
+ if (!Array.isArray(value) || 0 === value.length) return;
11829
+ const items = value.map((entry)=>entry).filter((entry)=>'string' == typeof entry.path && entry.path.length > 0).map((entry)=>`\`${String(entry.path)}\`(${String(entry.change ?? '')})`);
11830
+ return 0 === items.length ? void 0 : {
11831
+ items,
11832
+ list: true
11833
+ };
11834
+ },
11835
+ 'command-result-list': (value)=>{
11836
+ if (!Array.isArray(value) || 0 === value.length) return;
11837
+ const items = value.map((entry)=>entry).filter((entry)=>'string' == typeof entry.cmd && entry.cmd.length > 0).map((entry)=>`\`${String(entry.cmd)}\`:${String(entry.result ?? '')}`);
11838
+ return 0 === items.length ? void 0 : {
11839
+ items,
11840
+ list: true
11841
+ };
11842
+ }
11843
+ };
11595
11844
  function renderDetail(options) {
11596
11845
  const { taskId, task, requirement } = options;
11597
11846
  const builtin = new Map();
11598
- builtin.set('任务状态', {
11599
- items: [
11600
- PENDING_STATUS
11601
- ],
11602
- list: false
11603
- });
11604
- builtin.set('自测状态', {
11605
- items: [
11606
- PENDING_SELF_TEST
11607
- ],
11608
- list: false
11609
- });
11610
- builtin.set('人工验收', {
11611
- items: [
11612
- PENDING_ACCEPTANCE
11613
- ],
11614
- list: false
11615
- });
11616
- builtin.set('所属需求', {
11617
- items: [
11618
- `${requirement.code} ${requirement.name}`
11619
- ],
11620
- list: false
11621
- });
11622
- builtin.set('任务类型', {
11623
- items: [
11624
- task.type
11625
- ],
11626
- list: false
11627
- });
11628
- builtin.set('核心文件清单', {
11629
- items: (task.files ?? []).map((file)=>`\`${file.path}\`(${file.change})`),
11630
- list: true
11631
- });
11632
- builtin.set('详细实现方案', {
11633
- items: task.plan ?? [],
11634
- list: true
11635
- });
11636
- builtin.set('AI 单测与自检证据', {
11637
- items: (task.selfTest ?? []).map((item)=>`\`${item.cmd}\`:${item.result}`),
11638
- list: true
11639
- });
11640
- builtin.set('自测形式', {
11641
- items: task.testForms ?? [],
11642
- list: true
11643
- });
11644
- builtin.set('QA 历史功能影响范围 (Regression Scope)', {
11645
- items: task.regression ?? [],
11646
- list: true
11647
- });
11648
- builtin.set('待联调/遗留事项', {
11649
- items: [
11650
- task.notes ?? '无'
11651
- ],
11652
- list: false
11653
- });
11847
+ const mirrorInitial = (source)=>{
11848
+ if ('status' === source) return {
11849
+ items: [
11850
+ PENDING_STATUS
11851
+ ],
11852
+ list: false
11853
+ };
11854
+ if ('selfTest' === source) return {
11855
+ items: [
11856
+ PENDING_SELF_TEST
11857
+ ],
11858
+ list: false
11859
+ };
11860
+ if ('acceptance' === source) return {
11861
+ items: [
11862
+ PENDING_ACCEPTANCE
11863
+ ],
11864
+ list: false
11865
+ };
11866
+ if ('requirement' === source) return {
11867
+ items: [
11868
+ `${requirement.code} ${requirement.name}`
11869
+ ],
11870
+ list: false
11871
+ };
11872
+ if ('type' === source) return {
11873
+ items: [
11874
+ task.type
11875
+ ],
11876
+ list: false
11877
+ };
11878
+ };
11879
+ for (const [field, mirror] of Object.entries(mirrorFieldsOfScope(options.schema, task.scope))){
11880
+ const value = mirrorInitial(mirror.source);
11881
+ if (void 0 !== value) builtin.set(field, value);
11882
+ }
11883
+ for (const decl of detailFieldDeclsOfScope(options.schema, task.scope)){
11884
+ if (void 0 === decl.from) continue;
11885
+ const renderer = DETAIL_RENDERERS[decl.as ?? 'inline'];
11886
+ const value = renderer(task[decl.from]);
11887
+ if (void 0 !== value) builtin.set(decl.name, value);
11888
+ }
11654
11889
  const lines = [
11655
11890
  `### [${taskId}] ${task.name}`,
11656
11891
  ''
@@ -11664,7 +11899,11 @@ function renderDetail(options) {
11664
11899
  list: Array.isArray(custom)
11665
11900
  });
11666
11901
  if (void 0 === value) {
11667
- lines.push(`- **${field}**:<待补充>`);
11902
+ const decl = detailFieldDeclsOfScope(options.schema, task.scope).find((item)=>item.name === field);
11903
+ if (decl?.as !== void 0 && 'inline' !== decl.as) {
11904
+ lines.push(`- **${field}**:`);
11905
+ lines.push(' - <待补充>');
11906
+ } else lines.push(`- **${field}**:<待补充>`);
11668
11907
  continue;
11669
11908
  }
11670
11909
  if (!value.list && 1 === value.items.length) {
@@ -11743,7 +11982,7 @@ function buildSkeleton(options) {
11743
11982
  lines.push(docrender_separator(2));
11744
11983
  for (const field of schema.iterationFields){
11745
11984
  const provided = plan.iteration[field];
11746
- const fallback = '负责人' === field ? developer : '负责范围' === field ? schema.roles[role]?.scope ?? '' : '';
11985
+ const fallback = '负责人' === field ? developer : '负责范围' === field ? role : '';
11747
11986
  lines.push(joinRow([
11748
11987
  field,
11749
11988
  provided ?? fallback
@@ -12246,6 +12485,19 @@ function isGitAvailable() {
12246
12485
  return false;
12247
12486
  }
12248
12487
  }
12488
+ function docViewMeta(schema) {
12489
+ return {
12490
+ requirementColumns: schema.requirementColumns,
12491
+ taskColumns: schema.taskColumns,
12492
+ enums: {
12493
+ ...schema.enums
12494
+ },
12495
+ enumLabels: Object.fromEntries(schema.enumItems.map((item)=>[
12496
+ item.key,
12497
+ item.display ?? item.values.join("、")
12498
+ ]))
12499
+ };
12500
+ }
12249
12501
  function normalizeSelfTest(value) {
12250
12502
  const text = value.trim();
12251
12503
  if (0 === text.length) return "未执行";
@@ -12288,9 +12540,10 @@ function joinWithin(root, ...segments) {
12288
12540
  }
12289
12541
  function inferRole(markdown) {
12290
12542
  const match = /\|\s*负责范围\s*\|\s*([^|]*)\|/.exec(markdown);
12291
- const scope = match?.[1]?.trim() ?? "";
12292
- const hasFrontend = scope.includes("前端");
12293
- const hasBackend = scope.includes("后端");
12543
+ const scope = (match?.[1] ?? "").trim().toLowerCase();
12544
+ if (scope.includes("fullstack")) return "fullstack";
12545
+ const hasFrontend = scope.includes("frontend") || scope.includes("前端");
12546
+ const hasBackend = scope.includes("backend") || scope.includes("后端");
12294
12547
  if (hasFrontend && hasBackend) return "fullstack";
12295
12548
  if (hasBackend) return "backend";
12296
12549
  return "frontend";
@@ -12447,7 +12700,7 @@ function coerceInfo(value) {
12447
12700
  for (const [key, item] of Object.entries(value))if ("string" == typeof item) info[key] = item;
12448
12701
  return info;
12449
12702
  }
12450
- function coercePayload(raw) {
12703
+ function coercePayload(raw, schema) {
12451
12704
  if (!utils_isRecord(raw)) return null;
12452
12705
  const stats = utils_isRecord(raw["stats"]) ? raw["stats"] : {};
12453
12706
  const requirements = Array.isArray(raw["requirements"]) ? raw["requirements"].map(coerceRequirement).filter((item)=>null !== item) : [];
@@ -12457,6 +12710,7 @@ function coercePayload(raw) {
12457
12710
  const asNumber = (value, fallback)=>"number" == typeof value ? value : fallback;
12458
12711
  return {
12459
12712
  valid: true === raw["valid"],
12713
+ view: docViewMeta(schema),
12460
12714
  iterationInfo: coerceInfo(raw["iterationInfo"]),
12461
12715
  stats: {
12462
12716
  requirements: asNumber(stats["requirements"], requirements.length),
@@ -12523,7 +12777,7 @@ function runValidator(input) {
12523
12777
  "pipe"
12524
12778
  ]
12525
12779
  });
12526
- const parsed = coercePayload(JSON.parse(stdout));
12780
+ const parsed = coercePayload(JSON.parse(stdout), input.schema);
12527
12781
  if (null !== parsed) return {
12528
12782
  payload: parsed,
12529
12783
  error: null
@@ -12532,7 +12786,7 @@ function runValidator(input) {
12532
12786
  const failure = error;
12533
12787
  const stdout = failure.stdout;
12534
12788
  if ("string" == typeof stdout && stdout.trim().length > 0) try {
12535
- const parsed = coercePayload(JSON.parse(stdout));
12789
+ const parsed = coercePayload(JSON.parse(stdout), input.schema);
12536
12790
  if (null !== parsed) return {
12537
12791
  payload: parsed,
12538
12792
  error: null
@@ -12665,6 +12919,7 @@ function parseMarkdownDoc(markdown, schema) {
12665
12919
  }
12666
12920
  return {
12667
12921
  valid: false,
12922
+ view: docViewMeta(schema),
12668
12923
  iterationInfo,
12669
12924
  stats: {
12670
12925
  requirements: requirements.length,
@@ -12714,6 +12969,7 @@ function readIterationDoc(layout, iteration, developer, source = "local", preset
12714
12969
  const exported = exportRemoteDoc(docsRoot, ref, resolved.year, safeIteration, safeDeveloper, layout.iterationsRoot);
12715
12970
  const roleInferred = inferRole(exported.markdown);
12716
12971
  const scripted = runValidator({
12972
+ schema: loadDocSchema(exported.dir),
12717
12973
  docsRoot: exported.dir,
12718
12974
  scriptPath: exported.scriptPath,
12719
12975
  iteration: safeIteration,
@@ -12744,6 +13000,7 @@ function readIterationDoc(layout, iteration, developer, source = "local", preset
12744
13000
  const markdown = readMarkdown(file);
12745
13001
  const roleInferred = inferRole(markdown);
12746
13002
  const scripted = runValidator({
13003
+ schema: loadDocSchema(docsRoot),
12747
13004
  docsRoot,
12748
13005
  scriptPath: external_node_path_join(docsRoot, "scripts", "validate_task_doc.py"),
12749
13006
  iteration: resolved.relPath,
@@ -13358,11 +13615,16 @@ function commit(context, lines, changes, message, iteration, developer, action,
13358
13615
  function normalizeDetailField(name) {
13359
13616
  return name.replace(/[((][^))]*[))]/g, '').replace(/\s+/g, '').trim();
13360
13617
  }
13361
- const DETAIL_FIELDS_LOCKED = new Set([
13362
- '任务状态',
13363
- '人工验收',
13364
- '自测状态'
13618
+ const LOCKED_MIRROR_SOURCES = new Set([
13619
+ 'status',
13620
+ 'selfTest',
13621
+ 'acceptance'
13365
13622
  ]);
13623
+ function lockedDetailFields(schema, scope) {
13624
+ const locked = new Set();
13625
+ for (const [field, mirror] of Object.entries(mirrorFieldsOfScope(schema, scope)))if (LOCKED_MIRROR_SOURCES.has(mirror.source)) locked.add(field);
13626
+ return locked;
13627
+ }
13366
13628
  function readDetailField(lines, taskId, field) {
13367
13629
  const headingIndex = lines.findIndex((line)=>line.trim().startsWith(`### [${taskId}]`));
13368
13630
  if (headingIndex < 0) return null;
@@ -13417,7 +13679,7 @@ function applyTaskDetail(options) {
13417
13679
  for (const update of options.updates){
13418
13680
  const fieldName = allowed.get(normalizeDetailField(update.field));
13419
13681
  if (void 0 === fieldName) throw new errors_CliError(`字段「${update.field}」不可编辑(可改:${allowedFields.join(' / ')})`, errors_EXIT.USAGE);
13420
- if (DETAIL_FIELDS_LOCKED.has(fieldName)) throw new errors_CliError(`字段「${fieldName}」由状态流转命令维护,请使用 task start/submit/accept/reject 或 task selftest`, errors_EXIT.USAGE);
13682
+ if (lockedDetailFields(schema, scope).has(fieldName)) throw new errors_CliError(`字段「${fieldName}」由状态流转命令维护,请使用 task start/submit/accept/reject 或 task selftest`, errors_EXIT.USAGE);
13421
13683
  const parsed = readDetailField(lines, options.taskId, fieldName);
13422
13684
  if (null === parsed) throw new errors_CliError(`任务 ${options.taskId} 的详情区块缺少字段「${fieldName}」`, errors_EXIT.INVALID);
13423
13685
  const incoming = update.value.split('\n').map((item)=>item.trim()).filter((item)=>item.length > 0);
@@ -13776,22 +14038,6 @@ function availableActions(options) {
13776
14038
  }
13777
14039
  return result;
13778
14040
  }
13779
- const SYNC_DIRS = new Set([
13780
- "scripts",
13781
- 'skills',
13782
- 'docs',
13783
- '_prd',
13784
- 'node_modules'
13785
- ]);
13786
- function doc_migrate_listIterations(docsRoot) {
13787
- return external_node_fs_readdirSync(docsRoot).filter((name)=>!name.startsWith('.') && !SYNC_DIRS.has(name)).filter((name)=>{
13788
- try {
13789
- return statSync(external_node_path_join(docsRoot, name)).isDirectory();
13790
- } catch {
13791
- return false;
13792
- }
13793
- });
13794
- }
13795
14041
  function doc_migrate_splitRow(line) {
13796
14042
  const trimmed = line.trim();
13797
14043
  if (!trimmed.startsWith('|')) return null;
@@ -13804,6 +14050,57 @@ function doc_migrate_joinRow(cells) {
13804
14050
  function isSeparator(cells) {
13805
14051
  return cells.every((cell)=>/^:?-{2,}:?$/.test(cell));
13806
14052
  }
14053
+ function renameTaskColumns(options) {
14054
+ const { schema } = options;
14055
+ const table = locateTaskTable(options.lines, schema);
14056
+ if (null === table) return {
14057
+ lines: options.lines,
14058
+ renamed: []
14059
+ };
14060
+ const headerIndex = options.lines.findIndex((line, index)=>index > table.start && index < table.end && null !== doc_migrate_splitRow(line));
14061
+ if (headerIndex < 0) return {
14062
+ lines: options.lines,
14063
+ renamed: []
14064
+ };
14065
+ const header = doc_migrate_splitRow(options.lines[headerIndex] ?? '') ?? [];
14066
+ const wanted = new Set(schema.taskHeaders);
14067
+ const unknown = header.filter((name)=>name.length > 0 && !wanted.has(name));
14068
+ const missing = schema.taskHeaders.filter((name)=>!header.includes(name));
14069
+ if (0 === unknown.length || 0 === missing.length) return {
14070
+ lines: options.lines,
14071
+ renamed: []
14072
+ };
14073
+ const renames = new Map(options.renames);
14074
+ if (0 === renames.size) {
14075
+ if (unknown.length !== missing.length) throw new errors_CliError(`任务表有 ${unknown.length} 列不在 schema 中(${unknown.join('、')}),但有 ${missing.length} 列缺失(${missing.join('、')}),无法自动对应。\n请用 --rename 旧列名=新列名 明确指定,例如:\n ylcwf doc migrate --rename "${unknown[0] ?? '旧列名'}=${missing[0] ?? '新列名'}"`, errors_EXIT.USAGE);
14076
+ unknown.forEach((name, index)=>{
14077
+ const target = missing[index];
14078
+ if (void 0 !== target) renames.set(name, target);
14079
+ });
14080
+ }
14081
+ const renamed = [];
14082
+ const nextHeader = header.map((name)=>{
14083
+ const target = renames.get(name);
14084
+ if (void 0 === target) return name;
14085
+ renamed.push([
14086
+ name,
14087
+ target
14088
+ ]);
14089
+ return target;
14090
+ });
14091
+ if (0 === renamed.length) return {
14092
+ lines: options.lines,
14093
+ renamed: []
14094
+ };
14095
+ const lines = [
14096
+ ...options.lines
14097
+ ];
14098
+ lines[headerIndex] = doc_migrate_joinRow(nextHeader);
14099
+ return {
14100
+ lines,
14101
+ renamed
14102
+ };
14103
+ }
13807
14104
  function locateTaskTable(lines, schema) {
13808
14105
  const heading = `## ${schema.sections[2] ?? '三、任务清单'}`;
13809
14106
  const sectionStart = lines.findIndex((line)=>line.trim() === heading);
@@ -13863,9 +14160,12 @@ function migrateTaskTable(options) {
13863
14160
  }
13864
14161
  const unresolved = [];
13865
14162
  let added = 0;
13866
- const idIndex = header.indexOf('任务编号');
13867
- const typeIndex = header.indexOf('任务类型');
13868
- const terminalIndex = header.indexOf('执行终端');
14163
+ const labelOf = (semantic)=>schema.taskKeys[semantic] ?? '';
14164
+ const indexOf = (semantic)=>header.indexOf(labelOf(semantic));
14165
+ const idIndex = indexOf('id');
14166
+ const typeIndex = indexOf('type');
14167
+ const terminalIndex = indexOf('terminal');
14168
+ const scopeLabel = labelOf('scope');
13869
14169
  for(let index = headerIndex + 2; index < table.end; index += 1){
13870
14170
  const cells = doc_migrate_splitRow(options.lines[index] ?? '');
13871
14171
  if (null === cells || isSeparator(cells)) continue;
@@ -13873,7 +14173,7 @@ function migrateTaskTable(options) {
13873
14173
  header.forEach((name, position)=>{
13874
14174
  record[name] = cells[position] ?? '';
13875
14175
  });
13876
- for (const name of missing)if ('所属端' === name) {
14176
+ for (const name of missing)if (name === scopeLabel) {
13877
14177
  const taskId = cells[idIndex >= 0 ? idIndex : 0] ?? '';
13878
14178
  const type = cells[typeIndex >= 0 ? typeIndex : 0] ?? '';
13879
14179
  const terminal = cells[terminalIndex >= 0 ? terminalIndex : 0] ?? '';
@@ -13934,6 +14234,52 @@ function fieldSpans(lines, block) {
13934
14234
  }
13935
14235
  return spans;
13936
14236
  }
14237
+ function reorderDetailFields(options) {
14238
+ const blocks = locateDetailBlocks(options.lines, options.schema);
14239
+ let lines = [
14240
+ ...options.lines
14241
+ ];
14242
+ let reordered = 0;
14243
+ for (const block of [
14244
+ ...blocks
14245
+ ].reverse()){
14246
+ const spans = fieldSpans(lines, block);
14247
+ if (spans.length < 2) continue;
14248
+ const first = spans[0];
14249
+ const last = spans[spans.length - 1];
14250
+ if (void 0 === first || void 0 === last) continue;
14251
+ const outside = [
14252
+ ...lines.slice(block.headingIndex + 1, first.start),
14253
+ ...lines.slice(last.end, block.endIndex)
14254
+ ];
14255
+ if (outside.some((line)=>line.trim().length > 0)) continue;
14256
+ const scope = options.scopeByTaskId.get(block.taskId) ?? '';
14257
+ const expected = detailFieldsOfScope(options.schema, scope);
14258
+ const present = spans.map((span)=>span.name);
14259
+ const known = expected.filter((name)=>present.includes(name));
14260
+ const unknown = present.filter((name)=>!expected.includes(name));
14261
+ const wanted = [
14262
+ ...known,
14263
+ ...unknown
14264
+ ];
14265
+ if (wanted.every((name, index)=>name === present[index])) continue;
14266
+ const pieces = new Map(spans.map((span)=>[
14267
+ span.name,
14268
+ lines.slice(span.start, span.end)
14269
+ ]));
14270
+ const ordered = wanted.flatMap((name)=>pieces.get(name) ?? []);
14271
+ lines = [
14272
+ ...lines.slice(0, first.start),
14273
+ ...ordered,
14274
+ ...lines.slice(last.end)
14275
+ ];
14276
+ reordered += 1;
14277
+ }
14278
+ return {
14279
+ lines,
14280
+ reordered
14281
+ };
14282
+ }
13937
14283
  function migrateDetailFields(options) {
13938
14284
  const { schema } = options;
13939
14285
  const blocks = locateDetailBlocks(options.lines, schema);
@@ -13998,39 +14344,60 @@ function runDocMigrate(options) {
13998
14344
  const schema = loadDocSchema(docsRoot);
13999
14345
  const resolveScopeFromTerminal = makeTerminalResolver(config.terminals);
14000
14346
  const iterations = options.iteration?.trim() ? [
14001
- options.iteration.trim()
14002
- ] : doc_migrate_listIterations(docsRoot);
14347
+ requireIterationDir(docsRoot, layout.iterationsRoot, options.iteration.trim())
14348
+ ] : listIterationDirs(docsRoot, layout.iterationsRoot);
14349
+ const renames = new Map();
14350
+ for (const pair of options.rename ?? []){
14351
+ const [from, to] = pair.split('=');
14352
+ if (void 0 === from || void 0 === to || '' === from.trim() || '' === to.trim()) throw new errors_CliError(`--rename 的格式应为 旧列名=新列名,收到:${pair}`, errors_EXIT.USAGE);
14353
+ renames.set(from.trim(), to.trim());
14354
+ }
14003
14355
  const results = [];
14004
14356
  const changedFiles = [];
14005
14357
  for (const iteration of iterations){
14006
- const dir = external_node_path_join(docsRoot, iteration);
14358
+ const dir = iteration.dir;
14007
14359
  if (!external_node_fs_existsSync(dir)) continue;
14008
14360
  const files = external_node_fs_readdirSync(dir).filter((name)=>name.endsWith('.md') && !name.startsWith('_'));
14009
14361
  for (const name of files){
14010
14362
  const target = external_node_path_join(dir, name);
14011
14363
  const original = readFileSync(target, 'utf8');
14012
- const tableMigrated = migrateTaskTable({
14364
+ const renamedResult = renameTaskColumns({
14013
14365
  lines: original.split('\n'),
14014
14366
  schema,
14367
+ renames
14368
+ });
14369
+ const tableMigrated = migrateTaskTable({
14370
+ lines: renamedResult.lines,
14371
+ schema,
14015
14372
  resolveScopeFromTerminal
14016
14373
  });
14374
+ for (const [from, to] of renamedResult.renamed)printLine(`${'json' === format ? '' : '· '}${iteration.relPath}/${name}:列名「${from}」→「${to}」`);
14017
14375
  const scopeByTaskId = collectTaskScopes(tableMigrated.lines, schema);
14018
14376
  const detailMigrated = migrateDetailFields({
14019
14377
  lines: tableMigrated.lines,
14020
14378
  schema,
14021
14379
  scopeByTaskId
14022
14380
  });
14381
+ const reordered = reorderDetailFields({
14382
+ lines: detailMigrated.lines,
14383
+ schema,
14384
+ scopeByTaskId
14385
+ });
14023
14386
  const addedRows = tableMigrated.added;
14024
14387
  const addedFields = detailMigrated.added;
14025
- if (0 === addedRows && 0 === addedFields) continue;
14388
+ const renamedColumns = renamedResult.renamed.length;
14389
+ const reorderedBlocks = reordered.reordered;
14390
+ if (0 === addedRows && 0 === addedFields && 0 === renamedColumns && 0 === reorderedBlocks) continue;
14026
14391
  const migrated = {
14027
- lines: detailMigrated.lines,
14392
+ lines: reordered.lines,
14028
14393
  unresolved: tableMigrated.unresolved
14029
14394
  };
14030
14395
  results.push({
14031
- file: `${iteration}/${name}`,
14396
+ file: `${iteration.relPath}/${name}`,
14032
14397
  added: addedRows,
14033
14398
  addedFields,
14399
+ renamed: renamedColumns,
14400
+ reordered: reorderedBlocks,
14034
14401
  unresolved: tableMigrated.unresolved
14035
14402
  });
14036
14403
  if (true === options.dryRun) continue;
@@ -14038,15 +14405,15 @@ function runDocMigrate(options) {
14038
14405
  changedFiles.push(target);
14039
14406
  if (migrated.unresolved.length > 0) continue;
14040
14407
  const developer = basename(name, '.md');
14041
- const outcome = validateAfterWrite(layout, iteration, developer);
14408
+ const outcome = validateAfterWrite(layout, iteration.relPath, developer);
14042
14409
  if ('passed' !== outcome.kind) {
14043
14410
  writeFileSync(target, original, 'utf8');
14044
14411
  const reason = 'violation' === outcome.kind ? outcome.message : outcome.reason;
14045
14412
  if ('unavailable' === outcome.kind && !requireValidatorScript()) {
14046
- process.stderr.write(`警告:${outcome.reason};${iteration}/${name} 未做迁移后校验(docs.validator.requireScript=false)\n`);
14413
+ process.stderr.write(`警告:${outcome.reason};${iteration.relPath}/${name} 未做迁移后校验(docs.validator.requireScript=false)\n`);
14047
14414
  continue;
14048
14415
  }
14049
- throw new errors_CliError(`迁移后校验未通过,已回滚 ${iteration}/${name}:${reason}`, errors_EXIT.INVALID);
14416
+ throw new errors_CliError(`迁移后校验未通过,已回滚 ${iteration.relPath}/${name}:${reason}`, errors_EXIT.INVALID);
14050
14417
  }
14051
14418
  }
14052
14419
  }
@@ -14064,6 +14431,8 @@ function runDocMigrate(options) {
14064
14431
  const parts = [];
14065
14432
  if (item.added > 0) parts.push(`${item.added} 行任务`);
14066
14433
  if (item.addedFields > 0) parts.push(`${item.addedFields} 个详情字段`);
14434
+ if (item.renamed > 0) parts.push(`${item.renamed} 列改名`);
14435
+ if (item.reordered > 0) parts.push(`${item.reordered} 个详情区块重排`);
14067
14436
  printLine(` · ${item.file} ${parts.join(' + ')}${extra}`);
14068
14437
  }
14069
14438
  if (totalUnresolved.length > 0) {
@@ -14088,8 +14457,8 @@ function collectTaskScopes(lines, schema) {
14088
14457
  const headerIndex = lines.findIndex((line, index)=>index > table.start && index < table.end && null !== doc_migrate_splitRow(line));
14089
14458
  if (headerIndex < 0) return result;
14090
14459
  const header = doc_migrate_splitRow(lines[headerIndex] ?? '') ?? [];
14091
- const idIndex = header.indexOf('任务编号');
14092
- const scopeIndex = header.indexOf('所属端');
14460
+ const idIndex = header.indexOf(schema.taskKeys['id'] ?? '');
14461
+ const scopeIndex = header.indexOf(schema.taskKeys['scope'] ?? '');
14093
14462
  if (idIndex < 0 || scopeIndex < 0) return result;
14094
14463
  for(let index = headerIndex + 2; index < table.end; index += 1){
14095
14464
  const cells = doc_migrate_splitRow(lines[index] ?? '');
@@ -14101,7 +14470,10 @@ function collectTaskScopes(lines, schema) {
14101
14470
  return result;
14102
14471
  }
14103
14472
  function registerDocMigrate(doc) {
14104
- doc.command('migrate').description('按 schema.json 迁移存量文档(补缺失的任务列并回填)').option('-i, --iteration <name>', '只迁移指定迭代').option('--dry-run', '只打印将要迁移的文件,不写盘').option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
14473
+ doc.command('migrate').description('按 schema.json 迁移存量文档(列改名 + 补缺失列 + 补详情字段)').option('-i, --iteration <name>', '只迁移指定迭代').option('--dry-run', '只打印将要迁移的文件,不写盘').option('--rename <old=new>', '列名对应关系(可多次),如 --rename "任务编号=任务号";不给时按缺失/多余列自动推断', (value, previous)=>[
14474
+ ...previous ?? [],
14475
+ value
14476
+ ]).option('-c, --config <path>', '指定配置文件路径').option('--format <format>', '输出格式:human | json', 'human').action((options)=>{
14105
14477
  runDocMigrate(options);
14106
14478
  });
14107
14479
  }
@@ -14143,6 +14515,10 @@ function runDocApply(options, mode = 'apply') {
14143
14515
  requirements: [],
14144
14516
  tasks: []
14145
14517
  } : parseMarkdownDoc(original, schema);
14518
+ if (null !== original) {
14519
+ const documentRole = inferRole(original);
14520
+ if (documentRole !== role) process.stderr.write(`提示:${resolvedIteration.relPath}/${developer}.md 的负责范围是「${documentRole}」,与当前角色「${role}」不一致。\n 写入后的校验按文档为准(${documentRole});要让文档与本机角色一致,请手工修改「负责范围」为 ${role}。\n`);
14521
+ }
14146
14522
  validatePlanReferences({
14147
14523
  plan,
14148
14524
  schema,
@@ -14252,7 +14628,6 @@ function runDocApply(options, mode = 'apply') {
14252
14628
  iterationsRoot: layout.iterationsRoot,
14253
14629
  iteration,
14254
14630
  developer,
14255
- role,
14256
14631
  terminals: config.terminals
14257
14632
  });
14258
14633
  const remaining = remainingReport.issues.filter((issue)=>'error' === issue.level);
@@ -14566,7 +14941,6 @@ function collectSideIssues(options) {
14566
14941
  iterationsRoot: options.iterationsRoot,
14567
14942
  iteration: options.iteration,
14568
14943
  developer: options.developer,
14569
- role: loaded.config.profile.role,
14570
14944
  terminals: loaded.config.terminals
14571
14945
  }).issues.filter((issue)=>'error' === issue.level).map((issue)=>issue.message);
14572
14946
  } catch {
@@ -15215,9 +15589,9 @@ async function fetchManifest(url) {
15215
15589
  const payload = await response.json();
15216
15590
  if ('string' != typeof payload.version || 0 === payload.version.length) return null;
15217
15591
  return {
15218
- current: "0.6.1",
15592
+ current: "0.6.2",
15219
15593
  latest: payload.version,
15220
- hasUpdate: isNewer(payload.version, "0.6.1"),
15594
+ hasUpdate: isNewer(payload.version, "0.6.2"),
15221
15595
  downloadUrl: 'string' == typeof payload.downloadUrl ? payload.downloadUrl : null,
15222
15596
  source: 'manifest',
15223
15597
  checkedAt: new Date().toISOString(),
@@ -15229,7 +15603,7 @@ async function fetchManifest(url) {
15229
15603
  }
15230
15604
  async function fetchNpm() {
15231
15605
  const base = {
15232
- current: "0.6.1",
15606
+ current: "0.6.2",
15233
15607
  latest: null,
15234
15608
  hasUpdate: false,
15235
15609
  downloadUrl: null,
@@ -15256,7 +15630,7 @@ async function fetchNpm() {
15256
15630
  return {
15257
15631
  ...base,
15258
15632
  latest,
15259
- hasUpdate: isNewer(latest, "0.6.1"),
15633
+ hasUpdate: isNewer(latest, "0.6.2"),
15260
15634
  downloadUrl: null
15261
15635
  };
15262
15636
  } catch (error) {
@@ -15347,7 +15721,7 @@ async function runUpgrade(options) {
15347
15721
  const kind = detectInstallKind();
15348
15722
  const result = await checkUpdate(true);
15349
15723
  const target = options.to?.trim() ?? result.latest;
15350
- printLine("当前版本:0.6.1");
15724
+ printLine("当前版本:0.6.2");
15351
15725
  if (null !== result.error) printLine(`版本查询失败:${result.error}`);
15352
15726
  else if (null !== result.latest) printLine(`最新版本:${result.latest}(来源:${result.source})`);
15353
15727
  if (null === target) throw new errors_CliError('无法确定目标版本,请稍后重试或用 --to 指定', errors_EXIT.NOT_FOUND);
@@ -15724,7 +16098,6 @@ function checkDocsSides(config) {
15724
16098
  iterationsRoot,
15725
16099
  iteration,
15726
16100
  developer: config.profile.developer,
15727
- role: config.profile.role,
15728
16101
  terminals: config.terminals
15729
16102
  });
15730
16103
  for (const issue of report.issues)messages.push({
@@ -15976,7 +16349,7 @@ function readState(explicitPath) {
15976
16349
  issues: checked.issues,
15977
16350
  backups: listBackups(explicitPath),
15978
16351
  meta: {
15979
- version: "0.6.1",
16352
+ version: "0.6.2",
15980
16353
  features: SERVER_FEATURES
15981
16354
  }
15982
16355
  };
@@ -17205,7 +17578,7 @@ function registerReset(program) {
17205
17578
  }
17206
17579
  function buildProgram() {
17207
17580
  const program = new command_Command();
17208
- program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与执行终端仓库映射').version("0.6.1", '-v, --version', '显示版本号').showHelpAfterError();
17581
+ program.name('ylcwf').description('YLC 研发工作流配置:文档仓库、开发者标识、默认角色与执行终端仓库映射').version("0.6.2", '-v, --version', '显示版本号').showHelpAfterError();
17209
17582
  registerInit(program);
17210
17583
  registerShow(program);
17211
17584
  registerGet(program);