Commit Graph

63 Commits

Author SHA1 Message Date
木炎
d1711a3db3 feat(generator): unify all scene types through multi-mode path
Single-mode and page-state-eval scenes now get auto-wrapped into a
default mode and compiled through compile_multi_mode_request. This
eliminates the old browser_script_with_business_logic code path and
ensures all scenes get responsePath extraction, requestTemplate, and
contentType support.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 18:28:47 +08:00
木炎
a6aa18c6d9 fix: replace eval() with safe template resolver and add empty MODES guard
Issue #1 (Critical): Replaced eval() in buildModeRequest with a safe
resolveTemplateValue function that only supports args.fieldName and
args['fieldName'] patterns, eliminating XSS/injection vulnerability.

Issue #2 (Critical): Added defensive guard in detectMode that throws a
clear error when MODES array is empty, preventing undefined property access.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 13:20:55 +08:00
木炎
7420af8f31 fix: add serde rename for NormalizeRulesJson fields to match JS camelCase
The NormalizeRulesJson struct was serializing required_fields and filter_null
as snake_case, but the JavaScript template accesses them as requiredFields
and filterNull. Add #[serde(rename = "requiredFields")] and #[serde(rename = "filterNull")]
to fix the systematic snake_case vs camelCase mismatch in multi-mode templates.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 13:16:14 +08:00
木炎
42eb716b7e feat(generator): add multi-mode template for mode-aware script generation
Add browser_script_with_modes function that generates JavaScript with:
- detectMode() to select mode based on args
- buildModeRequest() with content-type handling (JSON/form-urlencoded)
- normalizeModeRows() with validation rules
- queryModeData() with jQuery + fetch dual HTTP client

Modify browser_script() to check for modes first before falling back
to business_logic or skeleton templates.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 13:10:21 +08:00
木炎
847f2c62c6 feat(generator): add multi-mode schema structs for enhanced LLM extraction
Add ModeConditionJson, NormalizeRulesJson, ApiEndpointEnhancedJson, and
ModeConfigJson structs to support multi-mode business logic in generated
scripts. Enhance SceneInfoJson with modes, default_mode, and mode_switch_field.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 12:56:46 +08:00
木炎
eead8f7802 feat(generator): enhance buildBrowserEntrypointResult with validation flow
- Add page context validation step with deps.validatePageContext
- Change validation failure status from 'error' to 'blocked'
- Add row normalization partial detection
- Use buildArtifact for all return paths consistently
- Add COLUMNS and REPORT_NAME constants for buildArtifact
- Export determineArtifactStatus, COLUMNS, REPORT_NAME in module.exports

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 12:28:35 +08:00
木炎
d123ee0aca feat(generator): enhance buildArtifact with determineArtifactStatus integration
- Change function signature to accept destructured object parameter
- Integrate determineArtifactStatus for automatic status calculation
- Use REPORT_NAME and COLUMNS constants (to be defined in Task 6)
- Add proper filtering for partial_reasons (exclude api_/validation_ prefixes)
- Add deduplication for reasons array
- Update call site in buildBrowserEntrypointResult to use new signature

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 12:24:17 +08:00
木炎
d26d96ef64 feat(generator): add determineArtifactStatus for complete status determination
Add a helper function to determine artifact status based on business
logic conditions:
- blocked: blockedReason exists (validation failed, wrong page context)
- error: fatalError exists (API call failed)
- partial: reasons array non-empty (some data issues)
- empty: no rows returned
- ok: rows exist with no issues

