okstra 0.232.0 → 0.234.0
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/README.md +19 -283
- package/dist/cli-registry.mjs +14 -1
- package/dist/cli-registry.mjs.map +1 -1
- package/dist/commands/execute/render-bundle.d.mts +6 -1
- package/dist/commands/execute/render-bundle.mjs +139 -32
- package/dist/commands/execute/render-bundle.mjs.map +1 -1
- package/dist/commands/lifecycle/config.mjs +6 -74
- package/dist/commands/lifecycle/config.mjs.map +1 -1
- package/dist/commands/trace/capacity.d.mts +12 -0
- package/dist/commands/trace/capacity.mjs +21 -0
- package/dist/commands/trace/capacity.mjs.map +1 -0
- package/dist/commands/trace/model.d.mts +89 -0
- package/dist/commands/trace/model.mjs +251 -0
- package/dist/commands/trace/model.mjs.map +1 -0
- package/dist/commands/trace/progression.d.mts +11 -0
- package/dist/commands/trace/progression.mjs +194 -0
- package/dist/commands/trace/progression.mjs.map +1 -0
- package/dist/commands/trace/review.d.mts +7 -0
- package/dist/commands/trace/review.mjs +51 -0
- package/dist/commands/trace/review.mjs.map +1 -0
- package/dist/commands/trace/task-link.d.mts +18 -0
- package/dist/commands/trace/task-link.mjs +72 -0
- package/dist/commands/trace/task-link.mjs.map +1 -0
- package/dist/commands/trace/trace.d.mts +1 -0
- package/dist/commands/trace/trace.mjs +293 -0
- package/dist/commands/trace/trace.mjs.map +1 -0
- package/dist/lib/bounded-file.d.mts +1 -0
- package/dist/lib/bounded-file.mjs +36 -0
- package/dist/lib/bounded-file.mjs.map +1 -0
- package/dist/lib/config-store.d.mts +34 -0
- package/dist/lib/config-store.mjs +70 -0
- package/dist/lib/config-store.mjs.map +1 -0
- package/dist/lib/file-lock.mjs +4 -5
- package/dist/lib/file-lock.mjs.map +1 -1
- package/dist/lib/input-limit.d.mts +4 -0
- package/dist/lib/input-limit.mjs +8 -0
- package/dist/lib/input-limit.mjs.map +1 -0
- package/dist/lib/memory-auto-register.mjs +2 -17
- package/dist/lib/memory-auto-register.mjs.map +1 -1
- package/dist/lib/report-language-tag.d.mts +1 -0
- package/dist/lib/report-language-tag.mjs +4 -0
- package/dist/lib/report-language-tag.mjs.map +1 -0
- package/dist/lib/report-language.d.mts +1 -0
- package/dist/lib/report-language.mjs +50 -0
- package/dist/lib/report-language.mjs.map +1 -0
- package/dist/lib/skill-catalog.mjs +3 -0
- package/dist/lib/skill-catalog.mjs.map +1 -1
- package/docs/architecture/storage-model.md +55 -5
- package/docs/architecture.md +10 -4
- package/docs/cli.md +320 -3
- package/docs/contributor-change-matrix.md +1 -2
- package/docs/project-structure-overview.md +34 -43
- package/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/operations/trace-interface-review.json +6 -0
- package/runtime/agents/operations/trace-scope-review.json +6 -0
- package/runtime/prompts/coding-preflight/authoring-checks.md +1 -1
- package/runtime/prompts/coding-preflight/clean-code.md +18 -20
- package/runtime/prompts/coding-preflight/overview.md +1 -1
- package/runtime/prompts/duties/code-reviewer.json +1 -1
- package/runtime/prompts/duties/interface-reviewer.json +32 -0
- package/runtime/prompts/host-orchestration/README.md +18 -9
- package/runtime/prompts/launch.template.md +3 -2
- package/runtime/prompts/lead/context-loader.md +2 -0
- package/runtime/prompts/lead/okstra-lead-contract.md +7 -7
- package/runtime/prompts/lead/report-writer.md +6 -6
- package/runtime/prompts/profiles/_coding-conventions-preflight.md +2 -2
- package/runtime/prompts/profiles/_common-contract.md +1 -1
- package/runtime/python/okstra_ctl/agent/invocation.py +1 -0
- package/runtime/python/okstra_ctl/agent/prompt_cli/cli.py +66 -26
- package/runtime/python/okstra_ctl/agent/prompt_cli/corrections.py +23 -8
- package/runtime/python/okstra_ctl/agent/prompt_cli/materialize.py +28 -10
- package/runtime/python/okstra_ctl/agent/prompt_cli/results.py +8 -11
- package/runtime/python/okstra_ctl/agent/standalone.py +12 -0
- package/runtime/python/okstra_ctl/analysis_packet.py +22 -11
- package/runtime/python/okstra_ctl/business_flow/cli.py +60 -6
- package/runtime/python/okstra_ctl/business_flow/contracts.py +12 -1
- package/runtime/python/okstra_ctl/business_flow/engine.py +17 -5
- package/runtime/python/okstra_ctl/business_flow/history.py +60 -0
- package/runtime/python/okstra_ctl/business_flow/source.py +35 -2
- package/runtime/python/okstra_ctl/business_flow/store.py +51 -14
- package/runtime/python/okstra_ctl/business_flow/sweep.py +124 -0
- package/runtime/python/okstra_ctl/code_review_census.py +93 -2
- package/runtime/python/okstra_ctl/code_review_prepare.py +381 -0
- package/runtime/python/okstra_ctl/code_review_run.py +384 -0
- package/runtime/python/okstra_ctl/code_review_scope.py +13 -0
- package/runtime/python/okstra_ctl/code_review_supervisor.py +41 -0
- package/runtime/python/okstra_ctl/code_review_target.py +140 -15
- package/runtime/python/okstra_ctl/coverage_census.py +11 -2
- package/runtime/python/okstra_ctl/design_snapshot.py +16 -9
- package/runtime/python/okstra_ctl/direct_work.py +45 -3
- package/runtime/python/okstra_ctl/dispatch_core.py +31 -15
- package/runtime/python/okstra_ctl/dispatch_state.py +9 -2
- package/runtime/python/okstra_ctl/domain/role.py +1 -0
- package/runtime/python/okstra_ctl/doyouknow/cli.py +9 -9
- package/runtime/python/okstra_ctl/doyouknow/config.py +2 -2
- package/runtime/python/okstra_ctl/doyouknow/group_view.py +152 -0
- package/runtime/python/okstra_ctl/doyouknow/source_contracts.py +4 -3
- package/runtime/python/okstra_ctl/doyouknow/source_store.py +2 -2
- package/runtime/python/okstra_ctl/doyouknow/sources/business.py +116 -0
- package/runtime/python/okstra_ctl/doyouknow/sources/manager.py +48 -9
- package/runtime/python/okstra_ctl/doyouknow/sync.py +34 -9
- package/runtime/python/okstra_ctl/final_report_schema.py +37 -34
- package/runtime/python/okstra_ctl/fixed_text.py +10 -0
- package/runtime/python/okstra_ctl/incremental_carry.py +6 -7
- package/runtime/python/okstra_ctl/initial_prompt_materialization.py +9 -2
- package/runtime/python/okstra_ctl/json_boundary.py +33 -6
- package/runtime/python/okstra_ctl/manager_cli.py +122 -1
- package/runtime/python/okstra_ctl/manager_journal.py +126 -0
- package/runtime/python/okstra_ctl/manager_launch.py +3 -3
- package/runtime/python/okstra_ctl/manager_log.py +221 -0
- package/runtime/python/okstra_ctl/manager_paths.py +8 -0
- package/runtime/python/okstra_ctl/manager_resume.py +59 -0
- package/runtime/python/okstra_ctl/manager_split.py +2 -2
- package/runtime/python/okstra_ctl/manager_store.py +116 -17
- package/runtime/python/okstra_ctl/manager_sync.py +42 -3
- package/runtime/python/okstra_ctl/manager_view.py +35 -2
- package/runtime/python/okstra_ctl/material.py +2 -0
- package/runtime/python/okstra_ctl/model_cli.py +64 -14
- package/runtime/python/okstra_ctl/model_defaults.py +22 -0
- package/runtime/python/okstra_ctl/model_io/renderers.py +3 -0
- package/runtime/python/okstra_ctl/operation_invocation.py +207 -28
- package/runtime/python/okstra_ctl/path_hints.py +14 -3
- package/runtime/python/okstra_ctl/paths.py +6 -1
- package/runtime/python/okstra_ctl/phases/catalog.py +24 -7
- package/runtime/python/okstra_ctl/phases/implementation/host-rules.md +3 -3
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-diff-review.md +8 -6
- package/runtime/python/okstra_ctl/phases/implementation/instructions/_implementation-self-check.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/profile.md +1 -1
- package/runtime/python/okstra_ctl/phases/implementation_option_selection/votes.py +11 -11
- package/runtime/python/okstra_ctl/phases/implementation_planning/authoring.py +12 -9
- package/runtime/python/okstra_ctl/phases/implementation_planning/host-rules.md +3 -6
- package/runtime/python/okstra_ctl/phases/implementation_planning/instructions/plan-body-verification.md +12 -10
- package/runtime/python/okstra_ctl/phases/implementation_planning/profile.md +5 -5
- package/runtime/python/okstra_ctl/phases/improvement_discovery/lenses.py +12 -0
- package/runtime/python/okstra_ctl/phases/improvement_discovery/profile.md +7 -6
- package/runtime/python/okstra_ctl/phases/improvement_discovery/resolved_census.py +159 -0
- package/runtime/python/okstra_ctl/phases/improvement_discovery/spec.md +5 -2
- package/runtime/python/okstra_ctl/phases/improvement_discovery/validation.py +21 -7
- package/runtime/python/okstra_ctl/phases/release_handoff/boundary.json +1 -1
- package/runtime/python/okstra_ctl/phases/release_handoff/profile.md +4 -1
- package/runtime/python/okstra_ctl/plan_verify_cli.py +6 -4
- package/runtime/python/okstra_ctl/project_group.py +175 -0
- package/runtime/python/okstra_ctl/project_group_cli.py +62 -0
- package/runtime/python/okstra_ctl/render.py +28 -2
- package/runtime/python/okstra_ctl/report_assembly.py +38 -11
- package/runtime/python/okstra_ctl/report_contract.py +26 -0
- package/runtime/python/okstra_ctl/report_corrections.py +36 -20
- package/runtime/python/okstra_ctl/report_inputs.py +1 -0
- package/runtime/python/okstra_ctl/report_language.py +4 -1
- package/runtime/python/okstra_ctl/report_narrative.py +179 -7
- package/runtime/python/okstra_ctl/report_projections.py +64 -18
- package/runtime/python/okstra_ctl/report_synthesis_packet.py +86 -36
- package/runtime/python/okstra_ctl/run.py +43 -35
- package/runtime/python/okstra_ctl/run_context.py +10 -1
- package/runtime/python/okstra_ctl/set_work_status.py +4 -15
- package/runtime/python/okstra_ctl/task_list_cli.py +34 -8
- package/runtime/python/okstra_ctl/task_query.py +239 -0
- package/runtime/python/okstra_ctl/trace_review.py +264 -0
- package/runtime/python/okstra_ctl/trace_tasks.py +197 -0
- package/runtime/python/okstra_ctl/user_authorization.py +14 -0
- package/runtime/python/okstra_ctl/wizard/confirmation.py +7 -3
- package/runtime/python/okstra_ctl/wizard/launch.py +52 -0
- package/runtime/python/okstra_ctl/wizard/launch_cli.py +39 -0
- package/runtime/python/okstra_ctl/wizard/outcome.py +17 -16
- package/runtime/python/okstra_ctl/wizard/registry.py +1 -1
- package/runtime/python/okstra_ctl/wizard/render.py +8 -0
- package/runtime/python/okstra_ctl/wizard/state.py +2 -1
- package/runtime/python/okstra_project/state.py +20 -0
- package/runtime/python/okstra_token_usage/blocks.py +74 -0
- package/runtime/python/okstra_token_usage/cli.py +23 -10
- package/runtime/python/okstra_token_usage/collect.py +25 -22
- package/runtime/python/okstra_token_usage/policy.py +193 -0
- package/runtime/schemas/business-flow-v1.schema.json +3 -0
- package/runtime/schemas/doyouknow-config-v1.schema.json +1 -1
- package/runtime/schemas/report-synthesis-packet-v1.0.schema.json +1 -1
- package/runtime/skills/_fragments/wizard-confirm-step.md +1 -1
- package/runtime/skills/_fragments/wizard-preflight.md +1 -1
- package/runtime/skills/_fragments/wizard-prompt-loop.md +3 -5
- package/runtime/skills/_fragments/wizard-relay-protocol.md +1 -1
- package/runtime/skills/_fragments/wizard-render-bundle.md +15 -29
- package/runtime/skills/okstra-brief-gen/SKILL.md +7 -7
- package/runtime/skills/okstra-brief-gen/references/tracker-recursion.md +1 -1
- package/runtime/skills/okstra-code-review/SKILL.md +58 -50
- package/runtime/skills/okstra-code-review/references/census-rules.md +6 -6
- package/runtime/skills/okstra-code-review/references/review-calibration.md +8 -12
- package/runtime/skills/okstra-discussion/SKILL.md +22 -38
- package/runtime/skills/okstra-explain-flow/SKILL.md +33 -4
- package/runtime/skills/okstra-manager/SKILL.md +24 -0
- package/runtime/skills/okstra-memory/SKILL.md +1 -1
- package/runtime/skills/okstra-pr-gen/SKILL.md +1 -1
- package/runtime/skills/okstra-run/SKILL.md +55 -183
- package/runtime/skills/okstra-schedule-gen/SKILL.md +9 -13
- package/runtime/skills/okstra-setup/SKILL.md +3 -2
- package/runtime/skills/okstra-setup/references/project-config.md +2 -4
- package/runtime/skills/okstra-tdd/SKILL.md +187 -0
- package/runtime/skills/okstra-user-response/SKILL.md +4 -2
- package/runtime/templates/doyouknow/group-view.css +103 -0
- package/runtime/templates/doyouknow/group-view.js +317 -0
- package/runtime/templates/doyouknow/group-view.template.html +72 -0
- package/runtime/templates/manager/view.template.html +4 -0
- package/runtime/templates/report-writer-prompt-preamble.md +15 -3
- package/runtime/templates/trace/trace.template.md +42 -0
- package/runtime/validators/checks/fixtures-02.py +25 -33
- package/runtime/validators/validate-run.py +93 -36
|
@@ -20,7 +20,7 @@ from typing import Any, Mapping, Sequence
|
|
|
20
20
|
|
|
21
21
|
from .convergence_provenance import id_occurs_wordbounded
|
|
22
22
|
from .json_boundary import JsonBoundaryError, load_owned_object
|
|
23
|
-
from .phases.improvement_discovery.lenses import LENSES
|
|
23
|
+
from .phases.improvement_discovery.lenses import LENSES, validate_priority_lenses
|
|
24
24
|
from .scope_provenance import brief_end_state_id_sequence
|
|
25
25
|
|
|
26
26
|
|
|
@@ -89,6 +89,7 @@ def build_census(
|
|
|
89
89
|
aspects: Sequence[Aspect],
|
|
90
90
|
requirement_ids: Sequence[str],
|
|
91
91
|
changed_files: Sequence[str] = (),
|
|
92
|
+
selected_lenses: Sequence[str] | None = None,
|
|
92
93
|
) -> dict[str, Any]:
|
|
93
94
|
"""Every cell for this run, in the order a worker should walk them."""
|
|
94
95
|
cells: list[dict[str, str]] = []
|
|
@@ -114,8 +115,14 @@ def build_census(
|
|
|
114
115
|
for index, path in enumerate(sorted(set(filter(None, changed_files))), start=1):
|
|
115
116
|
for aspect in by_scope["file"]:
|
|
116
117
|
add(f"C-F-{index:03d}-{aspect.slug}", aspect, path)
|
|
118
|
+
lenses = LENSES
|
|
119
|
+
if selected_lenses is not None:
|
|
120
|
+
try:
|
|
121
|
+
lenses = validate_priority_lenses(selected_lenses)
|
|
122
|
+
except ValueError as exc:
|
|
123
|
+
raise CensusError(str(exc)) from exc
|
|
117
124
|
for aspect in by_scope["lens"]:
|
|
118
|
-
for lens in
|
|
125
|
+
for lens in lenses:
|
|
119
126
|
add(f"C-L-{lens}", aspect, lens)
|
|
120
127
|
return {
|
|
121
128
|
"schemaVersion": CENSUS_SCHEMA_VERSION,
|
|
@@ -130,6 +137,7 @@ def census_for_run(
|
|
|
130
137
|
profile_text: str,
|
|
131
138
|
brief_path: Path,
|
|
132
139
|
changed_files: Sequence[str] = (),
|
|
140
|
+
selected_lenses: Sequence[str] | None = None,
|
|
133
141
|
) -> dict[str, Any] | None:
|
|
134
142
|
"""The run's census, or ``None`` when the phase profile declares none."""
|
|
135
143
|
aspects = parse_census_aspects(profile_text)
|
|
@@ -140,6 +148,7 @@ def census_for_run(
|
|
|
140
148
|
aspects=aspects,
|
|
141
149
|
requirement_ids=brief_end_state_id_sequence(brief_path),
|
|
142
150
|
changed_files=changed_files,
|
|
151
|
+
selected_lenses=selected_lenses,
|
|
143
152
|
)
|
|
144
153
|
|
|
145
154
|
|
|
@@ -9,8 +9,7 @@ from typing import Any, Mapping
|
|
|
9
9
|
|
|
10
10
|
from .convergence_store import write_json_atomic
|
|
11
11
|
from .design_surfaces import DesignSurfaceError, detect_design_surfaces
|
|
12
|
-
from .
|
|
13
|
-
from .report_narrative import NarrativeContractError, parse_narrative
|
|
12
|
+
from .report_narrative import NarrativeContractError, load_writer_input
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
def _evidence(trigger: Any) -> list[dict[str, Any]]:
|
|
@@ -102,10 +101,15 @@ def build_design_snapshot(planning: Mapping[str, Any]) -> dict[str, Any]:
|
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
|
|
105
|
-
def write_snapshot(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
def write_snapshot(
|
|
105
|
+
narrative_path: Path, output_path: Path, *, run_manifest: Path | None = None,
|
|
106
|
+
) -> dict[str, Any]:
|
|
107
|
+
try:
|
|
108
|
+
narrative = load_writer_input(narrative_path, run_manifest=run_manifest)
|
|
109
|
+
except NarrativeContractError as exc:
|
|
110
|
+
if run_manifest is None:
|
|
111
|
+
raise
|
|
112
|
+
raise DesignSurfaceError(str(exc)) from exc
|
|
109
113
|
planning = narrative.get("implementationPlanning")
|
|
110
114
|
if not isinstance(planning, Mapping):
|
|
111
115
|
raise DesignSurfaceError("implementationPlanning is missing from narrative")
|
|
@@ -115,7 +119,7 @@ def write_snapshot(narrative_path: Path, output_path: Path) -> dict[str, Any]:
|
|
|
115
119
|
|
|
116
120
|
|
|
117
121
|
_CLI_EPILOG = r"""Usage:
|
|
118
|
-
okstra design-snapshot --narrative <
|
|
122
|
+
okstra design-snapshot --run-manifest <path> --narrative <path> --output <design-preparation.json>
|
|
119
123
|
"""
|
|
120
124
|
_CLI_DESCRIPTION = "Write the detector-owned planning snapshot."
|
|
121
125
|
|
|
@@ -127,11 +131,14 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
127
131
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
128
132
|
prog="okstra design-snapshot")
|
|
129
133
|
parser.add_argument("--narrative", type=Path, required=True)
|
|
134
|
+
parser.add_argument("--run-manifest", type=Path)
|
|
130
135
|
parser.add_argument("--output", type=Path, required=True)
|
|
131
136
|
args = parser.parse_args(argv)
|
|
132
137
|
try:
|
|
133
|
-
snapshot = write_snapshot(
|
|
134
|
-
|
|
138
|
+
snapshot = write_snapshot(
|
|
139
|
+
args.narrative, args.output, run_manifest=args.run_manifest,
|
|
140
|
+
)
|
|
141
|
+
except (OSError, UnicodeError, ValueError) as exc:
|
|
135
142
|
print(f"design-snapshot: {exc}", file=sys.stderr)
|
|
136
143
|
return 2
|
|
137
144
|
print(json.dumps({"ok": True, "surfaces": sum(
|
|
@@ -6,8 +6,8 @@ import json
|
|
|
6
6
|
from datetime import date
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
|
-
from okstra_project import project_json_path, tasks_root
|
|
10
|
-
from okstra_project.dirs import TASK_CATALOG_RELATIVE
|
|
9
|
+
from okstra_project import parse_task_key, project_json_path, resolve_task_root_read_only, tasks_root
|
|
10
|
+
from okstra_project.dirs import TASK_CATALOG_RELATIVE, contained_relative_path
|
|
11
11
|
|
|
12
12
|
from . import group_context
|
|
13
13
|
from .brief_frontmatter import read_brief_frontmatter
|
|
@@ -17,6 +17,41 @@ from .paths import task_dir, task_manifest_file
|
|
|
17
17
|
from .render import render_task_catalog_discovery
|
|
18
18
|
from .run_context import dir_flock
|
|
19
19
|
|
|
20
|
+
TASK_MANIFEST_MAX_BYTES = 2 * 1024 * 1024
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_direct_task(project_root: Path, entry: dict, *, allow_create: bool) -> tuple[Path, dict]:
|
|
24
|
+
project_root = project_root.resolve()
|
|
25
|
+
project_id, group, task_id = parse_task_key(entry["taskKey"])
|
|
26
|
+
project = load_owned_object(project_json_path(project_root), artifact="project config", max_bytes=TASK_MANIFEST_MAX_BYTES)
|
|
27
|
+
if project.get("projectId") != project_id or not slugify_task_segment(group) or not slugify_task_segment(task_id):
|
|
28
|
+
raise ValueError("Task identity does not belong to this project")
|
|
29
|
+
existing = resolve_task_root_read_only(project_root, entry["taskKey"])
|
|
30
|
+
canonical = task_manifest_file(existing or task_dir(project_root, group, task_id))
|
|
31
|
+
path = Path(entry.get("taskManifestPath") or canonical)
|
|
32
|
+
path = path if path.is_absolute() else project_root / path
|
|
33
|
+
if (contained_relative_path(str(path), project_root) is None
|
|
34
|
+
or contained_relative_path(str(path), tasks_root(project_root).resolve()) is None):
|
|
35
|
+
raise ValueError("Task manifest is outside project tasks")
|
|
36
|
+
if path.exists():
|
|
37
|
+
manifest = load_owned_object(path, artifact="task manifest", max_bytes=TASK_MANIFEST_MAX_BYTES)
|
|
38
|
+
if manifest.get("taskKey") != entry["taskKey"]:
|
|
39
|
+
raise ValueError("Task manifest identity does not match the requested task")
|
|
40
|
+
for field, value in (("projectId", project_id), ("taskGroup", group), ("taskId", task_id)):
|
|
41
|
+
if field in manifest and manifest[field] != value:
|
|
42
|
+
raise ValueError("Task manifest owner is inconsistent")
|
|
43
|
+
return path, manifest
|
|
44
|
+
if not allow_create or (path.parent / "runs").exists() or entry.get("latestRunPath"):
|
|
45
|
+
raise ValueError("Task manifest is missing for a task with existing history")
|
|
46
|
+
return path, {
|
|
47
|
+
"schemaVersion": "1.0", "projectId": project_id, "projectRoot": str(project_root),
|
|
48
|
+
"taskKey": entry["taskKey"], "taskGroup": group, "taskId": task_id,
|
|
49
|
+
"taskGroupPathSegment": slugify_task_segment(group), "taskIdPathSegment": slugify_task_segment(task_id),
|
|
50
|
+
"taskRootPath": path.parent.relative_to(project_root).as_posix(),
|
|
51
|
+
"taskManifestPath": path.relative_to(project_root).as_posix(),
|
|
52
|
+
"taskBriefPath": entry.get("taskBriefPath", ""), "registrationSource": "direct",
|
|
53
|
+
}
|
|
54
|
+
|
|
20
55
|
|
|
21
56
|
def find_brief_tasks(project_root: Path, token: str, task_group: str) -> list[dict]:
|
|
22
57
|
project = load_owned_object(project_json_path(project_root), artifact="project config")
|
|
@@ -63,13 +98,20 @@ def record_direct_work(project_root: Path, manifest_path: Path, manifest: dict)
|
|
|
63
98
|
load_owned_object(project_root / previous_path, artifact="direct work record")
|
|
64
99
|
if previous_path else {}
|
|
65
100
|
)
|
|
66
|
-
|
|
101
|
+
trace_fields = {
|
|
102
|
+
"implementationTracePath": manifest["implementationTracePath"],
|
|
103
|
+
"traceDigest": manifest["traceDigest"],
|
|
104
|
+
"changedFiles": manifest["traceMetadata"].get("changedFiles", []),
|
|
105
|
+
} if manifest.get("traceDigest") else {}
|
|
106
|
+
if (previous.get("summary") == summary and previous.get("statusUpdatedAt") == manifest["workStatusUpdatedAt"]
|
|
107
|
+
and all(previous.get(key) == value for key, value in trace_fields.items())):
|
|
67
108
|
return
|
|
68
109
|
record = {
|
|
69
110
|
"schemaVersion": "1.0", "taskKey": manifest["taskKey"], "source": "direct",
|
|
70
111
|
"summary": summary, "crossVerification": "not-performed",
|
|
71
112
|
"statusUpdatedAt": manifest["workStatusUpdatedAt"],
|
|
72
113
|
"previousRecordPath": previous_path,
|
|
114
|
+
**trace_fields,
|
|
73
115
|
}
|
|
74
116
|
identity = {key: value for key, value in record.items() if key != "statusUpdatedAt"}
|
|
75
117
|
digest = hashlib.sha256(json.dumps(identity, sort_keys=True).encode()).hexdigest()
|
|
@@ -766,7 +766,7 @@ def _dispatch_cli_wrapper_batch(
|
|
|
766
766
|
returncode = port.wait(runtime)
|
|
767
767
|
completed = subprocess.CompletedProcess(handle.job.command, returncode)
|
|
768
768
|
settled = replace(handle, completed_process=completed)
|
|
769
|
-
outcomes.append((settled, attempt, _outcome_from_completed(settled)))
|
|
769
|
+
outcomes.append((settled, attempt, _outcome_from_completed(settled, manifest=plan.manifest)))
|
|
770
770
|
|
|
771
771
|
next_round: list[tuple[WorkerJob, int]] = []
|
|
772
772
|
for handle, attempt, outcome in outcomes:
|
|
@@ -885,7 +885,7 @@ def _abort_cli_batch_start(
|
|
|
885
885
|
continue
|
|
886
886
|
outcome = WorkerOutcome(
|
|
887
887
|
returncode=1,
|
|
888
|
-
missing_completion_paths=_missing_completion_paths(job),
|
|
888
|
+
missing_completion_paths=_missing_completion_paths(job, manifest=plan.manifest),
|
|
889
889
|
pane_id="",
|
|
890
890
|
status_sidecar_path=status_path_for_prompt(job.prompt_path),
|
|
891
891
|
timeout=False,
|
|
@@ -1326,7 +1326,7 @@ def _spawn_job(
|
|
|
1326
1326
|
_record_dispatch(plan.team_state_path, handle, attempt, "running", "")
|
|
1327
1327
|
_append_event(plan, "worker-dispatched", _attempt_details(job, attempt, handle))
|
|
1328
1328
|
if handle.completed_process is not None:
|
|
1329
|
-
outcome = _outcome_from_completed(handle)
|
|
1329
|
+
outcome = _outcome_from_completed(handle, manifest=plan.manifest)
|
|
1330
1330
|
retry_allowed = _finish_attempt(
|
|
1331
1331
|
plan,
|
|
1332
1332
|
job,
|
|
@@ -1720,7 +1720,7 @@ def _dispatch_job_with_retry(plan: DispatchPlan, job: WorkerJob) -> int:
|
|
|
1720
1720
|
handle = _spawn_job(plan, job, attempt)
|
|
1721
1721
|
if handle.completed_process is None:
|
|
1722
1722
|
return await_dispatches(plan, timeout_seconds=None)
|
|
1723
|
-
outcome = _outcome_from_completed(handle)
|
|
1723
|
+
outcome = _outcome_from_completed(handle, manifest=plan.manifest)
|
|
1724
1724
|
if _job_terminal_status(plan, job, attempt) == "completed":
|
|
1725
1725
|
return 0
|
|
1726
1726
|
if _should_retry(outcome, attempt) and handle.mutation_retry_allowed:
|
|
@@ -1835,25 +1835,30 @@ def _opened_cmux_surfaces(team_state_path: Path) -> tuple[str, ...]:
|
|
|
1835
1835
|
return tuple(opened)
|
|
1836
1836
|
|
|
1837
1837
|
|
|
1838
|
-
def _outcome_from_completed(
|
|
1838
|
+
def _outcome_from_completed(
|
|
1839
|
+
handle: WorkerHandle, *, manifest: Mapping[str, Any],
|
|
1840
|
+
) -> WorkerOutcome:
|
|
1839
1841
|
completed = handle.completed_process
|
|
1840
1842
|
if completed is None:
|
|
1841
1843
|
raise DispatchError("completed process missing")
|
|
1842
1844
|
return WorkerOutcome(
|
|
1843
1845
|
returncode=completed.returncode,
|
|
1844
|
-
missing_completion_paths=_missing_completion_paths(handle.job),
|
|
1846
|
+
missing_completion_paths=_missing_completion_paths(handle.job, manifest=manifest),
|
|
1845
1847
|
pane_id=handle.pane_id,
|
|
1846
1848
|
status_sidecar_path=handle.status_sidecar_path,
|
|
1847
1849
|
timeout=False,
|
|
1848
1850
|
terminal_stage="exited",
|
|
1849
1851
|
degraded_from=handle.degraded_from,
|
|
1850
|
-
artifact_defects=_artifact_defects(handle.job),
|
|
1852
|
+
artifact_defects=_artifact_defects(handle.job, manifest=manifest),
|
|
1851
1853
|
)
|
|
1852
1854
|
|
|
1853
1855
|
|
|
1854
|
-
def _artifact_defects(
|
|
1856
|
+
def _artifact_defects(
|
|
1857
|
+
job: WorkerJob, *, manifest: Mapping[str, Any],
|
|
1858
|
+
) -> tuple[str, ...]:
|
|
1855
1859
|
defect = unusable_result_defect(
|
|
1856
1860
|
job.worker_id, job.result_path, job.dispatch_kind,
|
|
1861
|
+
project_root=job.project_root, manifest=manifest,
|
|
1857
1862
|
)
|
|
1858
1863
|
return (defect,) if defect else ()
|
|
1859
1864
|
|
|
@@ -1881,7 +1886,7 @@ def _correct_teardown_marked_dispatches(plan: DispatchPlan) -> None:
|
|
|
1881
1886
|
status = read_wrapper_status(status_path) if status_path else None
|
|
1882
1887
|
if status is None or not status.is_terminal:
|
|
1883
1888
|
continue
|
|
1884
|
-
outcome = _outcome_from_status(record, status)
|
|
1889
|
+
outcome = _outcome_from_status(record, status, project_root=plan.project_root, manifest=plan.manifest)
|
|
1885
1890
|
if outcome.returncode != 0 or outcome.missing_completion_paths or outcome.timeout:
|
|
1886
1891
|
continue
|
|
1887
1892
|
_finish_record(plan, record, outcome)
|
|
@@ -1895,7 +1900,7 @@ def _advance_running_dispatches(plan: DispatchPlan, records: Sequence[Mapping[st
|
|
|
1895
1900
|
if status is not None and _wrapper_process_is_gone(status):
|
|
1896
1901
|
_settle_dead_dispatch(plan, record, status)
|
|
1897
1902
|
continue
|
|
1898
|
-
outcome = _outcome_from_status(record, status)
|
|
1903
|
+
outcome = _outcome_from_status(record, status, project_root=plan.project_root, manifest=plan.manifest)
|
|
1899
1904
|
retry_allowed = _finish_record(plan, record, outcome)
|
|
1900
1905
|
if (
|
|
1901
1906
|
_should_retry(outcome, int(record.get("attempt", 1)))
|
|
@@ -2991,16 +2996,19 @@ def _retry_details(job: WorkerJob, attempt: int, outcome: WorkerOutcome) -> dict
|
|
|
2991
2996
|
}
|
|
2992
2997
|
|
|
2993
2998
|
|
|
2994
|
-
def _outcome_from_status(
|
|
2999
|
+
def _outcome_from_status(
|
|
3000
|
+
record: Mapping[str, Any], status, *, project_root: Path,
|
|
3001
|
+
manifest: Mapping[str, Any],
|
|
3002
|
+
) -> WorkerOutcome:
|
|
2995
3003
|
return WorkerOutcome(
|
|
2996
3004
|
returncode=status.exit_code if status.exit_code is not None else 1,
|
|
2997
|
-
missing_completion_paths=_record_missing_completion_paths(record),
|
|
3005
|
+
missing_completion_paths=_record_missing_completion_paths(record, project_root=project_root, manifest=manifest),
|
|
2998
3006
|
pane_id=_string_value(record.get("paneId")),
|
|
2999
3007
|
status_sidecar_path=status.path,
|
|
3000
3008
|
timeout=status.timeout,
|
|
3001
3009
|
terminal_stage=status.stage,
|
|
3002
3010
|
degraded_from=_string_value(record.get("degradedFrom")),
|
|
3003
|
-
artifact_defects=_record_artifact_defects(record),
|
|
3011
|
+
artifact_defects=_record_artifact_defects(record, project_root=project_root, manifest=manifest),
|
|
3004
3012
|
)
|
|
3005
3013
|
|
|
3006
3014
|
|
|
@@ -3063,7 +3071,10 @@ def _record_completion_paths(record: Mapping[str, Any]) -> list[Path]:
|
|
|
3063
3071
|
return [Path(path) for path in _string_list(record.get("completionPaths"))]
|
|
3064
3072
|
|
|
3065
3073
|
|
|
3066
|
-
def _record_missing_completion_paths(
|
|
3074
|
+
def _record_missing_completion_paths(
|
|
3075
|
+
record: Mapping[str, Any], *, project_root: Path,
|
|
3076
|
+
manifest: Mapping[str, Any],
|
|
3077
|
+
) -> tuple[Path, ...]:
|
|
3067
3078
|
aliases = {Path(path) for path in _string_list(record.get("resultAliases"))}
|
|
3068
3079
|
result_path = Path(_string_value(record.get("resultPath")))
|
|
3069
3080
|
worker_result = Path(_string_value(record.get("workerResultPath")))
|
|
@@ -3074,6 +3085,7 @@ def _record_missing_completion_paths(record: Mapping[str, Any]) -> tuple[Path, .
|
|
|
3074
3085
|
if path.is_file():
|
|
3075
3086
|
if path == result_path and unusable_result_defect(
|
|
3076
3087
|
worker_id, path, dispatch_kind,
|
|
3088
|
+
project_root=project_root, manifest=manifest,
|
|
3077
3089
|
):
|
|
3078
3090
|
missing.append(path)
|
|
3079
3091
|
continue
|
|
@@ -3083,11 +3095,15 @@ def _record_missing_completion_paths(record: Mapping[str, Any]) -> tuple[Path, .
|
|
|
3083
3095
|
return tuple(missing)
|
|
3084
3096
|
|
|
3085
3097
|
|
|
3086
|
-
def _record_artifact_defects(
|
|
3098
|
+
def _record_artifact_defects(
|
|
3099
|
+
record: Mapping[str, Any], *, project_root: Path,
|
|
3100
|
+
manifest: Mapping[str, Any],
|
|
3101
|
+
) -> tuple[str, ...]:
|
|
3087
3102
|
defect = unusable_result_defect(
|
|
3088
3103
|
dispatch_worker_key(record),
|
|
3089
3104
|
Path(_string_value(record.get("resultPath"))),
|
|
3090
3105
|
_string_value(record.get("dispatchKind")),
|
|
3106
|
+
project_root=project_root, manifest=manifest,
|
|
3091
3107
|
)
|
|
3092
3108
|
return (defect,) if defect else ()
|
|
3093
3109
|
|
|
@@ -53,7 +53,7 @@ from .execution_manifest import (
|
|
|
53
53
|
from .execution_mutation_audit import ExecutionMutationAudit, MutationSnapshot
|
|
54
54
|
from .final_report_paths import final_report_data_path
|
|
55
55
|
from .report_inputs import report_narrative_path, uses_report_contract_v3
|
|
56
|
-
from .report_narrative import narrative_structure_defect
|
|
56
|
+
from .report_narrative import narrative_structure_defect, report_narrative_structure_defect
|
|
57
57
|
from .verdict_blocks import finding_vote_defect
|
|
58
58
|
from .worker_prompt_body import REPORT_WRITER_WORKER_ID
|
|
59
59
|
from .worker_prompt_contract import (
|
|
@@ -1656,6 +1656,7 @@ def dispatch_mode(jobs: Sequence[WorkerJob]) -> str:
|
|
|
1656
1656
|
|
|
1657
1657
|
def unusable_result_defect(
|
|
1658
1658
|
worker_id: str, result_path: Path, dispatch_kind: str = "",
|
|
1659
|
+
*, project_root: Path, manifest: Mapping[str, Any],
|
|
1659
1660
|
) -> str | None:
|
|
1660
1661
|
"""산출물이 있어도 소비자가 읽을 수 없으면 없는 것이다 — 서사와 재검증 표.
|
|
1661
1662
|
|
|
@@ -1688,6 +1689,9 @@ def unusable_result_defect(
|
|
|
1688
1689
|
return f"reverify result does not parse: {defect}"
|
|
1689
1690
|
if worker_id != REPORT_WRITER_WORKER_ID:
|
|
1690
1691
|
return None
|
|
1692
|
+
if uses_report_contract_v3(manifest):
|
|
1693
|
+
defect = report_narrative_structure_defect(project_root, manifest, path=result_path)
|
|
1694
|
+
return f"narrative does not parse: {defect}" if defect else None
|
|
1691
1695
|
try:
|
|
1692
1696
|
text = result_path.read_text(encoding="utf-8")
|
|
1693
1697
|
except (OSError, UnicodeDecodeError) as exc:
|
|
@@ -1698,12 +1702,15 @@ def unusable_result_defect(
|
|
|
1698
1702
|
return f"narrative does not parse: {defect}"
|
|
1699
1703
|
|
|
1700
1704
|
|
|
1701
|
-
def missing_completion_paths(
|
|
1705
|
+
def missing_completion_paths(
|
|
1706
|
+
job: WorkerJob, *, manifest: Mapping[str, Any],
|
|
1707
|
+
) -> tuple[Path, ...]:
|
|
1702
1708
|
missing: list[Path] = []
|
|
1703
1709
|
for path in job.completion_paths:
|
|
1704
1710
|
if path.is_file():
|
|
1705
1711
|
if path == job.result_path and unusable_result_defect(
|
|
1706
1712
|
job.worker_id, path, job.dispatch_kind,
|
|
1713
|
+
project_root=job.project_root, manifest=manifest,
|
|
1707
1714
|
):
|
|
1708
1715
|
missing.append(path)
|
|
1709
1716
|
continue
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import argparse
|
|
4
|
-
import json
|
|
5
4
|
from pathlib import Path
|
|
6
5
|
from typing import get_args
|
|
7
6
|
|
|
8
|
-
from ..fixed_text import
|
|
7
|
+
from ..fixed_text import emit_result
|
|
9
8
|
from ..json_boundary import JsonBoundaryError, external_user_json_source, load_external_json
|
|
10
9
|
from .config import load_config, save_config
|
|
11
10
|
from .contracts import DoyouknowError, MAX_INPUT_BYTES, read_envelope
|
|
@@ -16,7 +15,7 @@ from .source_contracts import SourceKind
|
|
|
16
15
|
def _parser() -> argparse.ArgumentParser:
|
|
17
16
|
parser = argparse.ArgumentParser(prog="okstra doyouknow", description="Store linked work records without starting a run.")
|
|
18
17
|
commands = parser.add_subparsers(dest="command", required=True)
|
|
19
|
-
for name in ("capture", "ingest", "show", "sync", "list", "config", "register", "retry"):
|
|
18
|
+
for name in ("capture", "ingest", "show", "sync", "list", "config", "register", "retry", "view"):
|
|
20
19
|
command = commands.add_parser(name)
|
|
21
20
|
if name == "show":
|
|
22
21
|
command.add_argument("record_id")
|
|
@@ -26,6 +25,8 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
26
25
|
command.add_argument("--file", type=Path, help="replace source settings from JSON")
|
|
27
26
|
elif name == "register":
|
|
28
27
|
command.add_argument("--ticket", required=True, help="pending registration UUID")
|
|
28
|
+
elif name == "view":
|
|
29
|
+
command.add_argument("--project-group", required=True, help="registered project group to render")
|
|
29
30
|
if name in ("sync", "list", "retry"):
|
|
30
31
|
command.add_argument("--source", choices=get_args(SourceKind))
|
|
31
32
|
if name == "retry":
|
|
@@ -41,12 +42,7 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
41
42
|
|
|
42
43
|
|
|
43
44
|
def _emit(payload: dict, *, text: bool) -> None:
|
|
44
|
-
|
|
45
|
-
print(json.dumps(payload, ensure_ascii=False, allow_nan=False))
|
|
46
|
-
return
|
|
47
|
-
rows = ["Okstra doyouknow\n", line("OK", payload["ok"])]
|
|
48
|
-
rows.extend(value_lines("Result", payload))
|
|
49
|
-
print("".join(rows), end="")
|
|
45
|
+
emit_result(payload, text=text, title="Okstra doyouknow")
|
|
50
46
|
|
|
51
47
|
|
|
52
48
|
def main(argv: list[str] | None = None) -> int:
|
|
@@ -62,6 +58,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
62
58
|
result = sync_sources(source=args.source)
|
|
63
59
|
elif args.command == "register":
|
|
64
60
|
result = register_ticket(args.ticket)
|
|
61
|
+
elif args.command == "view":
|
|
62
|
+
from .group_view import write_group_view
|
|
63
|
+
|
|
64
|
+
result = write_group_view(args.project_group)
|
|
65
65
|
elif args.command == "retry":
|
|
66
66
|
result = retry_pending(source=args.source, limit=args.limit)
|
|
67
67
|
elif args.command == "list":
|
|
@@ -6,7 +6,7 @@ from typing import TypedDict
|
|
|
6
6
|
from ..json_boundary import load_owned_object, serialize_owned_object, write_owned_object_atomic
|
|
7
7
|
from ..run_context import dir_flock
|
|
8
8
|
from .contracts import MAX_INPUT_BYTES, asset_object
|
|
9
|
-
from .source_contracts import validate_source_value
|
|
9
|
+
from .source_contracts import SOURCE_KINDS, validate_source_value
|
|
10
10
|
from .paths import database_path, ensure_storage_root, require_database_location as _require_database_location
|
|
11
11
|
|
|
12
12
|
|
|
@@ -26,7 +26,7 @@ def load_config(*, home: Path | None = None) -> SourceConfig:
|
|
|
26
26
|
_require_database_location(path)
|
|
27
27
|
if not path.exists():
|
|
28
28
|
return {"schemaVersion": 1, "autoRegister": True, "scope": None,
|
|
29
|
-
"sources":
|
|
29
|
+
"sources": list(SOURCE_KINDS), "includeProjects": [],
|
|
30
30
|
"excludeProjects": [], "includeGroups": [], "excludeGroups": []}
|
|
31
31
|
payload = load_owned_object(path, artifact="doyouknow config", max_bytes=MAX_INPUT_BYTES)
|
|
32
32
|
validate_source_value(payload)
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""One project group's projects, business flows and linked records as a single HTML page.
|
|
2
|
+
|
|
3
|
+
The page is a derived view: it reads the group registry and the sources `okstra doyouknow
|
|
4
|
+
sync` already stored, and compares each flow's recorded source versions with the
|
|
5
|
+
projects as they are now. It collects nothing itself.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import html
|
|
10
|
+
import json
|
|
11
|
+
import re
|
|
12
|
+
from datetime import datetime, timezone
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
from ..business_flow.contracts import BusinessFlowError
|
|
16
|
+
from ..business_flow.source import registered_roots
|
|
17
|
+
from ..business_flow.store import source_freshness
|
|
18
|
+
from ..paths import find_asset_root
|
|
19
|
+
from ..project_group import ProjectGroupError, group_path, show_group
|
|
20
|
+
from .contracts import DoyouknowError
|
|
21
|
+
from .paths import database_path, ensure_storage_root
|
|
22
|
+
from .source_store import list_sources
|
|
23
|
+
|
|
24
|
+
ASSET_DIRECTORY = ("templates", "doyouknow")
|
|
25
|
+
PAGE, STYLE, SCRIPT = "group-view.template.html", "group-view.css", "group-view.js"
|
|
26
|
+
_MARKER = re.compile(r"\{\{(TITLE|STYLE|SCRIPT|DATA)\}\}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _stored_sources(home: Path) -> tuple[list[dict], list[str]]:
|
|
30
|
+
"""Every active stored source, and a note for each one too large to be listed."""
|
|
31
|
+
sources, problems, after = [], [], None
|
|
32
|
+
while True:
|
|
33
|
+
listing = list_sources(home=home, limit=1000, after=after)
|
|
34
|
+
for source in listing["sources"]:
|
|
35
|
+
if source["lifecycle"] != "active":
|
|
36
|
+
continue
|
|
37
|
+
if source.get("detailsOmitted"):
|
|
38
|
+
# An omitted item carries no project, so it cannot be matched to a group.
|
|
39
|
+
problems.append(f"A stored source is too large to list, so its project group is unknown: {source['sourceId']}")
|
|
40
|
+
else:
|
|
41
|
+
sources.append(source)
|
|
42
|
+
if not listing["truncated"]:
|
|
43
|
+
return sources, problems
|
|
44
|
+
after = listing["nextCursor"]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _title(source: dict) -> str:
|
|
48
|
+
return next(node["title"] for node in source["nodes"] if node["id"] == source["nodeId"])
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _project_ids(source: dict) -> set[str]:
|
|
52
|
+
return {node["key"] for node in source["nodes"] if node["kind"] == "project"}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _flow(source: dict, freshness: str) -> dict:
|
|
56
|
+
metadata = source["metadata"]
|
|
57
|
+
return {
|
|
58
|
+
"id": source["sourceId"], "title": _title(source), "owner": metadata["projectId"], "locator": source["locator"],
|
|
59
|
+
"updatedAt": source["sourceUpdatedAt"] or "", "freshness": freshness, "projects": sorted(_project_ids(source)),
|
|
60
|
+
**{key: metadata[key] for key in (
|
|
61
|
+
"question", "summary", "status", "terms", "steps", "facts", "gaps", "questions",
|
|
62
|
+
"inspectedProjects", "relationships",
|
|
63
|
+
)},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _edges(source: dict) -> list[dict]:
|
|
68
|
+
projects = {node["id"]: node["key"] for node in source["nodes"] if node["kind"] == "project"}
|
|
69
|
+
return [
|
|
70
|
+
{
|
|
71
|
+
"from": projects[relation["fromNodeId"]], "to": projects[relation["toNodeId"]],
|
|
72
|
+
"kind": relation["kind"], "reason": relation["reason"], "evidence": relation["evidence"],
|
|
73
|
+
"standing": relation["standing"], "flowId": source["sourceId"],
|
|
74
|
+
}
|
|
75
|
+
for relation in source["relations"]
|
|
76
|
+
if relation["fromNodeId"] in projects and relation["toNodeId"] in projects
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def group_view_data(home: Path, project_group: str, *, now: str | None = None) -> dict:
|
|
81
|
+
try:
|
|
82
|
+
group = show_group(home, project_group)
|
|
83
|
+
# The same projects the knowledge query compares against, so a flow gets one freshness in both.
|
|
84
|
+
roots = registered_roots(group["projectGroup"], with_run_history=True, home=home)
|
|
85
|
+
except (ProjectGroupError, BusinessFlowError) as exc:
|
|
86
|
+
raise DoyouknowError(str(exc)) from exc
|
|
87
|
+
members = {member["projectId"]: member for member in group["projects"]}
|
|
88
|
+
stored, problems = _stored_sources(home)
|
|
89
|
+
captured: dict[str, dict] = {}
|
|
90
|
+
flows, edges, records = [], [], []
|
|
91
|
+
for source in stored:
|
|
92
|
+
if source["ref"]["kind"] != "business":
|
|
93
|
+
named_members = _project_ids(source) & members.keys()
|
|
94
|
+
if named_members:
|
|
95
|
+
records.append({
|
|
96
|
+
"kind": source["ref"]["kind"], "title": _title(source), "projects": sorted(named_members),
|
|
97
|
+
"locator": source["locator"], "updatedAt": source["sourceUpdatedAt"] or "",
|
|
98
|
+
})
|
|
99
|
+
elif source["ref"]["owner_id"] in members:
|
|
100
|
+
flows.append(_flow(source, source_freshness(source["metadata"]["sourceStates"], captured, roots)))
|
|
101
|
+
edges.extend(_edges(source))
|
|
102
|
+
inspected = {name for flow in flows for name in flow["inspectedProjects"]}
|
|
103
|
+
return {
|
|
104
|
+
"projectGroup": group["projectGroup"],
|
|
105
|
+
"generatedAt": now or datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
106
|
+
"projects": [
|
|
107
|
+
{
|
|
108
|
+
"projectId": name, "projectRoot": member["projectRoot"], "rootExists": member["rootExists"],
|
|
109
|
+
"investigated": name in inspected, "flowCount": sum(flow["owner"] == name for flow in flows),
|
|
110
|
+
}
|
|
111
|
+
for name, member in sorted(members.items())
|
|
112
|
+
],
|
|
113
|
+
"flows": sorted(flows, key=lambda flow: flow["title"].casefold()),
|
|
114
|
+
"edges": edges,
|
|
115
|
+
"records": sorted(records, key=lambda record: record["updatedAt"], reverse=True),
|
|
116
|
+
"problems": problems,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _asset(name: str) -> str:
|
|
121
|
+
asset_root = find_asset_root((*ASSET_DIRECTORY, name))
|
|
122
|
+
if asset_root is None:
|
|
123
|
+
raise DoyouknowError("group view asset not found: " + "/".join((*ASSET_DIRECTORY, name)))
|
|
124
|
+
return asset_root.joinpath(*ASSET_DIRECTORY, name).read_text(encoding="utf-8")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def render_group_view(home: Path, project_group: str, *, now: str | None = None) -> tuple[str, dict]:
|
|
128
|
+
data = group_view_data(home, project_group, now=now)
|
|
129
|
+
replacements = {
|
|
130
|
+
"TITLE": html.escape("Okstra project group · " + data["projectGroup"]),
|
|
131
|
+
"STYLE": _asset(STYLE),
|
|
132
|
+
"SCRIPT": _asset(SCRIPT),
|
|
133
|
+
# Inside a script element only `<` can end the element or open a comment.
|
|
134
|
+
"DATA": json.dumps(data, ensure_ascii=False).replace("<", "\\u003c"),
|
|
135
|
+
}
|
|
136
|
+
# One pass: replacing in turn would rescan stored text that happens to contain a marker.
|
|
137
|
+
return _MARKER.sub(lambda match: replacements[match.group(1)], _asset(PAGE)), data
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def write_group_view(project_group: str, *, home: Path | None = None, now: str | None = None) -> dict:
|
|
141
|
+
database = database_path(home)
|
|
142
|
+
okstra_home_root = database.parent.parent
|
|
143
|
+
html_page, data = render_group_view(okstra_home_root, project_group, now=now)
|
|
144
|
+
ensure_storage_root(database.parent)
|
|
145
|
+
path = database.parent / "view" / group_path(okstra_home_root, data["projectGroup"]).stem / "index.html"
|
|
146
|
+
path.parent.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
147
|
+
path.write_text(html_page, encoding="utf-8")
|
|
148
|
+
return {
|
|
149
|
+
"ok": True, "projectGroup": data["projectGroup"], "viewPath": str(path), "viewUrl": path.as_uri(),
|
|
150
|
+
"projects": len(data["projects"]), "flows": len(data["flows"]), "relationships": len(data["edges"]),
|
|
151
|
+
"records": len(data["records"]), "problems": data["problems"],
|
|
152
|
+
}
|
|
@@ -3,14 +3,15 @@ from __future__ import annotations
|
|
|
3
3
|
import json
|
|
4
4
|
from dataclasses import asdict, dataclass, field
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Literal
|
|
6
|
+
from typing import Literal, get_args
|
|
7
7
|
|
|
8
8
|
from ..json_boundary import serialize_owned_object
|
|
9
9
|
from .contracts import (DoyouknowError, MAX_INPUT_BYTES, Node, Relation, _check_input_depth,
|
|
10
10
|
_decoded_strings, asset_object, canonical_json, record_secret_policy_digest, reject_secrets)
|
|
11
11
|
from .identity import stable_id
|
|
12
12
|
|
|
13
|
-
SourceKind = Literal["memory", "manager", "task"]
|
|
13
|
+
SourceKind = Literal["memory", "manager", "task", "business"]
|
|
14
|
+
SOURCE_KINDS = get_args(SourceKind)
|
|
14
15
|
Lifecycle = Literal["active", "archived", "unlinked", "missing"]
|
|
15
16
|
JsonValue = str | int | float | bool | None | list["JsonValue"] | dict[str, "JsonValue"]
|
|
16
17
|
|
|
@@ -99,7 +100,7 @@ def snapshot_payload(snapshot: SourceSnapshot) -> dict:
|
|
|
99
100
|
|
|
100
101
|
|
|
101
102
|
def _require_snapshot_fields(snapshot: SourceSnapshot) -> None:
|
|
102
|
-
if snapshot.ref.kind not in
|
|
103
|
+
if snapshot.ref.kind not in SOURCE_KINDS or snapshot.lifecycle not in ("active", "archived", "unlinked", "missing"):
|
|
103
104
|
raise DoyouknowError("invalid source kind or lifecycle")
|
|
104
105
|
for value in (snapshot.ref.owner_id, snapshot.ref.native_id, snapshot.locator):
|
|
105
106
|
if not isinstance(value, str) or not value.strip():
|
|
@@ -8,7 +8,7 @@ from pathlib import Path
|
|
|
8
8
|
|
|
9
9
|
from .contracts import DoyouknowError, MAX_INPUT_BYTES, canonical_json
|
|
10
10
|
from .identity import node_id, source_id, stable_id
|
|
11
|
-
from .source_contracts import SourceRef, SourceScan, SourceSnapshot, snapshot_payload, validate_source_value
|
|
11
|
+
from .source_contracts import SOURCE_KINDS, SourceRef, SourceScan, SourceSnapshot, snapshot_payload, validate_source_value
|
|
12
12
|
from .store import SCHEMA_VERSION, SQLITE_TIMEOUT_SECONDS, _digest, _insert_node, _require_database_location, database_path, write_connection
|
|
13
13
|
|
|
14
14
|
SOURCE_SCHEMA_STATEMENTS = (
|
|
@@ -61,7 +61,7 @@ def _validated_scan(scan: SourceScan) -> tuple[list[dict], list[SourceRef]]:
|
|
|
61
61
|
raise DoyouknowError("invalid source scan status")
|
|
62
62
|
if scan.status == "complete" and scan.errors:
|
|
63
63
|
raise DoyouknowError("a complete source scan cannot contain errors")
|
|
64
|
-
if scan.domain.kind not in
|
|
64
|
+
if scan.domain.kind not in SOURCE_KINDS or not scan.domain.owner_id.strip():
|
|
65
65
|
raise DoyouknowError("invalid source scan domain")
|
|
66
66
|
if any((ref.kind, ref.owner_id) != (scan.domain.kind, scan.domain.owner_id) for ref in refs):
|
|
67
67
|
raise DoyouknowError("source scan contains a different domain")
|