@buaa_smat/hometrans 26.0.7 → 26.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/agents/a2h-executor.md +37 -0
  2. package/env-requirements.json +15 -1
  3. package/i18n/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
  4. package/i18n/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
  5. package/i18n/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
  6. package/i18n/skills/a2h-app-migrate/SKILL.md +2 -2
  7. package/i18n/skills/a2h-app-migrate/references/workflow.yaml +27 -4
  8. package/i18n/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
  9. package/i18n/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
  10. package/i18n/skills/a2h-batch-ui-align/SKILL.md +7 -7
  11. package/i18n/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
  12. package/i18n/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
  13. package/i18n/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
  14. package/i18n/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
  15. package/i18n/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
  16. package/i18n/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
  17. package/i18n/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
  18. package/i18n/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
  19. package/i18n/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
  20. package/i18n/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
  21. package/i18n/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
  22. package/i18n/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
  23. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
  24. package/i18n/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
  25. package/i18n/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
  26. package/i18n/skills/a2h-page-specgen/SKILL.md +1 -1
  27. package/i18n/skills/a2h-page-specgen/references/gates.md +3 -1
  28. package/i18n/skills/a2h-page-specgen/references/scenario-authoring.md +11 -11
  29. package/i18n/skills/a2h-page-specgen/references/spec-template.md +3 -3
  30. package/i18n/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
  31. package/i18n/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
  32. package/i18n/skills/a2h-page-specgen/scripts/gate.mjs +144 -0
  33. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +11 -11
  34. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +11 -11
  35. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +11 -11
  36. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +11 -11
  37. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
  38. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
  39. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +11 -11
  40. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +11 -11
  41. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +11 -11
  42. package/i18n/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +11 -11
  43. package/i18n/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
  44. package/i18n/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
  45. package/i18n/skills/a2h-page-specgen/scripts/test/gate.test.mjs +132 -3
  46. package/i18n/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
  47. package/i18n/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
  48. package/i18n/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
  49. package/i18n/skills/a2h-utg-static/SKILL.md +2 -0
  50. package/package.json +1 -1
  51. package/platforms/atomcode/agents/a2h-executor.frontmatter.md +6 -0
  52. package/platforms/codebuddy/agents/a2h-executor.frontmatter.md +5 -0
  53. package/platforms/codebuddy/skills/a2h-app-migrate/SKILL.unique.md +2 -2
  54. package/platforms/deveco/agents/a2h-executor.frontmatter.md +7 -0
  55. package/platforms/deveco/agents/build-fixer.frontmatter.md +0 -2
  56. package/platforms/deveco/agents/code-reviewer.frontmatter.md +0 -2
  57. package/platforms/deveco/agents/model-render-worker.frontmatter.md +0 -2
  58. package/platforms/deveco/agents/model-worker.frontmatter.md +0 -2
  59. package/platforms/deveco/agents/specgen-worker.frontmatter.md +0 -2
  60. package/platforms/deveco/skills/a2h-app-migrate/SKILL.unique.md +1 -1
  61. package/platforms/opencode/agents/a2h-executor.frontmatter.md +7 -0
  62. package/platforms/opencode/agents/build-fixer.frontmatter.md +0 -2
  63. package/platforms/opencode/agents/code-reviewer.frontmatter.md +0 -2
  64. package/platforms/opencode/agents/model-render-worker.frontmatter.md +0 -2
  65. package/platforms/opencode/agents/model-worker.frontmatter.md +0 -2
  66. package/platforms/opencode/agents/specgen-worker.frontmatter.md +0 -2
  67. package/platforms/opencode/skills/a2h-app-migrate/SKILL.unique.md +13 -6
  68. package/skills/a2h-app-migrate/SKILL.md +29 -3
  69. package/skills/a2h-app-migrate/references/host-rules.md +33 -0
  70. package/skills/a2h-app-migrate/references/workflow.yaml +24 -4
  71. package/skills/a2h-app-migrate/scripts/opencode_depth.mjs +418 -0
  72. package/skills/a2h-app-migrate/test/test_executor_header_sync.mjs +78 -0
  73. package/skills/a2h-app-migrate/test/test_opencode_depth.mjs +312 -0
  74. package/skills/a2h-app-migrate/tools/dag.mjs +267 -0
  75. package/skills/a2h-arkts-logic-coder/references/ISSUES.md +2 -0
  76. package/skills/a2h-batch-ui-align/SKILL.md +7 -7
  77. package/skills/a2h-batch-ui-align/references/cards/alignment.md +1 -1
  78. package/skills/a2h-batch-ui-align/references/cards/state.md +20 -2
  79. package/skills/a2h-batch-ui-align/references/cards/widgets.md +2 -2
  80. package/skills/a2h-batch-ui-align/references/checker-rules.md +3 -3
  81. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +3 -1
  82. package/skills/a2h-batch-ui-align/references/host-dispatch.md +5 -5
  83. package/skills/a2h-batch-ui-align/references/incremental-scope.md +2 -2
  84. package/skills/a2h-batch-ui-align/references/step3-capture.md +10 -6
  85. package/skills/a2h-batch-ui-align/references/step5-convert.md +13 -9
  86. package/skills/a2h-batch-ui-align/scripts/build_conversion_set.mjs +59 -7
  87. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -0
  88. package/skills/a2h-batch-ui-align/scripts/group_pass.mjs +3 -2
  89. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +139 -23
  90. package/skills/a2h-batch-ui-align/scripts/host_env.mjs +32 -8
  91. package/skills/a2h-batch-ui-align/scripts/interactions.mjs +186 -0
  92. package/skills/a2h-batch-ui-align/scripts/phase5_check.mjs +33 -7
  93. package/skills/a2h-batch-ui-align/scripts/static_check/rules/hit_test.ts +83 -22
  94. package/skills/a2h-batch-ui-align/scripts/static_check/rules/media_tint.ts +39 -5
  95. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_hit_test.test.mjs +82 -0
  96. package/skills/a2h-batch-ui-align/scripts/tests/arkts_static_check_scroll_padding_raster.test.mjs +25 -1
  97. package/skills/a2h-batch-ui-align/scripts/tests/group_queue.test.mjs +184 -2
  98. package/skills/a2h-batch-ui-align/scripts/tests/host_env.test.mjs +33 -0
  99. package/skills/a2h-batch-ui-align/scripts/tests/interactions.test.mjs +258 -0
  100. package/skills/a2h-page-specgen/SKILL.md +1 -1
  101. package/skills/a2h-page-specgen/references/evidence.md +15 -0
  102. package/skills/a2h-page-specgen/references/gates.md +3 -1
  103. package/skills/a2h-page-specgen/references/scenario-authoring.md +10 -10
  104. package/skills/a2h-page-specgen/references/spec-template.md +2 -2
  105. package/skills/a2h-page-specgen/scripts/contract-calls.mjs +40 -3
  106. package/skills/a2h-page-specgen/scripts/entry-evidence.mjs +73 -5
  107. package/skills/a2h-page-specgen/scripts/gate.mjs +141 -0
  108. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.prompt.md +10 -10
  109. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/PlainDisplayPage.worker.md +10 -10
  110. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.prompt.md +10 -10
  111. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/SilentFailurePage.worker.md +10 -10
  112. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.json +10 -10
  113. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.post-review.json +1 -1
  114. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.prompt.md +10 -10
  115. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/UniAppSourcePage.worker.md +10 -10
  116. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.prompt.md +10 -10
  117. package/skills/a2h-page-specgen/scripts/test/acceptance/authoring/ValidatedSearchPage.worker.md +10 -10
  118. package/skills/a2h-page-specgen/scripts/test/contract-calls.test.mjs +45 -1
  119. package/skills/a2h-page-specgen/scripts/test/entry-evidence.test.mjs +100 -0
  120. package/skills/a2h-page-specgen/scripts/test/gate.test.mjs +104 -3
  121. package/skills/a2h-resource-convert/references/conversion-rules.md +2 -0
  122. package/skills/a2h-resource-convert/scripts/a2h_resource_convert.ts +36 -1
  123. package/skills/a2h-resource-convert/scripts/tests/adaptive_icon.test.mjs +42 -0
  124. package/skills/a2h-spec-design-pipeline/SKILL.md +1 -1
  125. package/skills/a2h-spec-design-pipeline/references/coding-loop.md +16 -0
  126. package/skills/a2h-spec-design-pipeline/references/execution-model.md +2 -2
  127. package/skills/a2h-spec-design-pipeline/references/static-defect-gate.md +5 -1
  128. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleMeta.json +5 -0
  129. package/skills/a2h-spec-design-pipeline/rules/migration-rules/config/ruleSet.json +4 -0
  130. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-cn.md +2 -1
  131. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-runtime-pitfall-en.md +3 -1
  132. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-cn.md +105 -0
  133. package/skills/a2h-spec-design-pipeline/rules/migration-rules/document/checker/hometrans/arkui-v2-observation-en.md +122 -0
  134. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIRuntimePitfallCheck.js +4 -4
  135. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/checker/ArkUIV2ObservationCheck.js +1862 -0
  136. package/skills/a2h-spec-design-pipeline/rules/migration-rules/lib/index.js +2 -0
  137. package/skills/a2h-spec-design-pipeline/rules/migration-rules/package.json +1 -1
  138. package/skills/a2h-spec-design-pipeline/scripts/dispatch/wait.mjs +15 -2
  139. package/skills/a2h-spec-design-pipeline/scripts/dispatch.mjs +20 -4
  140. package/skills/a2h-spec-design-pipeline/scripts/test_arkui_v2_observation.ts +284 -0
  141. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_commands.mjs +32 -0
  142. package/skills/a2h-spec-design-pipeline/scripts/test_dispatch_wait.mjs +22 -1
  143. package/skills/a2h-utg-static/SKILL.md +2 -0
  144. package/skills/a2h-utg-static/references/extractors.md +16 -0
  145. package/skills/a2h-utg-static/scripts/run_pipeline.mjs +22 -1
  146. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +4 -0
  147. package/skills/a2h-utg-static/scripts/tests/test_pr169_review_fixes.mjs +15 -0
  148. package/skills/a2h-utg-static/scripts/tests/test_view_attachments.mjs +330 -0
  149. package/skills/a2h-utg-static/scripts/view_attachments.mjs +465 -0
  150. package/platforms/codebuddy/agents/build-fixer.frontmatter.md +0 -5
  151. package/platforms/codebuddy/agents/code-reviewer.frontmatter.md +0 -5
  152. package/platforms/codebuddy/agents/model-render-worker.frontmatter.md +0 -5
  153. package/platforms/codebuddy/agents/model-worker.frontmatter.md +0 -5
  154. package/platforms/codebuddy/agents/specgen-worker.frontmatter.md +0 -5