This is Task 3 of 8 in the progressive template enhancement.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 12:21:13 +08:00
木炎
d996b511f6 feat(generator): add jQuery + fetch dual HTTP client support in template
Enhance defaultDeps with:
- validatePageContext: Checks hostname against expected_domain for page context validation
- queryData: Dual HTTP client with jQuery $.ajax as primary and fetch as fallback
  - jQuery preferred for internal pages that typically have it
  - Clear error message if neither client is available

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 12:19:02 +08:00
木炎
b8d2eb9faa fix(generator): use endpoint.url directly in buildRequest to fix URL construction bug
The previous implementation used `new URL(endpoint.url, window.location.origin)`
which incorrectly constructed URLs based on the current page's origin. This broke
when endpoint URLs were already complete URLs (e.g., http://20.76.57.61:18080/...).

The fix uses endpoint.url directly since LLM extraction already provides complete
URLs. Also changed from GET with query params to POST with JSON body to match
typical API expectations.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 11:34:16 +08:00
木炎
689abf08ec feat(rust): add --scene-info-json parameter for LLM extraction results
- Add SceneInfoJson struct with serde rename for camelCase compatibility
- Add ApiEndpointJson and BusinessLogicJson support structs
- Add scene_info_json field to GenerateSceneRequest (backward compatible)
- Rename browser_script to browser_script_skeleton
- Add new browser_script that delegates based on scene_info presence
- Add browser_script_with_business_logic for enhanced script generation
- Update CLI to accept --scene-info-json parameter
- Update usage string to document new parameter

Generated with [Qoder][https://qoder.com]
2026-04-17 10:27:27 +08:00
木炎
f268668713 feat: add folder picker and target_url input to Web UI
- Add /select-folder and /select-file APIs using PowerShell dialogs
- Add --target-url parameter to CLI for explicit target URL override
- Redesign Web UI with folder browse buttons for all path inputs
- Add target_url optional input field for specifying target page URL
- Auto-fill scene-id from selected folder name

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 00:23:09 +08:00
木炎
ce072c2ebe feat: auto-extract expected_domain from external script URLs
When HTML has no sgclaw-expected-domain meta tag, analyzer now scans
for external script URLs (http:// or https://) and extracts the
domain (host:port) as expected_domain.

Example:
  <script src="http://25.215.213.128:18080/a_js/YPTAPI.js"></script>
  → expected_domain = "25.215.213.128:18080"

This reduces manual editing required for third-party scenes.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 00:14:05 +08:00
木炎
464f18c672 fix: remove mandatory validation for ReportCollection fields
Remove the validation that required target_url, expected_domain, and
entry_script meta tags for ReportCollection scenes. Third-party scenes
do not have these meta tags, so the generator now uses empty values
that users can manually edit in scene.toml.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-17 00:09:12 +08:00
木炎
73edf1e5cf feat: add monitoring template support to generator
- Add scene_kind field to GenerateSceneRequest
- Update generate_scene_package to use analyze_scene_source_with_hint
- Implement scene_toml_monitoring for simplified monitoring scene manifests
- Add scene_toml router to dispatch to different templates based on SceneKind
- Add --scene-kind CLI option to sg_scene_generate binary
- Add generator_emits_monitoring_template test
- Create monitoring fixture with index.html (no meta tag, tests hint param)

Monitoring templates have simplified scene.toml without org/period resolvers.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-16 23:51:11 +08:00
木炎
87cee36173 fix: delegate analyze_scene_source to analyze_scene_source_with_hint
Remove duplicate implementation in analyze_scene_source() and replace
with simple delegation to analyze_scene_source_with_hint(source_dir, None).

This eliminates ~50 lines of duplicated logic that could drift apart
from the main implementation. Updated the test to verify the new
behavior where sources without scene-kind meta tag default to
ReportCollection instead of being rejected.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-16 23:42:46 +08:00
木炎
67fe17302e feat: add SceneKind::Monitoring and scene_kind_hint param to analyzer
- Add SceneKind::Monitoring enum variant with from_str/as_str helpers
- Add analyze_scene_source_with_hint function accepting optional scene kind hint
- User hint takes priority over meta tag, defaults to ReportCollection
- ReportCollection requires target_url, expected_domain, entry_script
- Monitoring type has optional fields
- Add test cases for hint parameter behavior
- Update non_report fixture with required meta tags for ReportCollection

🤖 Generated with [Qoder][https://qoder.com]
2026-04-16 23:33:24 +08:00
木炎
bd83d92480 refactor(service): unify submit bootstrap target resolution
Use page context, deterministic plans, and direct-skill metadata as the service-owned bootstrap target precedence so callback-host startup no longer relies on line-loss text matching or the old request-url helper.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 20:23:24 +08:00
木炎
c60cd308ca feat: service console auto-connect, settings panel, and batch of enhancements
- Auto-connect WebSocket on page load in service console
- Settings modal for editing sgclaw_config.json (API key, base URL, model, skills dir, etc.)
- UpdateConfig/ConfigUpdated protocol messages for remote config save
- save_to_path() for SgClawSettings serialization
- ConfigUpdated handler in sg_claw_client binary
- Protocol serialization tests for new message types
- HTML test assertions for auto-connect and settings UI
- Additional pending changes: deterministic submit, org units, lineloss xlsx export, browser script tool, and docs

🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 14:32:46 +08:00
木炎
6aa0c110bd fix(callback_host): close orphaned helper page before opening on same WS connection
Sends sgHideBrowerserClosePage (best-effort) before sgHideBrowerserOpenPage
on the same bootstrap WebSocket connection. This prevents duplicate helper
pages across process restarts. Also enables hidden domain mode so the helper
page is not visible to users.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 10:01:50 +08:00
木炎
390a431a4b fix(callback_host): revert close_helper_page that broke helper page loading
The close_helper_page function opened a second browser WebSocket
connection during Drop and sent a close command directly via the WS
bypassing the HTTP polling system. This interfered with the browser's
normal state and caused the helper page to fail to open.

The cached_host lift (previous commit) already solves the duplicate
helper page issue within a single process lifetime. The Drop-based
close logic is deferred until a proper cleanup mechanism is designed.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 09:41:33 +08:00
木炎
0f70702914 test(callback_host): add hidden domain bootstrap test
🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 09:21:17 +08:00
木炎
8decd9554c fix(service): lift cached_host to outer loop to prevent duplicate helper pages
🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 09:15:33 +08:00
木炎
adb64429ee feat(callback_host): close helper page on Drop via browser WS
🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 09:09:59 +08:00
木炎
32e2c59a40 feat(callback_host): add use_hidden_domain param to bootstrap_helper_page
🤖 Generated with [Qoder][https://qoder.com]
2026-04-14 09:07:20 +08:00
木炎
ad3778d4c5 fix: pass expected_domain to wrapped browser scripts
The `expected_domain` was removed from args for normalization but never
re-inserted, causing JS scripts to receive empty expected_domain and
report "missing_expected_domain" errors.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-13 17:20:48 +08:00
木炎
7320fb7f79 fix: support async browser scripts in build_eval_js
Wrap eval script in async IIFE and await Promise-like results.
Fixes Promise serialization returning '{}' for async skill scripts.

🤖 Generated with [Qoder][https://qoder.com]
2026-04-13 16:12:08 +08:00
木炎
a957712590 fix: add target_url param for Action::Eval in browser_script_skill_tool
🤖 Generated with [Qoder][https://qoder.com]
2026-04-13 15:03:49 +08:00
木炎
733aee1e9a feat: add lineloss URL mapping in derive_request_url_from_instruction
临时方案:检测指令中包含'线损'或'lineloss'时返回台区线损平台 URL

🤖 Generated with [Qoder][https://qoder.com]
2026-04-13 14:41:14 +08:00
木炎
f8f822e1f3 test: add lineloss requesturl mapping test 2026-04-13 14:38:03 +08:00
木炎
007959b903 merge: bring main lineloss defaults into ws
Bring the main-branch lineloss default-period fix into feature/claw-ws while keeping the ws submit/backend path intact.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 21:37:03 +08:00
木炎
a8a470481d fix: align lineloss default periods with page semantics
Default month/week deterministic lineloss requests to the source page's built-in time ranges while preserving explicit-period parsing and existing routing contracts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 21:35:28 +08:00
木炎
447457b7d3 fix: restore zhihu ws routing before direct submit
Keep ws-backed submit flows routing Zhihu natural-language requests through orchestration before direct submit so sg_claw service console behavior stays consistent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 21:14:35 +08:00
木炎
45b60e37f7 fix: restore zhihu export routing before direct submit
Keep Zhihu hotlist export requests on the orchestration path so natural-language submits without page context no longer fail in direct-submit routing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 19:24:09 +08:00
木炎
d230ff0389 merge: integrate main deterministic submit into ws branch
Keep the ws submit path while bringing over main's deterministic lineloss routing and the focused merge verification updates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 14:05:55 +08:00
木炎
dd7805d341 feat: add deterministic tq lineloss submit path
Add the deterministic tq-lineloss routing and normalization flow so exact-suffix requests execute through the existing browser-script seam with canonical org and period arguments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 13:10:58 +08:00
木炎
883647dffc feat: add config-owned direct submit runtime
Keep browser-attached workflows on the configured direct-skill path and align the Zhihu export/browser regression contracts with the current ws merge state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 15:45:42 +08:00
木炎
b454fa3f54 refactor: remove ws-only scene routing remnants
Keep the ws branch focused on websocket and Zhihu behavior by dropping staged scene-routing artifacts and restoring single-path skills dir semantics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 22:35:43 +08:00
木炎
7443b9da7f fix: classify direct report artifacts by status
Treat direct skill report-artifact payloads as task outcomes so partial and empty reports stay successful while blocked and error statuses fail explicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 18:01:18 +08:00
zhaoyilun
34035cdc9c fix: stabilize zhihu export and dashboard flow 2026-04-10 17:21:13 +08:00
木炎
4becf81066 feat: add config-owned direct skill submit path
Add fixed direct-submit skill loading from configured staged skills and validate directSubmitSkill early so malformed configs fail before routing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 19:02:30 +08:00
木炎
57b9be733d fix: harden service websocket reconnect flows
Stabilize the service console and callback-host websocket paths so idle disconnects and mid-task client drops no longer wedge task execution or spam repeated commands.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 10:34:34 +08:00
木炎
96c3bf1dee feat: route staged scene skills through runtime
Add registry-driven scene routing and multi-root skill loading so fault-details and 95598 scene skills can be triggered from natural language while still running through the browser-backed runtime.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 16:17:17 +08:00
木炎
bdf8e12246 feat: align browser callback runtime and export flows
Consolidate the browser task runtime around the callback path, add safer artifact opening for Zhihu exports, and cover the new service/browser flows with focused tests and supporting docs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 21:44:53 +08:00
木炎
6068a8228b feat: realign zhihu browser callback runtime
Keep Zhihu browser-attached execution on the callback-host path so direct routes, runtime wiring, and service startup stay aligned for the current websocket browser flow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 12:09:47 +08:00
木炎
3e18350320 feat: add websocket browser service runtime
Wire the service/browser runtime onto the websocket-driven execution path and add the new browser/service modules needed for the submit flow and runtime integration.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-04 23:42:27 +08:00
zyl
2ae71fb1c9 compat: probe zhihu extractor before renavigate 2026-03-30 18:39:49 +08:00
zyl
f51d6b7659 sgclaw: snapshot today's runtime and skill updates 2026-03-30 18:39:49 +08:00
zyl
cd94904329 sgclaw: stop zhihu publish flow before editor on creator page 2026-03-30 18:39:49 +08:00
zyl
d2c9902966 feat: add browser script skill execution 2026-03-30 08:29:44 +08:00