@@ -56,6 +56,7 @@ import { _replace, _uiModule } from './group_watch.mjs';
56
56
  import { scrollableContainers, sourceDeclaresScroll, sourceFileFor } from './capture_audit.mjs';
57
57
  import { scrollVerdict } from './scroll_verdict.mjs';
58
58
  import * as mp from './module_placement.mjs';
59
+ import { interactionsOf } from './interactions.mjs';
59
60
 
60
61
  // ---------------------------------------------------------------- Python compatibility layer
61
62
  // These outputs are a contract read by other scripts and the agent and must match the original Python version byte for byte:
@@ -892,8 +893,26 @@ export function templateKeys(node, shareable = shareableByPath) {
892
893
 
893
894
  const tkey = (k) => pyRepr(k[0]) + '\u0000' + pyRepr(k[1]);
894
895
 
896
+ // `args.action` values that name no gesture: a plain tap, and the placeholders a2h-utg-static writes on
897
+ // fragment-transaction / embed / pager edges (`default`) and launch-path edges (`launch`).
898
+ const NOT_A_GESTURE = new Set(['tap', 'click', 'onClick', 'default', 'launch']);
899
+
895
900
  export function edgeView(e, end) {
896
901
  const v = { [end]: e[end], mechanism: get(e, 'mechanism'), trigger: get(e, 'trigger') };
902
+ // The condition the jump needs (`!isLoggedIn` → login page): without it the conversion writes an unconditional jump.
903
+ const guard = get(e, 'guard');
904
+ if (truthy(guard)) { v.guard = guard; }
905
+ // On-screen wording of the trigger, and a gesture other than a plain tap (long_press, double_tap, swipe-*).
906
+ const args = get(e, 'args', {}) ?? {};
907
+ const label = get(args, 'label');
908
+ if (truthy(label)) { v.label = label; }
909
+ // `action` names the gesture; when it is a placeholder or the generic `swipe`, `args.gesture` is the more
910
+ // specific one (`{action: 'swipe', gesture: 'open-drawer'}`), and a placeholder never hides a real gesture.
911
+ const action = get(args, 'action');
912
+ const named = get(args, 'gesture');
913
+ const useAction = truthy(action) && !NOT_A_GESTURE.has(action) && !(action === 'swipe' && truthy(named));
914
+ const gesture = useAction ? action : named;
915
+ if (truthy(gesture) && !NOT_A_GESTURE.has(gesture)) { v.gesture = gesture; }
897
916
  // What opening / dismissing an overlay also does to its host (a2h-utg-static `args.host_effects`:
898
917
  // `{open: [{id, stmt, at, resolved}], dismiss: [...]}`). Absent on an older UTG.
899
918
  const fx = get(get(e, 'args', {}) ?? {}, 'host_effects');
@@ -920,7 +939,9 @@ const isEmptyish = (v) => v === null || v === undefined || (Array.isArray(v) &&
920
939
  export function hintsOf(node) {
921
940
  const widgets = (or(get(node, 'widgets'), [])).map((w) => {
922
941
  const o = {};
923
- for (const k of ['widget', 'kind', 'view_id', 'text', 'placeholder', 'preference_type', 'at']) {
942
+ // gesture_param (long press / double tap ...) and trigger_targets (the nodes this control opens): without them a
943
+ // source-only page cannot tell a long-press control from a tap one, or which control opens which page.
944
+ for (const k of ['widget', 'kind', 'view_id', 'text', 'placeholder', 'preference_type', 'at', 'gesture_param', 'trigger_targets']) {
924
945
  const v = get(w, k);
925
946
  if (v !== null && v !== undefined) { o[k] = w[k]; }
926
947
  }
@@ -1886,6 +1907,17 @@ export function build(ws, uiInfo, entry = null, renumber = false, exploring = fa
1886
1907
  for (const [nid, r] of roles) {
1887
1908
  if (r.role === 'attach') { setdefault(attached, r.host, []).push(nid); }
1888
1909
  }
1910
+ // In-page interactions of a page (interactions.mjs): its own, and those of the nodes attached to it. An attach
1911
+ // node has no page dir of its own, so its interactions would otherwise reach neither a meta.json nor a prompt.
1912
+ // Computed once per page: the source-only meta, the captured meta and conversion_set.json all read it.
1913
+ const interactionsCache = new Map();
1914
+ const interactionsFor = (nid) => {
1915
+ if (!interactionsCache.has(nid)) {
1916
+ interactionsCache.set(nid, [nid, ...sortedBy(attached.get(nid) ?? [])]
1917
+ .flatMap((n) => interactionsOf(g.nodes.get(n))).map((x) => ({ ...x, host: nid })));
1918
+ }
1919
+ return interactionsCache.get(nid);
1920
+ };
1889
1921
 
1890
1922
  const tmplIndex = new Map();
1891
1923
  for (const [nid, dirs] of captured) {
@@ -2021,6 +2053,7 @@ export function build(ws, uiInfo, entry = null, renumber = false, exploring = fa
2021
2053
  const p = or(paths.get(nid), {});
2022
2054
  const labels = get(p, 'steps', []).map((s) => get(s, 'label')).filter(truthy);
2023
2055
  const route = or(get(p, 'nl_path_text'), get(p, 'path_text'));
2056
+ const ixs = interactionsFor(nid);
2024
2057
  const meta = {
2025
2058
  page_id: slug, static_node: nid, kind: get(node, 'kind'), label: get(node, 'label'),
2026
2059
  declared_at: get(node, 'declared_at'),
@@ -2033,6 +2066,7 @@ export function build(ws, uiInfo, entry = null, renumber = false, exploring = fa
2033
2066
  reached_from: (g.inbound.get(nid) ?? []).map((e) => edgeView(e, 'source')),
2034
2067
  navigates_to: (g.outbound.get(nid) ?? []).map((e) => edgeView(e, 'target')),
2035
2068
  template_pages: templates.slice(0, MAX_TEMPLATES),
2069
+ ...(ixs.length ? { interactions: ixs } : {}),
2036
2070
  click_path: get(p, 'steps', []),
2037
2071
  breadcrumb: labels.join(' > '),
2038
2072
  click_path_text: or(route, ''),
@@ -2059,6 +2093,9 @@ export function build(ws, uiInfo, entry = null, renumber = false, exploring = fa
2059
2093
  if (blank) { demoted.set(nid, blank); }
2060
2094
  row.tier = captured.has(nid) && !blank ? 'captured' : 'source-only';
2061
2095
  row.page_dirs = dirs;
2096
+ // Step 5.5 wires navigation by walking these rows' navigates_to (step5-convert.md).
2097
+ const out = (g.outbound.get(nid) ?? []).map((e) => edgeView(e, 'target'));
2098
+ if (out.length) { row.navigates_to = out; }
2062
2099
  // captured but every frame FLAG_SECURE-blocked: view tree only, no pixel verification possible
2063
2100
  if (row.tier === 'captured' && row.page_dirs.every((d) => pixelsBlocked(uiInfo, d))) { row.pixels = 'blocked'; }
2064
2101
  if (blank) { row.pixels = 'rejected'; row.capture_rejected = blank; }
@@ -2105,15 +2142,27 @@ export function build(ws, uiInfo, entry = null, renumber = false, exploring = fa
2105
2142
  for (const [nid, dirs] of captured) {
2106
2143
  if (get(roles.get(nid), 'role') !== 'page') { continue; }
2107
2144
  for (const d of dirs ?? []) { writeDemotion(d, demoted.get(nid) ?? null); }
2108
- // A captured meta.json has no reached_from / navigates_to: the overlay edges that carry host effects
2109
- // go in as overlay_effects, the same edge views a source-only page lists.
2110
- const fx = g.nodes.has(nid) ? overlayEffectsOf(g, nid) : [];
2145
+ // export_ui_info writes a captured meta.json without the static edges. Step 5.5 wires navigation from
2146
+ // navigates_to, so a captured page — usually the main path — needs them as much as a source-only one does.
2147
+ // The overlay edges that carry host effects also go in as overlay_effects, and the page's in-page
2148
+ // interactions (its own and its attached nodes') as interactions.
2149
+ const want = g.nodes.has(nid) ? {
2150
+ reached_from: (g.inbound.get(nid) ?? []).map((e) => edgeView(e, 'source')),
2151
+ navigates_to: (g.outbound.get(nid) ?? []).map((e) => edgeView(e, 'target')),
2152
+ overlay_effects: overlayEffectsOf(g, nid),
2153
+ interactions: interactionsFor(nid),
2154
+ } : { reached_from: [], navigates_to: [], overlay_effects: [], interactions: [] };
2111
2155
  for (const d of dirs ?? []) {
2112
2156
  const file = path.join(uiInfo, pathName(String(d)), 'meta.json');
2113
2157
  const meta = or(readJson(file), null);
2114
2158
  if (!meta) { continue; }
2115
- if (fx.length) { meta.overlay_effects = fx; } else if (meta.overlay_effects !== undefined) { delete meta.overlay_effects; } else { continue; }
2116
- writeJson(file, meta);
2159
+ let changed = false;
2160
+ for (const [k, v] of Object.entries(want)) {
2161
+ if (v.length) {
2162
+ if (JSON.stringify(meta[k]) !== JSON.stringify(v)) { meta[k] = v; changed = true; }
2163
+ } else if (meta[k] !== undefined) { delete meta[k]; changed = true; }
2164
+ }
2165
+ if (changed) { writeJson(file, meta); }
2117
2166
  }
2118
2167
  }
2119
2168
  // pages.json rows feed Step 4.1 and group_queue: a demoted page must not read "captured" there.
@@ -2245,8 +2294,11 @@ export function build(ws, uiInfo, entry = null, renumber = false, exploring = fa
2245
2294
  if (hasHostEffects(get(get(e, 'args', {}) ?? {}, 'host_effects'))) { overlayEffects.push({ source: nid, ...edgeView(e, 'target') }); }
2246
2295
  }
2247
2296
  }
2297
+ // Every page's in-page interactions, for the group pack and phase5_check interaction-uncovered.
2298
+ const interactions = nodesOut.filter((r) => r.role === 'page').flatMap((r) => interactionsFor(r.node));
2248
2299
  writeJson(path.join(uiInfo, 'conversion_set.json'),
2249
- { summary, nodes: nodesOut, plan, ...(overlayEffects.length ? { overlay_effects: overlayEffects } : {}) });
2300
+ { summary, nodes: nodesOut, plan, ...(overlayEffects.length ? { overlay_effects: overlayEffects } : {}),
2301
+ ...(interactions.length ? { interactions } : {}) });
2250
2302
  return summary;
2251
2303
  }
2252
2304
 
@@ -38,6 +38,7 @@ import { fileURLToPath, pathToFileURL } from 'node:url';
38
38
  import { scrollableContainers } from './capture_audit.mjs';
39
39
  import { scrollVerdict } from './scroll_verdict.mjs';
40
40
  import { edgesInScope, loadEffects, renderEffectsSection } from './overlay_effects.mjs';
41
+ import { interactionsInScope, loadInteractions, renderInteractionsSection } from './interactions.mjs';
41
42
 
42
43
  /** A doc heading / evidence name quoted the way the docs quote it: 「name」 in zh, "name" in en. */
43
44
  const quoteName = (s) => (`「${s}」`);
@@ -1626,6 +1627,8 @@ export function render(group, pack, idx, hres, android, uiInfo = null, { inline
1626
1627
  if (uiInfo !== null) {
1627
1628
  const members = new Set(pyIter(or(dget(group, 'members'), [])).map((m) => pyStr(dget(m, 'node'))));
1628
1629
  lines.push(...renderEffectsSection(edgesInScope(loadEffects(uiInfo), { members })));
1630
+ // In-page interactions of this group's pages and their attached nodes (interactions.mjs)
1631
+ lines.push(...renderInteractionsSection(interactionsInScope(loadInteractions(uiInfo), members)));
1629
1632
  }
1630
1633
  if (uiInfo !== null) { lines.push(...renderEvidence(referenceEvidence(group, uiInfo))); }
1631
1634
  lines.push(...renderCards([...pack.files.values()].map(([p]) => pathStr(p))));
@@ -210,7 +210,8 @@ function verifyStep(hp, out, commit) {
210
210
  commitVerified(hp, out, gid);
211
211
  } else if ((s.attempts ?? 0) >= gq.MAX_ATTEMPTS) {
212
212
  // the same session already answered this three times: a fourth identical request will not differ
213
- out.needs_human.push({ group: gid, hint: `phase5 blocking=${p.blocking} after ${s.attempts} attempts: ${p.issues}` });
213
+ out.needs_human.push({ group: gid, hint: `phase5 blocking=${p.blocking} after ${s.attempts} attempts: ${p.issues}. `
214
+ + 'If its session is saturated (repeats itself, or its context is near full), `requeue --fresh` starts a new one' });
214
215
  } else {
215
216
  const msg = `phase5_check blocking=${p.blocking}: ${p.issues}. Fix every blocking item, rewrite the report, reply DONE ${gid}`;
216
217
  const rq = Q(hp, 'requeue', '--group', gid, ...(p.missing ? ['--resume'] : []), '--message', msg);
@@ -224,7 +225,7 @@ function verifyStep(hp, out, commit) {
224
225
  function nextAction(out, summary) {
225
226
  if (out.stop_first.length) return 'stop each stop_first task, then `group_queue.mjs release --unit <unit> --stalled`, then run this pass again';
226
227
  if (out.reviews_unbound) return 'dispatch a reviewer for every reviews_unbound answers file (Step 3.2) and `review-bind` it: the capture cannot finish without them; then start `dispatch`';
227
- if (out.dispatch.length) return 'start every dispatch entry (resume_task set: resume that session), `group_queue.mjs bind` each, then `group_queue.mjs wait` (shell timeout above 9 min)';
228
+ if (out.dispatch.length) return 'start every dispatch entry (resume_task set: resume that session), `group_queue.mjs bind` each, then one `group_queue.mjs wait` in its own shell call (shell timeout above 5 min), never a loop of waits';
228
229
  if (out.needs_human.length) return 'needs_human lists groups the queue cannot move: read each hint, fix the cause, `requeue` or ask the user';
229
230
  if (summary?.idle && !(summary.returned_unverified ?? []).length && !Object.keys(summary.stuck ?? {}).length) return 'queue idle: go to Step 5.5';
230
231
  return '`group_queue.mjs wait` (never sleep in a loop), then run this pass again';
@@ -74,7 +74,7 @@
74
74
  * node group_queue.mjs release <harmony_dir> --unit G002+G003 [--task <id>] [--stalled] [--error "..."]
75
75
  * node group_queue.mjs reap <harmony_dir> # reported / silent units
76
76
  * node group_queue.mjs review-bind <harmony_dir> --name <part> --answers <path> [--task <id>]
77
- * node group_queue.mjs wait <harmony_dir> [--timeout-s 540] [--job run_cycle]
77
+ * node group_queue.mjs wait <harmony_dir> [--timeout-s 300] [--job run_cycle]
78
78
  * node group_queue.mjs status <harmony_dir> [--assert-settled] # exit 1 while a group is still open
79
79
  * node group_queue.mjs refresh <harmony_dir> [--force] # rebuild a plan behind the captures
80
80
  * node group_queue.mjs verified <harmony_dir> --group G007 [--summary "..."] # also marks its pages done
@@ -90,6 +90,7 @@
90
90
  import * as fs from 'node:fs';
91
91
  import * as path from 'node:path';
92
92
  import { spawnSync } from 'node:child_process';
93
+ import { createHash } from 'node:crypto';
93
94
  import { fileURLToPath, pathToFileURL } from 'node:url';
94
95
  import * as ac from './agent_cli.mjs';
95
96
  import * as answersCheck from './answers_check.mjs';
@@ -810,6 +811,8 @@ export function initState(hp, prompts, {
810
811
  host: _impl.host(), // NO_CANCEL_HOSTS get a longer stall limit (stallLimit)
811
812
  },
812
813
  width: Math.max(1, width), events: [], stopping: false, groups: {},
814
+ // each init (a new parent, a takeover) starts a new idle stretch for `wait` (idleKey)
815
+ inited_at: _now(),
813
816
  };
814
817
  for (const [gid, g] of groups) {
815
818
  st.groups[gid] = _row(hp, g, true);
@@ -1868,15 +1871,46 @@ export function bind(hp, unit, task) {
1868
1871
  const st = loadState(hp);
1869
1872
  if (!ac.truthy(st)) throw new ac.SystemExit('no queue: run `group_queue.mjs init` first');
1870
1873
  const t = _now();
1874
+ const finished = [];
1871
1875
  for (const gid of unit.split('+')) {
1872
1876
  if (!Object.hasOwn(st.groups, gid)) throw new ac.SystemExit(`unknown group id: ${gid}`);
1873
- Object.assign(st.groups[gid], { session: task, bound_at: t });
1877
+ // The report of this attempt already on disk at bind time AND the bind came long after the
1878
+ // lease: the dispatch call probably blocked until the agent finished, i.e. it ran in the
1879
+ // foreground (measured: a resume retried without `background: true` turned every later wave
1880
+ // into a barrier on its slowest group). A background dispatch returns its handle within
1881
+ // seconds, so a quick agent that reports before a prompt bind is not flagged.
1882
+ const g = st.groups[gid];
1883
+ if (g.state === 'running' && t - (g.started_at ?? t) >= FOREGROUND_MIN_GAP_S
1884
+ && _report(hp, gid, _reportSince(g))) finished.push(gid);
1885
+ // a new session starts with a clean context
1886
+ if (g.session !== task) delete g.context_exhausted;
1887
+ Object.assign(g, { session: task, bound_at: t });
1874
1888
  }
1875
1889
  _save(_statePath(hp), st);
1876
- return { bound: unit, task };
1890
+ if (finished.length === 0) return { bound: unit, task };
1891
+ return { bound: unit, task, foreground: finished, warning: FOREGROUND_WARNING };
1877
1892
  });
1878
1893
  }
1879
1894
 
1895
+ /** Lease→bind gap (s) above which a bind that finds the attempt's report suggests a foreground dispatch. */
1896
+ export const FOREGROUND_MIN_GAP_S = 300;
1897
+
1898
+ export const FOREGROUND_WARNING = 'Inferred, not confirmed: this unit had already written its report when it was '
1899
+ + `bound, more than ${FOREGROUND_MIN_GAP_S / 60} min after its lease, so its dispatch most likely ran in the `
1900
+ + 'foreground and blocked the queue until it finished. If you did dispatch it in the background, ignore this. '
1901
+ + 'Otherwise dispatch every unit, fresh or resumed, with '
1902
+ + '`background: true` (opencode v2: `subagent({ agent, background: true, sessionID })`; v1 / DevEco: '
1903
+ + '`task` with `background: true` and `task_id`), and keep it when retrying a failed call.';
1904
+
1905
+ /**
1906
+ * Host error text of a session that ran out of context. Resuming it only fails again, so the next
1907
+ * attempt of that group (automatic retry or `requeue`) starts a fresh session instead. Only "the input
1908
+ * exceeded / used up the context" counts: a mere mention of the context window ("output truncated to fit
1909
+ * the context window"), an output-token cap or a rate limit ("too many tokens per minute") keeps the
1910
+ * session, whose re-intake would cost 30-75 min.
1911
+ */
1912
+ export const CONTEXT_EXHAUSTED_RE = /context_length_exceeded|prompt is too long|maximum context length|exceed(?:s|ed|ing)?\b[^.\n]{0,40}\bcontext\b|context (?:window |length )?(?:is |was |has been )?(?:full|exhausted|exceeded)/i;
1913
+
1880
1914
  export const STALL_TWICE_HINT = 'Its session stalled twice. Do not requeue it fresh while that session may still '
1881
1915
  + 'be alive (opencode/DevEco cannot cancel it: two writers on one file). Resume it (`requeue` keeps its '
1882
1916
  + 'session by default) or wait for its completion notice, then decide.';
@@ -1904,13 +1938,16 @@ function _settle(hp, st, gid, { stalled = false, error = '', report = null } = {
1904
1938
  s.released_at = _now();
1905
1939
  delete s.next_session; // set again below only when this release resumes it
1906
1940
  if (isStall) s.stalls = (ac.get(s, 'stalls') ?? 0) + 1;
1941
+ // A session that ran out of context has ended and cannot take another turn: its next attempt is fresh.
1942
+ if (!report && error && CONTEXT_EXHAUSTED_RE.test(error)) s.context_exhausted = true;
1907
1943
  let next = null; // [message, resume session]
1908
1944
  if (isStall && s.stalls >= 2) {
1909
1945
  next = null; // resuming the same session stalled again: a human looks at it (row.needs)
1910
1946
  } else if ((row.action === 'retry' || row.action === 'resume') && s.attempts < MAX_ATTEMPTS) {
1911
1947
  // A stalled agent may still be alive (opencode/DevEco cannot cancel it): resuming its
1912
1948
  // own session queues behind it instead of starting a second writer.
1913
- next = [RESUME, ac.or(ac.get(s, 'session'), null)];
1949
+ next = [RESUME, ac.truthy(ac.get(s, 'context_exhausted')) ? null : ac.or(ac.get(s, 'session'), null)];
1950
+ if (!next[1]) delete s.context_exhausted;
1914
1951
  } else if (row.action === 'redispatch' && !ac.truthy(ac.get(s, 'narrowed'))) {
1915
1952
  s.narrowed = true;
1916
1953
  // name the files it never wrote: "write the anchor first" alone let an off-target report repeat itself
@@ -2153,30 +2190,75 @@ function _markJobExitSeen(hp, j) {
2153
2190
  } catch { /* advisory: at worst the exit is reported again */ }
2154
2191
  }
2155
2192
 
2193
+ // Wait news is reported once, remembered on disk like a job exit: a bound reviewer completing
2194
+ // (per bind), a skill-agent's report appearing (per bind), an intake ack covering its files (per
2195
+ // lease) and an unbound review part appearing. A snapshot taken when `wait` starts would miss one
2196
+ // that happened between two waits, while the parent was dispatching or verifying (one wait per
2197
+ // shell call makes those gaps common). Not .json: detach lists every *.json in jobs/ as a job.
2198
+ const _waitSeenFile = (hp) => path.join(detach._dir(hp), 'wait.seen');
2199
+
2200
+ export function _waitSeen(hp) {
2201
+ try {
2202
+ const doc = JSON.parse(fs.readFileSync(_waitSeenFile(hp), 'utf8'));
2203
+ return new Set(Array.isArray(doc) ? doc : []);
2204
+ } catch {
2205
+ return new Set();
2206
+ }
2207
+ }
2208
+
2209
+ /** Remember `keys` as reported; keep only keys still `live`, so the file stays small. */
2210
+ function _markWaitSeen(hp, keys, live) {
2211
+ const old = _waitSeen(hp);
2212
+ const next = [...new Set([...[...old].filter((k) => live.has(k)), ...keys])];
2213
+ if (!keys.length && next.length === old.size) return;
2214
+ try {
2215
+ fs.mkdirSync(detach._dir(hp), { recursive: true });
2216
+ fs.writeFileSync(_waitSeenFile(hp), JSON.stringify(next));
2217
+ } catch { /* advisory: at worst an event is reported again */ }
2218
+ }
2219
+
2156
2220
  /**
2157
2221
  * Block until a slot can be refilled or something needs the parent: a running group's
2158
2222
  * report appeared, a unit went silent, a background job (detach.mjs) left `running`,
2159
2223
  * a reviewer's answers file is complete or silent, or there is a free slot with a
2160
2224
  * ready unit. Returns at once when that is already true.
2161
2225
  */
2162
- export async function wait(hp, { timeoutS = 540, pollS = 5, jobs = [], answers = [] } = {}) {
2163
- const end = _now() + timeoutS;
2226
+ // One `wait` is one blocking shell call, and the host queues every completion notification
2227
+ // until it returns: keep it short. A trace measured a parent that wrapped 12 waits in one shell
2228
+ // loop and held the foreground for an hour while group_pass kept printing dispatches.
2229
+ export const WAIT_CAP_S = 300;
2230
+
2231
+ /**
2232
+ * One idle stretch of the queue: every group's state and start time, plus the init that made the
2233
+ * state. A group leased again gets a new started_at even if it ends in the same state, and a new
2234
+ * parent (init, --takeover) gets a new inited_at, so each sees its first idle reported.
2235
+ */
2236
+ export function idleKeyOf(st) {
2237
+ const rows = Object.entries(ac.get(st, 'groups', {})).sort(([a], [b]) => cmpStr(a, b))
2238
+ .map(([g, s]) => [g, s.state, ac.get(s, 'started_at', null)]);
2239
+ const h = createHash('sha1').update(JSON.stringify([ac.get(st, 'inited_at', null), rows])).digest('hex').slice(0, 16);
2240
+ return `idle:${h}`;
2241
+ }
2242
+
2243
+ /** When a wait started at `start` (seconds) must return: `timeoutS` later, never past the cap. */
2244
+ export function waitDeadline(start, timeoutS) {
2245
+ const t = Number.isFinite(timeoutS) && timeoutS >= 0 ? timeoutS : WAIT_CAP_S; // NaN would never time out
2246
+ return start + Math.min(t, WAIT_CAP_S);
2247
+ }
2248
+
2249
+ export async function wait(hp, { timeoutS = WAIT_CAP_S, pollS = 5, jobs = [], answers = [] } = {}) {
2250
+ const end = waitDeadline(_now(), timeoutS);
2164
2251
  const answersCheck = await import('./answers_check.mjs');
2165
- // bound reviewers whose answers are open now: one that completes during this wait is news
2166
- const initiallyOpen = new Set(watchedAnswers(hp, [])
2167
- .filter((w) => !answersCheck.answersDone(w.answers).complete).map((w) => w.answers));
2168
2252
  // M5: a group in its evidence-intake step whose ack now covers every file is ready for its
2169
2253
  // conversion task; the ack alone used to wake nothing, so a parent in `wait` sat to the timeout.
2170
2254
  const intakeReading = (st0) => Object.entries(ac.get(st0 ?? {}, 'groups', {}))
2171
2255
  .filter(([, s]) => s.state === 'running' && ac.isDict(s.intake) && s.intake.state === 'reading');
2256
+ const intakeKey = ([g, s]) => `intake:${g}@${ac.get(s.intake, 'leased_at') ?? ''}`;
2172
2257
  const intakeAcked = (st0) => intakeReading(st0)
2173
- .filter(([g, s]) => eg.ackStatus(hp, g, ac.get(s.intake, 'leased_at') ?? 0).ok).map(([g]) => g);
2174
- const initiallyAcked = new Set(intakeAcked(loadState(hp)));
2175
- const initiallyDoneAgents = new Set(watchedAgents(hp).filter((a) => a.done).map((a) => a.name));
2258
+ .filter(([g, s]) => eg.ackStatus(hp, g, ac.get(s.intake, 'leased_at') ?? 0).ok);
2176
2259
  // T5: review parts the explorer waits on (capture_pending.json `reviews`) that no reviewer was
2177
2260
  // bound to: a run_cycle that follows its answers (--follow-min) does not exit to say so.
2178
2261
  const unboundReviews = () => unboundReviewParts(hp);
2179
- const initiallyUnbound = new Set(unboundReviews());
2180
2262
  let lastRefresh = null;
2181
2263
  for (;;) {
2182
2264
  touchParent(hp); // the parent is alive while it waits: a crashed one stops beating
@@ -2206,32 +2288,57 @@ export async function wait(hp, { timeoutS = 540, pollS = 5, jobs = [], answers =
2206
2288
  && !_jobExitSeen(hp, j));
2207
2289
  if (jobsDone.length) reasons.push('job');
2208
2290
  const watched = watchedAnswers(hp, answers);
2209
- const ans = watched.map((w) => ({ ...answersCheck.answersDone(w.answers), since: w.since, explicit: w.explicit }));
2291
+ const ans = watched.map((w) => ({ ...answersCheck.answersDone(w.answers), since: w.since, explicit: w.explicit, key: `answers:${w.answers}@${w.since ?? ''}` }));
2210
2292
  const limit = r.stall_limit_min * 60; // a reviewer is silent by the same load-scaled limit
2211
- // explicit files report completion as before; a bound reviewer only when it completed during this wait
2212
- const ansDone = ans.filter((a) => a.complete && (a.explicit || initiallyOpen.has(a.answers))).map((a) => a.answers);
2293
+ // explicit files report completion as before; a bound reviewer once per bind, even when it
2294
+ // completed between two waits
2295
+ const seen = _waitSeen(hp);
2296
+ const ansDoneRows = ans.filter((a) => a.complete && (a.explicit || !seen.has(a.key)));
2297
+ const ansDone = ansDoneRows.map((a) => a.answers);
2213
2298
  // no file yet: silent counted from its bind (measured: a reviewer that never wrote was never reported)
2214
2299
  const ansSilent = ans.filter((a) => {
2215
2300
  const last = Math.max(a.mtime ?? 0, a.since ?? 0);
2216
2301
  return !a.complete && last > 0 && _now() - last >= limit;
2217
2302
  }).map((a) => a.answers);
2218
2303
  if (ansDone.length) reasons.push('answers');
2219
- const acked = ac.truthy(st) ? intakeAcked(st).filter((g) => !initiallyAcked.has(g)) : [];
2304
+ const ackRows = ac.truthy(st) ? intakeAcked(st).filter((e) => !seen.has(intakeKey(e))) : [];
2305
+ const acked = ackRows.map(([g]) => g);
2220
2306
  if (acked.length) reasons.push('intake');
2221
2307
  const agents = watchedAgents(hp);
2222
2308
  const agentLimit = Math.max(AGENT_SILENT_MIN, AGENT_SILENT_FACTOR * r.stall_limit_min) * 60;
2223
- const agentsDone = agents.filter((a) => a.done && !initiallyDoneAgents.has(a.name)).map((a) => a.name);
2309
+ const agentKey = (a) => `agent:${a.name}@${a.since ?? ''}`;
2310
+ const agentsDone = agents.filter((a) => a.done && !seen.has(agentKey(a))).map((a) => a.name);
2224
2311
  const agentsSilent = agents.filter((a) => !a.done && a.since && _now() - a.since >= agentLimit).map((a) => a.name);
2225
- const newReviews = unboundReviews().filter((f) => !initiallyUnbound.has(f));
2312
+ const unbound = unboundReviews();
2313
+ const newReviews = unbound.filter((f) => !seen.has(`review:${f}`));
2226
2314
  if (newReviews.length) reasons.push('reviews');
2227
2315
  if (agentsDone.length) reasons.push('agent');
2228
2316
  if (agentsSilent.length) reasons.push('agent-silent');
2229
2317
  if (ansSilent.length) reasons.push('answers-silent');
2230
2318
  const sum = ac.truthy(st) ? summary(st, plan, exploring) : null;
2231
2319
  if (sum && sum.free_slots > 0 && (sum.ready_units > 0 || sum.backfill_units > 0)) reasons.push('slots');
2232
- if (sum && sum.idle) reasons.push('idle');
2320
+ // An idle queue is news once per idle stretch (keyed by the group counts, which change when the
2321
+ // queue moves). After that, while a bound skill agent or reviewer is still at work, `wait` blocks
2322
+ // for it instead of returning `idle` at once. Measured (coolmall 12-03): after Step 5.4 every
2323
+ // wait for the wiring / verify agent returned `idle` in 1 s, and the parent fell back to
2324
+ // `Start-Sleep 280` six times, picking up the verify report 257 s late.
2325
+ const idleKey = sum && sum.idle ? idleKeyOf(st) : null;
2326
+ // what the parent can still wait for: unreported agents, unanswered files (bound or --answers),
2327
+ // --job jobs still running. A reviewer whose agent ended unanswered stays here until review-unbind.
2328
+ const waitingOn = [
2329
+ ...agents.filter((a) => !a.done).map((a) => `agent:${a.name}`),
2330
+ ...ans.filter((a) => !a.complete).map((a) => `answers:${a.answers}`),
2331
+ ...jobs.filter((j) => ac.get(ac.get(js, j, {}), 'state') === 'running').map((j) => `job:${j}`),
2332
+ ];
2333
+ const idleNews = idleKey !== null && !(seen.has(idleKey) && waitingOn.length);
2334
+ if (idleNews) reasons.push('idle');
2233
2335
  if (reasons.length || _now() >= end) {
2234
2336
  for (const j of jobsDone) _markJobExitSeen(hp, j);
2337
+ const live = new Set([...ans.map((a) => a.key), ...agents.map(agentKey), ...(idleKey ? [idleKey] : []),
2338
+ ...(ac.truthy(st) ? intakeReading(st).map(intakeKey) : []), ...unbound.map((f) => `review:${f}`)]);
2339
+ _markWaitSeen(hp, [...ansDoneRows.filter((a) => !a.explicit).map((a) => a.key),
2340
+ ...agents.filter((a) => agentsDone.includes(a.name)).map(agentKey),
2341
+ ...ackRows.map(intakeKey), ...newReviews.map((f) => `review:${f}`), ...(idleNews ? [idleKey] : [])], live);
2235
2342
  return { reasons: reasons.length ? reasons : ['timeout'], reported: r.reported, stalled: r.stalled,
2236
2343
  stall_limit_min: r.stall_limit_min,
2237
2344
  jobs: Object.fromEntries(jobs.map((j) => {
@@ -2240,6 +2347,8 @@ export async function wait(hp, { timeoutS = 540, pollS = 5, jobs = [], answers =
2240
2347
  })),
2241
2348
  answers_complete: ansDone, answers_silent: ansSilent, ...(acked.length ? { intake_acked: acked } : {}),
2242
2349
  ...(agentsDone.length ? { agents_done: agentsDone } : {}), ...(agentsSilent.length ? { agents_silent: agentsSilent } : {}),
2350
+ // idle already reported and held back by these: the parent sees what a `timeout` waited on
2351
+ ...(idleKey !== null && !idleNews ? { waiting_on: waitingOn } : {}),
2243
2352
  ...(newReviews.length ? { reviews_to_dispatch: newReviews } : {}),
2244
2353
  ...(lastRefresh ? { plan_refresh: lastRefresh } : {}), summary: sum };
2245
2354
  }
@@ -2311,15 +2420,22 @@ export function control(hp, cmd) {
2311
2420
  if (s.state === 'running') throw new ac.SystemExit(`${gid} is running: release it first`);
2312
2421
  const fresh = ac.truthy(ac.get(cmd, 'fresh'));
2313
2422
  const alive = _stalledSession(s);
2423
+ // A returned group that failed verification resumes its own session: it still holds the evidence it
2424
+ // read and the files it wrote (measured: fresh re-intakes re-read every frame, 30-75 min a group).
2425
+ const returned = s.state === 'returned';
2426
+ // ...unless that session ran out of context (its release error said so): resuming it would fail again.
2427
+ const exhausted = ac.truthy(ac.get(s, 'context_exhausted'));
2314
2428
  Object.assign(s, { state: 'queued', next_message: ac.get(cmd, 'message') });
2315
2429
  // an unfinished intake (failed or never accepted) starts over: new manifest, rounds and ack window
2316
2430
  if (ac.truthy(s.intake) && _intakeState(s) !== 'done') delete s.intake;
2317
2431
  delete s.intake_unbound;
2318
- if (!fresh && ac.truthy(s.session) && (ac.truthy(ac.get(cmd, 'resume')) || alive)) {
2432
+ if (!fresh && !exhausted && ac.truthy(s.session) && (ac.truthy(ac.get(cmd, 'resume')) || alive || returned)) {
2319
2433
  s.next_session = s.session;
2320
2434
  out.resume_task = s.session;
2321
2435
  } else {
2322
2436
  delete s.next_session;
2437
+ delete s.context_exhausted;
2438
+ if (exhausted && !fresh) out.fresh_reason = 'context-exhausted';
2323
2439
  if (fresh && alive) {
2324
2440
  Object.assign(out, { stop_first: true, warning: `${gid}'s session ${s.session} stalled and may still be `
2325
2441
  + 'running: dispatch the fresh attempt only after that session has ended (its completion notice '
@@ -2510,7 +2626,7 @@ total throughput instead (~1.3 turns/min measured earlier) wants a lower --width
2510
2626
  group_queue.mjs reap <harmony_dir>
2511
2627
  group_queue.mjs review-bind <harmony_dir> --name <part> --answers <path> [--task <id>] [--kind reviewer]
2512
2628
  group_queue.mjs review-unbind <harmony_dir> --name <part> # the reviewer ended without its answers
2513
- group_queue.mjs wait <harmony_dir> [--timeout-s 540] [--job run_cycle] [--answers <file>]
2629
+ group_queue.mjs wait <harmony_dir> [--timeout-s 300] [--job run_cycle] [--answers <file>]
2514
2630
  group_queue.mjs status <harmony_dir> [--assert-settled] # exit 1 while a group is still open
2515
2631
  group_queue.mjs refresh <harmony_dir> [--force]
2516
2632
  group_queue.mjs verified <harmony_dir> --group G007 [--summary "..."] # also marks its pages done in batch_progress.json
@@ -2565,7 +2681,7 @@ export async function main(argv = process.argv.slice(2)) {
2565
2681
  { flags: ['--kind'], default: 'reviewer', help: 'review-bind: reviewer (counts against --max-agents) or skill-agent' },
2566
2682
  { flags: ['--stalled'], action: 'store_true', help: 'release: the unit was reaped as silent' },
2567
2683
  { flags: ['--error'], default: '', help: "release: the agent's error text, if it failed" },
2568
- { flags: ['--timeout-s'], type: 'float', default: 540 },
2684
+ { flags: ['--timeout-s'], type: 'float', default: 300 },
2569
2685
  { flags: ['--job'], action: 'append', default: [], help: 'wait: also return when this detach.mjs job ends' },
2570
2686
  { flags: ['--answers'], action: 'append', default: [],
2571
2687
  help: 'wait: also return when this answers file is complete; review-bind: the answers path of the part' },
@@ -8,11 +8,16 @@
8
8
  * the v1 `task` tool to `subagent`.) So a v2 host is always `background_ready` and must never
9
9
  * be sent into an enable/restart loop or degraded to blocking waves.
10
10
  *
11
- * opencode v1 (>= 1.16.2) and DevEco Code 0.2.0-3 reject `task(background: true)` unless
12
- * OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS / DEVECO_EXPERIMENTAL_BACKGROUND_SUBAGENTS
13
- * is "true". The host reads them once, at start-up: nothing run inside a session can
14
- * turn them on for that session. `enable` therefore writes them to the user's
15
- * environment and the session has to be restarted once. Claude Code needs neither.
11
+ * opencode v1 (>= 1.16.2) rejects `task(background: true)` unless
12
+ * OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS is "true". The host reads it once, at start-up:
13
+ * nothing run inside a session can turn it on for that session. `enable` therefore writes it
14
+ * to the user's environment and the session has to be restarted once. Claude Code needs neither.
15
+ *
16
+ * DevEco Code checks DEVECO_EXPERIMENTAL_BACKGROUND_SUBAGENTS too, but the flag DEFAULTS TO ON
17
+ * (verified in the 0.3.0-23 binary: `experimentalBackgroundSubagents = DEVECO_EXPERIMENTAL ||
18
+ * DEVECO_EXPERIMENTAL_BACKGROUND_SUBAGENTS`, the latter defaulting to true when unset). So a
19
+ * DevEco session is ready unless the user explicitly turned the flag off ("false" / "0");
20
+ * only then does `check` ask for `enable` + restart.
16
21
  *
17
22
  * `check` tells the two apart by the opencode major version (`opencode --version`, or
18
23
  * $OPENCODE_VERSION): >= 2 -> native; 1.x / undetectable -> the v1 flag path below.
@@ -129,10 +134,25 @@ export function persisted() {
129
134
  return out;
130
135
  }
131
136
 
137
+ const ON = /^(true|1)$/i;
138
+ const OFF = /^(false|0)$/i;
139
+
140
+ /**
141
+ * Is background dispatch on for this session, per flag? opencode v1: only an explicit "true".
142
+ * DevEco: on unless explicitly "false" / "0" (default on), or forced on by DEVECO_EXPERIMENTAL.
143
+ */
144
+ export function activeFlags(env) {
145
+ const v = (n) => String(ac.get(env, n) ?? '').trim();
146
+ return {
147
+ [FLAGS.opencode]: ON.test(v(FLAGS.opencode)),
148
+ [FLAGS.deveco]: ON.test(v('DEVECO_EXPERIMENTAL')) || !OFF.test(v(FLAGS.deveco)),
149
+ };
150
+ }
151
+
132
152
  export function check() {
133
153
  const env = _impl.env();
134
154
  const h = host(env);
135
- const active = Object.fromEntries(Object.values(FLAGS).map((n) => [n, ac.get(env, n) === 'true']));
155
+ const active = activeFlags(env);
136
156
  const saved = persisted();
137
157
  // opencode v2+ runs background sub-agents natively; the experimental flag is a v1 mechanism
138
158
  // that v2 ignores. Detect it so a v2 host is never sent into an enable/restart loop or
@@ -144,8 +164,12 @@ export function check() {
144
164
  if (h === 'claude') action = 'none: Claude Code runs Agent sub-agents in the background natively';
145
165
  else if (native) action = `none: opencode v${version} runs background sub-agents natively (`
146
166
  + '`subagent` with `background: true`); no flag needed — the experimental flag is a v1 mechanism';
167
+ else if (h === 'deveco' && active[FLAGS.deveco]) action = 'none: DevEco Code enables background sub-agents by default';
147
168
  else if (h !== 'unknown' && active[FLAGS[h]]) action = 'none: background sub-agents are enabled in this session';
148
169
  else if (h !== 'unknown' && saved[FLAGS[h]]) action = 'restart: the flag is saved but this session started before it; quit and restart the host session (on Windows from a new terminal)';
170
+ else if (h === 'deveco') action = `enable: ${FLAGS.deveco} is set to "${ac.get(env, FLAGS.deveco)}" (turned off; it is on by default): `
171
+ + 'ask the user to remove that setting (preferred — nothing else changes), then restart the host session; '
172
+ + '`node host_env.mjs enable` also works but writes the opencode flag too';
149
173
  else action = 'enable: run `node host_env.mjs enable`, then restart the host session';
150
174
  const ok = h === 'claude' || native || (h !== 'unknown' && active[FLAGS[h]]);
151
175
  // `opencode` on PATH need not be the binary running this session (desktop app vs npm global,
@@ -188,8 +212,8 @@ export function disable() {
188
212
  return { disabled: names, where: f };
189
213
  }
190
214
 
191
- const DOC = `Check / persist background sub-agent support. opencode v2 is native (no flag); opencode v1
192
- and DevEco Code use an env flag that this persists.
215
+ const DOC = `Check / persist background sub-agent support. opencode v2 is native (no flag); DevEco Code
216
+ has it on by default (only an explicit "false" turns it off); opencode v1 needs an env flag that this persists.
193
217
 
194
218
  host_env.mjs check | enable | disable
195
219
  `;