freelang-editor 11.7.4
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/.config/jest.config.js +47 -0
- package/.config/jest.fast.config.js +9 -0
- package/.config/openapi.yaml +457 -0
- package/.config/tsconfig.json +30 -0
- package/.github/CODE_OF_CONDUCT.md +176 -0
- package/.github/CONTRIBUTING.md +296 -0
- package/.github/DISCUSSIONS.md +179 -0
- package/.github/ISSUE_TEMPLATE/bug-report.md +44 -0
- package/.github/ISSUE_TEMPLATE/feature-request.md +39 -0
- package/.github/pull_request_template.md +87 -0
- package/.github/workflows/phase-3c-l2-proof.yml +101 -0
- package/.github/workflows/phase-c-full-slack.yml +409 -0
- package/.github/workflows/phase-c-full.yml +241 -0
- package/.github/workflows/phase-c-scan.yml +64 -0
- package/.gitmodules +3 -0
- package/.tmp.js +3 -0
- package/CHANGELOG.md +1182 -0
- package/CLAUDE.md +633 -0
- package/Dockerfile +3 -0
- package/LICENSE +21 -0
- package/MISTAKES-COVERAGE.json +115 -0
- package/Makefile +95 -0
- package/PHASE-F-ROADMAP.md +554 -0
- package/README.md +459 -0
- package/SELF_HOSTING_CHECKLIST.md +155 -0
- package/benchmark-freelang.fl +47 -0
- package/benchmark-results.json +37 -0
- package/benchmark-simple.fl +38 -0
- package/bin/freelang-migrate +310 -0
- package/bin/freelang-smart +258 -0
- package/bootstrap.js +1134 -0
- package/docker-compose.yml +3 -0
- package/docs/AI_FRIENDLINESS.md +181 -0
- package/docs/AI_LEARNING_PATH.md +542 -0
- package/docs/AI_MAINTENANCE.md +153 -0
- package/docs/AI_QUICKSTART.md +380 -0
- package/docs/AI_REFERENCE.md +559 -0
- package/docs/AI_RELIABILITY_GUIDE.md +597 -0
- package/docs/AKL_ARCHITECTURE.md +228 -0
- package/docs/AKL_P0_KIMDB.md +215 -0
- package/docs/API.md +380 -0
- package/docs/ARCHITECTURE.md +208 -0
- package/docs/CHANGELOG.md +1014 -0
- package/docs/CLAUDE.md +991 -0
- package/docs/CLAUDE_AI.md +210 -0
- package/docs/CODEGEN_IMPROVEMENTS.md +158 -0
- package/docs/CODE_OF_CONDUCT.md +337 -0
- package/docs/CONTRIBUTING.md +437 -0
- package/docs/CRON_AUTOMATION.md +97 -0
- package/docs/DEPLOYMENT.md +357 -0
- package/docs/DETERMINISM_GUIDE.md +174 -0
- package/docs/HUMAN_GUIDE.md +599 -0
- package/docs/INDEX.md +199 -0
- package/docs/INLINE_TEST_GUIDE.md +231 -0
- package/docs/LANGUAGE-FAULTS.md +583 -0
- package/docs/LANGUAGE_IMPROVEMENT_REQUESTS.md +187 -0
- package/docs/LEARNING.md +257 -0
- package/docs/MISTAKES-100.md +52 -0
- package/docs/MISTAKES.md +131 -0
- package/docs/NAMING_CONVENTIONS.md +158 -0
- package/docs/NIGHTLY-MONITORING.md +222 -0
- package/docs/OFFICIAL_LANGUAGE.md +249 -0
- package/docs/ONBOARDING_1HOUR.md +210 -0
- package/docs/PERFORMANCE.md +329 -0
- package/docs/PHASE-3C-L2-PROOF-PLAN.md +282 -0
- package/docs/PHASE-3C-L2-RESULTS.md +183 -0
- package/docs/PHASE-3D-AI-LIBRARY.md +170 -0
- package/docs/PHASE-3E-VM-OPTIMIZATION.md +192 -0
- package/docs/PHASE-C-CI.md +242 -0
- package/docs/PHASE-C-PR-CHECKLIST.md +267 -0
- package/docs/PHASE-C-ROADMAP.md +141 -0
- package/docs/PHASE-C-SCAN.md +205 -0
- package/docs/PHASE-G-ROADMAP.md +228 -0
- package/docs/PHASE-X-V11.5-ROADMAP.md +267 -0
- package/docs/PHASE4_IMPLEMENTATION_PLAN.md +290 -0
- package/docs/PHASE5-COMPLETION.md +186 -0
- package/docs/PHASE5-SUMMARY.md +82 -0
- package/docs/PLUGIN_GUIDE.md +241 -0
- package/docs/PROJECT_OVERVIEW_KO.md +66 -0
- package/docs/QUICKSTART.md +160 -0
- package/docs/README.md +192 -0
- package/docs/RESERVED.md +125 -0
- package/docs/ROADMAP.md +191 -0
- package/docs/SECURITY.md +518 -0
- package/docs/SETUP.md +127 -0
- package/docs/SLACK-SETUP.md +190 -0
- package/docs/STATE_OF_V11.md +74 -0
- package/docs/STDLIB_NAMING_AUDIT.md +154 -0
- package/docs/STDLIB_REFERENCE.md +2722 -0
- package/docs/STYLE_GUIDE.md +559 -0
- package/docs/TASK5-MAP-DESTRUCTURE-DESIGN.md +136 -0
- package/docs/TOOLS.md +357 -0
- package/docs/TYPE_SYSTEM_GUIDE.md +201 -0
- package/docs/UI-PATTERN.md +265 -0
- package/docs/V11.5-RULES.md +416 -0
- package/docs/V11.6-HARNESS-RULES.md +222 -0
- package/docs/V11.6-MULTI-AGENT-PLAN.md +265 -0
- package/docs/V11.6-STABILIZATION-PLAN.md +290 -0
- package/docs/Y4-2B_DRY_RUN.md +142 -0
- package/docs/_classifications.json +882 -0
- package/docs/api/stdlib.md +134 -0
- package/docs/blog/2026-04-17-v11-ai-first-evolution.md +223 -0
- package/docs/blog/2026-04-20-self-hosting-fixedpoint.md +269 -0
- package/docs/blog/2026-05-04-mistakes-are-language-faults.md +267 -0
- package/docs/blog/2026-05-04-mistakes-coverage-honest.md +170 -0
- package/docs/blog/2026-05-04-phase-g-followup-smart-wrapper.md +188 -0
- package/docs/blog/2026-05-04-phase-g-mistakes-100.md +269 -0
- package/docs/blog/2026-05-04-phase-x-v11.5-launch.md +224 -0
- package/docs/blog/2026-05-04-v11.5.0-real-language-change.md +252 -0
- package/docs/blog-demo/README.md +44 -0
- package/docs/examples/index.md +78 -0
- package/docs/examples/todo-app.md +99 -0
- package/docs/guide/ai-blocks.md +335 -0
- package/docs/guide/basics.md +235 -0
- package/docs/guide/frameworks.md +319 -0
- package/docs/homepage/README.md +164 -0
- package/docs/index.md +183 -0
- package/docs/v12-DESIGN.md +214 -0
- package/examples/README.md +26 -0
- package/examples/browser-test.html +149 -0
- package/examples/csv-tool/analyze.fl +222 -0
- package/examples/csv-tool/employees.csv +16 -0
- package/examples/csv-tool/products.csv +21 -0
- package/examples/factorial.fl +9 -0
- package/examples/fib30.fl +4 -0
- package/examples/hello.fl +2 -0
- package/examples/hello.fl.js +3 -0
- package/examples/learning-session/01-grade-stats.fl +49 -0
- package/examples/learning-session/02-class-stats.fl +52 -0
- package/examples/learning-session/03-cart.fl +61 -0
- package/examples/learning-session/04-word-freq.fl +57 -0
- package/examples/learning-session/05-todo.fl +69 -0
- package/examples/learning-session/06-library.fl +76 -0
- package/examples/learning-session/07-currency.fl +99 -0
- package/examples/learning-session/08-csv-grades.fl +104 -0
- package/examples/learning-session/09-calc-repl.fl +92 -0
- package/examples/learning-session/10-contacts.fl +109 -0
- package/examples/learning-session/11-markdown.fl +107 -0
- package/examples/learning-session/12-calendar.fl +87 -0
- package/examples/learning-session/13-statistics.fl +123 -0
- package/examples/learning-session/14-primes.fl +107 -0
- package/examples/learning-session/15-statistics.fl +123 -0
- package/examples/learning-session/16-calendar.fl +87 -0
- package/examples/learning-session/17-markdown.fl +107 -0
- package/examples/learning-session/18-contacts.fl +109 -0
- package/examples/learning-session/19-json-serializer.fl +86 -0
- package/examples/learning-session/20-template.fl +201 -0
- package/examples/learning-session/21-calc-parser.fl +148 -0
- package/examples/learning-session/22-table.fl +96 -0
- package/examples/patterns/01-map-filter-reduce.fl +50 -0
- package/examples/patterns/02-error-handling.fl +51 -0
- package/examples/patterns/03-type-validation.fl +57 -0
- package/examples/patterns/04-state-management.fl +44 -0
- package/examples/patterns/05-api-integration.fl +95 -0
- package/examples/patterns/06-database-operations.fl +113 -0
- package/examples/patterns/07-string-processing.fl +86 -0
- package/examples/patterns/08-data-transformation.fl +92 -0
- package/examples/patterns/09-decision-logic.fl +122 -0
- package/examples/patterns/10-agent-orchestration.fl +184 -0
- package/examples/patterns/README.md +344 -0
- package/examples/simple-server.fl +29 -0
- package/examples/tables-app.fl +219 -0
- package/examples/test-libs.fl +272 -0
- package/jest.config.js +4 -0
- package/lib/datetime.fl +123 -0
- package/lib/http-client.fl +129 -0
- package/lib/pipeline.fl +150 -0
- package/lib/query.fl +160 -0
- package/lib/result.fl +124 -0
- package/lib/template.fl +161 -0
- package/lib/validate.fl +136 -0
- package/package.json +58 -0
- package/scripts/ai-eval.js +318 -0
- package/scripts/ai-self-verify.js +200 -0
- package/scripts/ai-validate.js +302 -0
- package/scripts/bench.sh +71 -0
- package/scripts/benchmark.js +258 -0
- package/scripts/benchmark.sh +99 -0
- package/scripts/build-binary.sh +68 -0
- package/scripts/build-runtime.sh +46 -0
- package/scripts/build-stage1-final.sh +58 -0
- package/scripts/build-stage1.sh +119 -0
- package/scripts/build-standalone.sh +17 -0
- package/scripts/build.js +130 -0
- package/scripts/check-let-regressions.js +95 -0
- package/scripts/check-parens.py +117 -0
- package/scripts/check-ports.sh +49 -0
- package/scripts/check-syntax.js +30 -0
- package/scripts/cli-extras.js +135 -0
- package/scripts/cron-daily-verify.sh +101 -0
- package/scripts/deploy.sh +91 -0
- package/scripts/dev.sh +37 -0
- package/scripts/extract-fl-examples.js +29 -0
- package/scripts/extract-runtime-helpers.js +122 -0
- package/scripts/fl-compile.sh +14 -0
- package/scripts/fl-fixpoint.sh +28 -0
- package/scripts/fl-repl.sh +21 -0
- package/scripts/fl-run.sh +41 -0
- package/scripts/fl-serve.sh +25 -0
- package/scripts/fuzz-compiler.js +92 -0
- package/scripts/gen-ai-prompt.js +340 -0
- package/scripts/gen-fixtures.js +166 -0
- package/scripts/gen-mistakes-split.js +199 -0
- package/scripts/gen-stdlib-docs.js +69 -0
- package/scripts/lint-stdlib-aliases.js +166 -0
- package/scripts/measure-baseline.sh +43 -0
- package/scripts/property-test.js +885 -0
- package/scripts/push-to-gogs.sh +60 -0
- package/scripts/regression-scan.js +132 -0
- package/scripts/run-jest-shard.sh +85 -0
- package/scripts/safe-push.sh +37 -0
- package/scripts/scan-fl-tokens.js +170 -0
- package/scripts/scan-for-fl-tokens.sh +17 -0
- package/scripts/self-diff.sh +95 -0
- package/scripts/snapshot-v0.sh +35 -0
- package/scripts/test-l2-fixpoint.sh +54 -0
- package/scripts/verify-all.sh +130 -0
- package/scripts/verify-build-deterministic.sh +110 -0
- package/scripts/verify-c7-bootstrap.sh +150 -0
- package/scripts/verify-c8-fixed-point-simple.sh +121 -0
- package/scripts/verify-c8-fixed-point.sh +133 -0
- package/scripts/verify-c9-fuzzing.sh +214 -0
- package/scripts/verify-fixed-point-deep.sh +133 -0
- package/scripts/verify-fixed-point.sh +65 -0
- package/scripts/verify-l2-proof.sh +153 -0
- package/scripts/verify-l3-proof.sh +40 -0
- package/scripts/verify-mistakes-coverage.js +120 -0
- package/scripts/verify-self-host.sh +509 -0
- package/self/CHANGELOG.md +964 -0
- package/self/COMPILER_REDESIGN_FAILURES.md +59 -0
- package/self/INTEGRATION-CHECKLIST.md +113 -0
- package/self/README.md +34 -0
- package/self/all.fl +1353 -0
- package/self/ast.fl +219 -0
- package/self/ast.self.js +47 -0
- package/self/bench/_bi_json-parse.js +46 -0
- package/self/bench/_bi_json-str.js +60 -0
- package/self/bench/_bi_list-distinct.js +37 -0
- package/self/bench/_bi_list-filter-even.js +56 -0
- package/self/bench/_bi_list-first.js +29 -0
- package/self/bench/_bi_list-last.js +28 -0
- package/self/bench/_bi_list-map-inc.js +41 -0
- package/self/bench/_bi_list-range.js +22 -0
- package/self/bench/_bi_list-reduce-sum.js +50 -0
- package/self/bench/_bi_list-reverse.js +28 -0
- package/self/bench/_bi_list-sort.js +35 -0
- package/self/bench/_bi_list-take.js +36 -0
- package/self/bench/_bi_m-abs.js +24 -0
- package/self/bench/_bi_m-floor.js +22 -0
- package/self/bench/_bi_m-max.js +26 -0
- package/self/bench/_bi_m-min.js +26 -0
- package/self/bench/_bi_m-mod.js +21 -0
- package/self/bench/_bi_map-has.js +50 -0
- package/self/bench/_bi_map-keys.js +50 -0
- package/self/bench/_bi_map-values.js +52 -0
- package/self/bench/_bi_str-concat.js +36 -0
- package/self/bench/_bi_str-contains.js +43 -0
- package/self/bench/_bi_str-ends.js +45 -0
- package/self/bench/_bi_str-index.js +34 -0
- package/self/bench/_bi_str-lower.js +23 -0
- package/self/bench/_bi_str-repeat.js +26 -0
- package/self/bench/_bi_str-split.js +41 -0
- package/self/bench/_bi_str-starts.js +47 -0
- package/self/bench/_bi_str-trim.js +26 -0
- package/self/bench/_bi_str-upper.js +23 -0
- package/self/bench/_bi_t-list.js +24 -0
- package/self/bench/_bi_t-null.js +23 -0
- package/self/bench/_bi_t-number.js +23 -0
- package/self/bench/_bi_t-string.js +25 -0
- package/self/bench/_bi_t-typeof.js +25 -0
- package/self/bench/_c_parse_probe.fl +426 -0
- package/self/bench/_c_parse_probe.js +67 -0
- package/self/bench/_codegen_nodrv.fl +751 -0
- package/self/bench/_combined2.fl +423 -0
- package/self/bench/_combined_arr.fl +422 -0
- package/self/bench/_combined_astprobe.fl +429 -0
- package/self/bench/_combined_astprobe.js +69 -0
- package/self/bench/_combined_cg.fl +424 -0
- package/self/bench/_combined_cg.js +64 -0
- package/self/bench/_combined_lex.fl +421 -0
- package/self/bench/_combined_trace.fl +435 -0
- package/self/bench/_combined_trace.js +75 -0
- package/self/bench/_ext_abs-neg.js +2 -0
- package/self/bench/_ext_and.js +2 -0
- package/self/bench/_ext_cond-1.js +2 -0
- package/self/bench/_ext_cond-2.js +2 -0
- package/self/bench/_ext_do-seq.js +2 -0
- package/self/bench/_ext_fact20.js +3 -0
- package/self/bench/_ext_fib25.js +3 -0
- package/self/bench/_ext_length.js +2 -0
- package/self/bench/_ext_let-1d.js +18 -0
- package/self/bench/_ext_let-2d.js +2 -0
- package/self/bench/_ext_list-sum.js +3 -0
- package/self/bench/_ext_math.js +2 -0
- package/self/bench/_ext_or.js +2 -0
- package/self/bench/_ext_str.js +2 -0
- package/self/bench/_fact15.js +2 -0
- package/self/bench/_fb_fact15.js +2 -0
- package/self/bench/_fb_func-fact.js +2 -0
- package/self/bench/_fb_func-multi.js +2 -0
- package/self/bench/_fb_func-mutual.js +3 -0
- package/self/bench/_fb_func-simple.js +21 -0
- package/self/bench/_fib.js +2 -0
- package/self/bench/_fn_async-await-seq.js +40 -0
- package/self/bench/_fn_async-await.js +3 -0
- package/self/bench/_fn_async-print.js +26 -0
- package/self/bench/_fn_async-result.js +1 -0
- package/self/bench/_fn_call-form.js +24 -0
- package/self/bench/_fn_compose.js +37 -0
- package/self/bench/_fn_pipe.js +34 -0
- package/self/bench/_fn_thread-first-sexpr.js +31 -0
- package/self/bench/_fn_thread-first.js +25 -0
- package/self/bench/_fn_thread-last.js +31 -0
- package/self/bench/_generated.js +35 -0
- package/self/bench/_mt_match-default.js +51 -0
- package/self/bench/_mt_match-num.js +58 -0
- package/self/bench/_mt_match-str.js +56 -0
- package/self/bench/_mt_match-var.js +32 -0
- package/self/bench/_mt_match-wild.js +36 -0
- package/self/bench/_mt_struct-make.js +81 -0
- package/self/bench/_mt_struct-tag.js +81 -0
- package/self/bench/_probe.fl +1 -0
- package/self/bench/_probe2.fl +1 -0
- package/self/bench/_probe3.fl +3 -0
- package/self/bench/_probe_apply.fl +1 -0
- package/self/bench/_probe_args.fl +7 -0
- package/self/bench/_probe_arr.fl +7 -0
- package/self/bench/_probe_arr2.fl +5 -0
- package/self/bench/_probe_block.fl +7 -0
- package/self/bench/_probe_call.fl +1 -0
- package/self/bench/_probe_cg.fl +27 -0
- package/self/bench/_probe_compose.fl +13 -0
- package/self/bench/_probe_define.fl +1 -0
- package/self/bench/_probe_keys.fl +5 -0
- package/self/bench/_probe_length.fl +5 -0
- package/self/bench/_probe_lexparse.fl +4 -0
- package/self/bench/_probe_loop.fl +12 -0
- package/self/bench/_probe_map.fl +8 -0
- package/self/bench/_probe_map2.fl +8 -0
- package/self/bench/_probe_map3.fl +5 -0
- package/self/bench/_probe_mapkeys.fl +5 -0
- package/self/bench/_probe_mapv12.fl +1 -0
- package/self/bench/_probe_mapv12.js +2 -0
- package/self/bench/_probe_match.fl +1 -0
- package/self/bench/_probe_match2.fl +1 -0
- package/self/bench/_probe_neg.fl +7 -0
- package/self/bench/_probe_neg2.fl +3 -0
- package/self/bench/_probe_protocol.fl +7 -0
- package/self/bench/_probe_self_parse.fl +6 -0
- package/self/bench/_probe_struct.fl +1 -0
- package/self/bench/_probe_true.fl +3 -0
- package/self/bench/_probe_true2.fl +6 -0
- package/self/bench/_probe_v12_cg.fl +7 -0
- package/self/bench/_probe_v12_extract.fl +8 -0
- package/self/bench/_probe_v12_extract.js +7 -0
- package/self/bench/_probe_v12_internal.fl +21 -0
- package/self/bench/_probe_v12_map_ast.fl +12 -0
- package/self/bench/_rs_combo.js +3 -0
- package/self/bench/_rs_gcd.js +36 -0
- package/self/bench/_rs_grade.js +2 -0
- package/self/bench/_rs_mutual-fib.js +2 -0
- package/self/bench/_rs_range-sum.js +2 -0
- package/self/bench/_rs_sum-10k.js +2 -0
- package/self/bench/_rs_sum-5k.js +2 -0
- package/self/bench/_sf_loop-fact-10.js +73 -0
- package/self/bench/_sf_loop-sum-10k.js +87 -0
- package/self/bench/_sf_set-x.js +40 -0
- package/self/bench/_sf_throw-catch.js +1 -0
- package/self/bench/_sf_while-5.js +62 -0
- package/self/bench/_v12_combined.fl +1184 -0
- package/self/bench/_v12_extract_test.fl +14 -0
- package/self/bench/_v12_extract_test.js +7 -0
- package/self/bench/_v12_inspect.js +26 -0
- package/self/bench/_v12_inspect_mod.js +137 -0
- package/self/bench/_v12_makevartest.fl +8 -0
- package/self/bench/_v12_makevartest.js +6 -0
- package/self/bench/_v12_parse_probe.fl +9 -0
- package/self/bench/_v12_parse_trace.fl +18 -0
- package/self/bench/_v12_simple_fn.fl +2 -0
- package/self/bench/_v12_simple_fn.js +3 -0
- package/self/bench/_v12_trace.fl +2 -0
- package/self/bench/_v12_trace.js +3 -0
- package/self/bench/collection.js +13 -0
- package/self/bench/fib30.fl +4 -0
- package/self/bench/final-test.fl +12 -0
- package/self/bench/final-test.js +2 -0
- package/self/bench/fp1-v12.js +4 -0
- package/self/bench/fp1.fl +3 -0
- package/self/bench/fp1.fp.js +4 -0
- package/self/bench/fp2-v12.js +4 -0
- package/self/bench/fp2.fl +3 -0
- package/self/bench/fp2.fp.js +4 -0
- package/self/bench/fp3-v12.js +8 -0
- package/self/bench/fp3.fl +11 -0
- package/self/bench/fp3.fp.js +8 -0
- package/self/bench/fp4-v12.js +6 -0
- package/self/bench/fp4.fl +9 -0
- package/self/bench/fp4.fp.js +6 -0
- package/self/bench/hello-sample.fl +3 -0
- package/self/bench/hello-sample.js +4 -0
- package/self/bench/hello.fl +1 -0
- package/self/bench/json.js +9 -0
- package/self/bench/json1mb.fl +3 -0
- package/self/bench/math.js +8 -0
- package/self/bench/realworld.fl +17 -0
- package/self/bench/realworld.js +8 -0
- package/self/bench/regex.js +10 -0
- package/self/bench/sample.json +1 -0
- package/self/bench/string.js +7 -0
- package/self/bench/test-ffi.fl +3 -0
- package/self/bench/test-ffi.js +2 -0
- package/self/bench/test-hof-advanced.fl +7 -0
- package/self/bench/test-hof-advanced.js +2 -0
- package/self/bench/test-hof.fl +5 -0
- package/self/bench/test-hof.js +2 -0
- package/self/bench/test-output.txt +1 -0
- package/self/bench/test-phase15-integration.fl +16 -0
- package/self/bench/test-phase15-integration.js +3 -0
- package/self/bench/test-phase19-complete.fl +24 -0
- package/self/bench/test-phase19-complete.js +2 -0
- package/self/bench/test-stdlib-codegen.fl +9 -0
- package/self/bench/test-stdlib-codegen.js +2 -0
- package/self/bench/test-time.fl +8 -0
- package/self/bench/test-time.js +2 -0
- package/self/bench/time.js +9 -0
- package/self/bench/tiny-v12.js +2 -0
- package/self/bench/tiny.fl +1 -0
- package/self/builtins/core.fl +150 -0
- package/self/char-class.fl +45 -0
- package/self/codegen-core.fl +733 -0
- package/self/codegen-final.fl +135 -0
- package/self/codegen.fl +379 -0
- package/self/codegen.fl.bak +856 -0
- package/self/codegen.self.js +75 -0
- package/self/examples/agent-loop.fl +32 -0
- package/self/examples/ci-cd-example.fl +114 -0
- package/self/examples/cloud-real.fl +134 -0
- package/self/examples/docker-example.fl +67 -0
- package/self/examples/fullstack-app.fl +330 -0
- package/self/examples/k8s-example.fl +91 -0
- package/self/examples/microservices.fl +448 -0
- package/self/examples/rest-api.fl +253 -0
- package/self/examples/style-example.fl +133 -0
- package/self/examples/workflow-orchestration.fl +44 -0
- package/self/fixtures/eval/add.fl +1 -0
- package/self/fixtures/eval/and-sc.fl +1 -0
- package/self/fixtures/eval/bool-false.fl +1 -0
- package/self/fixtures/eval/bool-true.fl +1 -0
- package/self/fixtures/eval/closure.fl +1 -0
- package/self/fixtures/eval/cmp-eq.fl +1 -0
- package/self/fixtures/eval/cmp-lt.fl +1 -0
- package/self/fixtures/eval/cond-first.fl +1 -0
- package/self/fixtures/eval/define-fn3.fl +1 -0
- package/self/fixtures/eval/define-var.fl +1 -0
- package/self/fixtures/eval/defn-bare.fl +1 -0
- package/self/fixtures/eval/defn-call.fl +1 -0
- package/self/fixtures/eval/div.fl +1 -0
- package/self/fixtures/eval/filter-hof.fl +1 -0
- package/self/fixtures/eval/floor.fl +1 -0
- package/self/fixtures/eval/fn-apply.fl +1 -0
- package/self/fixtures/eval/get-idx.fl +1 -0
- package/self/fixtures/eval/get-key.fl +1 -0
- package/self/fixtures/eval/higher-order.fl +1 -0
- package/self/fixtures/eval/let-bare.fl +1 -0
- package/self/fixtures/eval/let-flat.fl +1 -0
- package/self/fixtures/eval/let-use.fl +1 -0
- package/self/fixtures/eval/list-first.fl +1 -0
- package/self/fixtures/eval/list-last.fl +1 -0
- package/self/fixtures/eval/list-len.fl +1 -0
- package/self/fixtures/eval/map-hof.fl +1 -0
- package/self/fixtures/eval/mod.fl +1 -0
- package/self/fixtures/eval/mul-nested.fl +1 -0
- package/self/fixtures/eval/not.fl +1 -0
- package/self/fixtures/eval/null-p.fl +1 -0
- package/self/fixtures/eval/or-sc.fl +1 -0
- package/self/fixtures/eval/pow.fl +1 -0
- package/self/fixtures/eval/recursion.fl +1 -0
- package/self/fixtures/eval/reduce-hof.fl +1 -0
- package/self/fixtures/eval/replace.fl +1 -0
- package/self/fixtures/eval/sqrt.fl +1 -0
- package/self/fixtures/eval/str-concat.fl +1 -0
- package/self/fixtures/eval/str-num.fl +1 -0
- package/self/fixtures/eval/sub.fl +1 -0
- package/self/fixtures/eval/substring.fl +1 -0
- package/self/fixtures/lex/array.fl +1 -0
- package/self/fixtures/lex/at-atom.fl +1 -0
- package/self/fixtures/lex/block.fl +1 -0
- package/self/fixtures/lex/comment.fl +2 -0
- package/self/fixtures/lex/deep-array.fl +1 -0
- package/self/fixtures/lex/deep-map.fl +1 -0
- package/self/fixtures/lex/deep-nest.fl +1 -0
- package/self/fixtures/lex/dollar-dot.fl +1 -0
- package/self/fixtures/lex/empty-list.fl +1 -0
- package/self/fixtures/lex/empty-str.fl +1 -0
- package/self/fixtures/lex/empty.fl +1 -0
- package/self/fixtures/lex/float.fl +1 -0
- package/self/fixtures/lex/hex.fl +1 -0
- package/self/fixtures/lex/kebab-sym.fl +1 -0
- package/self/fixtures/lex/keyword.fl +1 -0
- package/self/fixtures/lex/leading-zero.fl +1 -0
- package/self/fixtures/lex/long-num.fl +1 -0
- package/self/fixtures/lex/many-args.fl +1 -0
- package/self/fixtures/lex/map.fl +1 -0
- package/self/fixtures/lex/mixed.fl +1 -0
- package/self/fixtures/lex/neg-float.fl +1 -0
- package/self/fixtures/lex/negative.fl +1 -0
- package/self/fixtures/lex/nested.fl +1 -0
- package/self/fixtures/lex/null.fl +1 -0
- package/self/fixtures/lex/pipe-op.fl +1 -0
- package/self/fixtures/lex/route-like.fl +1 -0
- package/self/fixtures/lex/scientific.fl +1 -0
- package/self/fixtures/lex/single-num.fl +1 -0
- package/self/fixtures/lex/small-sexpr.fl +1 -0
- package/self/fixtures/lex/spaces.fl +1 -0
- package/self/fixtures/lex/str-quote.fl +1 -0
- package/self/fixtures/lex/str-tab.fl +1 -0
- package/self/fixtures/lex/string-esc.fl +1 -0
- package/self/fixtures/lex/string.fl +1 -0
- package/self/fixtures/lex/symbol.fl +1 -0
- package/self/fixtures/lex/tabs-nl.fl +3 -0
- package/self/fixtures/lex/true-false.fl +1 -0
- package/self/fixtures/lex/unicode.fl +1 -0
- package/self/fixtures/lex/variable.fl +1 -0
- package/self/fixtures/lex/zero.fl +1 -0
- package/self/fixtures/parse/and-or.fl +1 -0
- package/self/fixtures/parse/array-lit.fl +1 -0
- package/self/fixtures/parse/block-func.fl +1 -0
- package/self/fixtures/parse/compose.fl +1 -0
- package/self/fixtures/parse/cond.fl +1 -0
- package/self/fixtures/parse/define-fn.fl +1 -0
- package/self/fixtures/parse/define-val.fl +1 -0
- package/self/fixtures/parse/defn.fl +1 -0
- package/self/fixtures/parse/do-begin.fl +1 -0
- package/self/fixtures/parse/dotted.fl +1 -0
- package/self/fixtures/parse/empty-fn.fl +1 -0
- package/self/fixtures/parse/empty-list.fl +1 -0
- package/self/fixtures/parse/fn.fl +1 -0
- package/self/fixtures/parse/if-else.fl +1 -0
- package/self/fixtures/parse/if-only.fl +1 -0
- package/self/fixtures/parse/keyword-arg.fl +1 -0
- package/self/fixtures/parse/kw.fl +1 -0
- package/self/fixtures/parse/let-1d.fl +1 -0
- package/self/fixtures/parse/let-2d.fl +1 -0
- package/self/fixtures/parse/let-bare.fl +1 -0
- package/self/fixtures/parse/literal-num.fl +1 -0
- package/self/fixtures/parse/literal-str.fl +1 -0
- package/self/fixtures/parse/loop-recur.fl +1 -0
- package/self/fixtures/parse/map-lit.fl +1 -0
- package/self/fixtures/parse/match-simple.fl +1 -0
- package/self/fixtures/parse/multi-body.fl +1 -0
- package/self/fixtures/parse/nested-arr.fl +1 -0
- package/self/fixtures/parse/nested-block.fl +1 -0
- package/self/fixtures/parse/nested-map.fl +1 -0
- package/self/fixtures/parse/nested.fl +1 -0
- package/self/fixtures/parse/pipe.fl +1 -0
- package/self/fixtures/parse/quote.fl +1 -0
- package/self/fixtures/parse/set-bang.fl +1 -0
- package/self/fixtures/parse/sexpr.fl +1 -0
- package/self/fixtures/parse/str-interp.fl +1 -0
- package/self/fixtures/parse/sym.fl +1 -0
- package/self/fixtures/parse/thread-first.fl +1 -0
- package/self/fixtures/parse/thread-last.fl +1 -0
- package/self/fixtures/parse/try-catch.fl +1 -0
- package/self/fixtures/parse/var.fl +1 -0
- package/self/full-compiler-fixed.fl +1308 -0
- package/self/full-compiler-v1-bloated.fl +1298 -0
- package/self/full-compiler.fl +1301 -0
- package/self/interpreter.fl +351 -0
- package/self/lexer.fl +200 -0
- package/self/lexer.self.js +30 -0
- package/self/main.fl +22 -0
- package/self/parser.fl +241 -0
- package/self/parser.self.js +33 -0
- package/self/runtime/http-server.js +642 -0
- package/self/runtime/interpreter.js +30787 -0
- package/self/runtime/repl.js +186 -0
- package/self/runtime-helpers.ts +282 -0
- package/self/scope.fl +80 -0
- package/self/scope.self.js +1 -0
- package/self/self/bench/_bi_list-distinct.js +2 -0
- package/self/self/bench/_bi_list-filter-even.js +2 -0
- package/self/self/bench/_bi_list-first.js +2 -0
- package/self/self/bench/_bi_list-last.js +2 -0
- package/self/self/bench/_bi_list-map-inc.js +2 -0
- package/self/self/bench/_bi_list-range.js +2 -0
- package/self/self/bench/_bi_list-reduce-sum.js +2 -0
- package/self/self/bench/_bi_list-reverse.js +2 -0
- package/self/self/bench/_bi_list-sort.js +2 -0
- package/self/self/bench/_bi_list-take.js +2 -0
- package/self/self/bench/_bi_map-has.js +2 -0
- package/self/self/bench/_bi_map-keys.js +2 -0
- package/self/self/bench/_bi_map-values.js +2 -0
- package/self/self/bench/_bi_str-concat.js +2 -0
- package/self/self/bench/_bi_str-contains.js +2 -0
- package/self/self/bench/_bi_str-ends.js +2 -0
- package/self/self/bench/_bi_str-index.js +2 -0
- package/self/self/bench/_bi_str-lower.js +2 -0
- package/self/self/bench/_bi_str-repeat.js +2 -0
- package/self/self/bench/_bi_str-split.js +2 -0
- package/self/self/bench/_bi_str-starts.js +2 -0
- package/self/self/bench/_bi_str-trim.js +2 -0
- package/self/self/bench/_bi_str-upper.js +2 -0
- package/self/self/bench/_ext_abs-neg.js +2 -0
- package/self/self/bench/_ext_and.js +2 -0
- package/self/self/bench/_ext_cond-1.js +2 -0
- package/self/self/bench/_ext_cond-2.js +2 -0
- package/self/self/bench/_ext_do-seq.js +2 -0
- package/self/self/bench/_ext_fact20.js +3 -0
- package/self/self/bench/_ext_fib25.js +3 -0
- package/self/self/bench/_ext_length.js +2 -0
- package/self/self/bench/_ext_let-1d.js +2 -0
- package/self/self/bench/_ext_let-2d.js +2 -0
- package/self/self/bench/_ext_list-sum.js +3 -0
- package/self/self/bench/_ext_math.js +2 -0
- package/self/self/bench/_ext_or.js +2 -0
- package/self/self/bench/_ext_str.js +2 -0
- package/self/self/bench/_fact15.js +2 -0
- package/self/self/bench/_fb_fact15.js +2 -0
- package/self/self/bench/_fb_func-fact.js +2 -0
- package/self/self/bench/_fb_func-multi.js +2 -0
- package/self/self/bench/_fb_func-mutual.js +3 -0
- package/self/self/bench/_fb_func-simple.js +2 -0
- package/self/self/bench/_fib.js +2 -0
- package/self/self/bench/_fn_async-await-seq.js +2 -0
- package/self/self/bench/_fn_async-print.js +2 -0
- package/self/self/bench/_fn_call-form.js +2 -0
- package/self/self/bench/_fn_compose.js +2 -0
- package/self/self/bench/_fn_pipe.js +2 -0
- package/self/self/bench/_fn_thread-first-sexpr.js +2 -0
- package/self/self/bench/_fn_thread-first.js +2 -0
- package/self/self/bench/_fn_thread-last.js +2 -0
- package/self/self/bench/_generated.js +2 -0
- package/self/self/bench/_mt_match-default.js +2 -0
- package/self/self/bench/_mt_match-num.js +2 -0
- package/self/self/bench/_mt_match-str.js +2 -0
- package/self/self/bench/_mt_match-var.js +2 -0
- package/self/self/bench/_mt_match-wild.js +2 -0
- package/self/self/bench/_mt_struct-make.js +4 -0
- package/self/self/bench/_mt_struct-tag.js +4 -0
- package/self/self/bench/_rs_combo.js +3 -0
- package/self/self/bench/_rs_gcd.js +2 -0
- package/self/self/bench/_rs_grade.js +2 -0
- package/self/self/bench/_rs_mutual-fib.js +2 -0
- package/self/self/bench/_rs_range-sum.js +2 -0
- package/self/self/bench/_rs_sum-5k.js +2 -0
- package/self/self/bench/_sf_loop-fact-10.js +1 -0
- package/self/self/bench/_sf_loop-sum-10k.js +1 -0
- package/self/self/bench/_sf_set-x.js +3 -0
- package/self/self/bench/_sf_throw-catch.js +1 -0
- package/self/self/bench/_sf_while-5.js +3 -0
- package/self/stdlib/ai.fl +73 -0
- package/self/stdlib/assert.fl +30 -0
- package/self/stdlib/async.fl +48 -0
- package/self/stdlib/base64.fl +22 -0
- package/self/stdlib/binary.fl +30 -0
- package/self/stdlib/build.fl +69 -0
- package/self/stdlib/collection.fl +37 -0
- package/self/stdlib/color.fl +35 -0
- package/self/stdlib/crypto-hash.fl +29 -0
- package/self/stdlib/crypto.fl +56 -0
- package/self/stdlib/data.fl +69 -0
- package/self/stdlib/db.fl +53 -0
- package/self/stdlib/encoding.fl +49 -0
- package/self/stdlib/error.fl +36 -0
- package/self/stdlib/feed.fl +86 -0
- package/self/stdlib/file.fl +53 -0
- package/self/stdlib/format.fl +34 -0
- package/self/stdlib/graph.fl +72 -0
- package/self/stdlib/hash.fl +32 -0
- package/self/stdlib/heap.fl +76 -0
- package/self/stdlib/http.fl +47 -0
- package/self/stdlib/image.fl +45 -0
- package/self/stdlib/json.fl +11 -0
- package/self/stdlib/list-extra.fl +32 -0
- package/self/stdlib/markdown.fl +59 -0
- package/self/stdlib/math-extra.fl +34 -0
- package/self/stdlib/math.fl +13 -0
- package/self/stdlib/metadata.fl +66 -0
- package/self/stdlib/mongodb/bson.fl +21 -0
- package/self/stdlib/mongodb/schema.fl +95 -0
- package/self/stdlib/mongodb/wire.fl +54 -0
- package/self/stdlib/mongodb.fl +172 -0
- package/self/stdlib/path.fl +72 -0
- package/self/stdlib/plot.fl +56 -0
- package/self/stdlib/process.fl +50 -0
- package/self/stdlib/queue.fl +65 -0
- package/self/stdlib/regex.fl +11 -0
- package/self/stdlib/resource.fl +61 -0
- package/self/stdlib/search.fl +54 -0
- package/self/stdlib/set-extra.fl +35 -0
- package/self/stdlib/sort.fl +61 -0
- package/self/stdlib/stack.fl +54 -0
- package/self/stdlib/stats.fl +110 -0
- package/self/stdlib/stream.fl +56 -0
- package/self/stdlib/string-extended.fl +25 -0
- package/self/stdlib/string-extra.fl +40 -0
- package/self/stdlib/string.fl +21 -0
- package/self/stdlib/test-helpers.fl +51 -0
- package/self/stdlib/test-runner.fl +76 -0
- package/self/stdlib/time-extra.fl +27 -0
- package/self/stdlib/time.fl +31 -0
- package/self/stdlib/tree.fl +57 -0
- package/self/stdlib/types.fl +85 -0
- package/self/stdlib/url.fl +33 -0
- package/self/stdlib/uuid.fl +28 -0
- package/self/stdlib/validation.fl +42 -0
- package/self/stdlib/vector-math.fl +52 -0
- package/self/stdlib/ws.fl +52 -0
- package/self/tests/mongodb-phase3.fl +75 -0
- package/self/tests/mongodb-wire-phase2.fl +45 -0
- package/self/tests/test-ast.fl +36 -0
- package/self/tests/test-builtins.fl +340 -0
- package/self/tests/test-char-class.fl +29 -0
- package/self/tests/test-codegen-builtins.fl +240 -0
- package/self/tests/test-codegen-ext.fl +380 -0
- package/self/tests/test-codegen-ffi.fl +295 -0
- package/self/tests/test-codegen-fn.fl +177 -0
- package/self/tests/test-codegen-match.fl +161 -0
- package/self/tests/test-codegen-run.fl +252 -0
- package/self/tests/test-codegen-sf.fl +262 -0
- package/self/tests/test-codegen.fl +260 -0
- package/self/tests/test-core-fl.fl +63 -0
- package/self/tests/test-forward-decl.fl +5 -0
- package/self/tests/test-func-block.fl +4 -0
- package/self/tests/test-interp-user-fn.fl +296 -0
- package/self/tests/test-interp.fl +225 -0
- package/self/tests/test-lexer.fl +162 -0
- package/self/tests/test-list-debug.fl +21 -0
- package/self/tests/test-mutual-rec.fl +6 -0
- package/self/tests/test-parser-debug.fl +35 -0
- package/self/tests/test-parser-full-debug.fl +66 -0
- package/self/tests/test-parser-lex-debug.fl +107 -0
- package/self/tests/test-parser-lex-only.fl +40 -0
- package/self/tests/test-parser-simple-debug.fl +35 -0
- package/self/tests/test-parser.fl +262 -0
- package/self/tests/test-real-stdlib.fl +377 -0
- package/self/tests/test-scope.fl +74 -0
- package/self/tests/test-selfcompile.fl +325 -0
- package/self/tests/test-stdlib.fl +44 -0
- package/self/tests/test-tco.fl +16 -0
- package/self/tests/test-token.fl +4 -0
- package/self/token.fl +38 -0
- package/self/token.self.js +8 -0
- package/self/v12-driver.fl +16 -0
- package/self/verify.fl +39 -0
- package/self-evolve/1-observe-ast.fl +28 -0
- package/self-evolve/2-inspect-block.fl +35 -0
- package/self-evolve/3-full-ast-json.fl +10 -0
- package/self-evolve/4-trace-block-fields.fl +23 -0
- package/self-evolve/5-analyze-do-ast.fl +29 -0
- package/self-evolve/6-test-do-elim-simple.fl +14 -0
- package/self-evolve/debug-evaluate.fl +24 -0
- package/self-evolve/debug-gen1-const-fold.fl +57 -0
- package/self-evolve/debug-map.fl +15 -0
- package/self-evolve/debug-optimize-simple.fl +95 -0
- package/self-evolve/debug-recursive-map.fl +23 -0
- package/self-evolve/logs/gen-0.fl +1658 -0
- package/self-evolve/logs/gen-1.fl +1658 -0
- package/self-evolve/logs/gen-2.fl +1658 -0
- package/self-evolve/logs/speed-gen-0.fl +1423 -0
- package/self-evolve/run-semantic-test.js +130 -0
- package/self-evolve/test-basic.fl +19 -0
- package/self-evolve/test-fold-direct.fl +60 -0
- package/self-evolve/test-gen1-simple.fl +67 -0
- package/self-evolve/test-optimize-debug.fl +63 -0
- package/self-evolve/tmp-test.fl +1 -0
- package/self-evolve/v11-analyzer.fl +40 -0
- package/self-evolve/v11-benchmark.fl +45 -0
- package/self-evolve/v11-evolution-real.fl +45 -0
- package/self-evolve/v11-evolution.fl +32 -0
- package/self-evolve/v11-gen1-validate.fl +157 -0
- package/self-evolve/v11-optimizer-constant-fold.fl +124 -0
- package/self-evolve/v11-optimizer-dead-expr.fl +111 -0
- package/self-evolve/v11-optimizer-gen1-complete.fl +180 -0
- package/self-evolve/v11-optimizer-gen1.fl +68 -0
- package/self-evolve/v11-optimizer.fl +56 -0
- package/self-evolve/v11-semantic-test.fl +54 -0
- package/self-evolve/v11-speed-benchmark.fl +106 -0
- package/self-evolve/v11-speed-optimizer.fl +79 -0
- package/src/AGENT-DSL.md +527 -0
- package/src/CLI-DEPLOYMENT.md +204 -0
- package/src/CLI.md +361 -0
- package/src/EXPRESS-ADVANCED.md +294 -0
- package/src/EXPRESS-AUTH.md +365 -0
- package/src/EXPRESS-CACHE.md +409 -0
- package/src/EXPRESS-COMPLETE.md +569 -0
- package/src/EXPRESS-README.md +121 -0
- package/src/EXPRESS-TEST.md +492 -0
- package/src/EXPRESS-WEBSOCKET.md +391 -0
- package/src/LOGGING-GUIDE.md +354 -0
- package/src/STORAGE-GUIDE.md +416 -0
- package/src/__tests__/advanced.test.ts +573 -0
- package/src/__tests__/ai-library.test.ts +210 -0
- package/src/__tests__/build-determinism.test.ts +33 -0
- package/src/__tests__/builtins-advanced.test.ts +150 -0
- package/src/__tests__/builtins-sanity.test.ts +180 -0
- package/src/__tests__/codegen.let.test.ts +81 -0
- package/src/__tests__/core.test.ts +188 -0
- package/src/__tests__/coverage-boost.test.ts +626 -0
- package/src/__tests__/cron-scheduler.test.ts +269 -0
- package/src/__tests__/enterprise-blocks.test.ts +63 -0
- package/src/__tests__/errors.test.ts +313 -0
- package/src/__tests__/integration.test.ts +219 -0
- package/src/__tests__/interpreter.test.ts +170 -0
- package/src/__tests__/l2-proof.test.ts +78 -0
- package/src/__tests__/lexer-parser.test.ts +366 -0
- package/src/__tests__/lexer.test.ts +106 -0
- package/src/__tests__/mariadb-prepared-statement.test.ts +206 -0
- package/src/__tests__/migrate.test.ts +403 -0
- package/src/__tests__/mongodb-integration.test.ts.skip +207 -0
- package/src/__tests__/mongodb-phase4.test.ts +132 -0
- package/src/__tests__/p1-1-parallel-tasks.test.ts +179 -0
- package/src/__tests__/p1-2-compensation.test.ts +242 -0
- package/src/__tests__/p1-3-distributed.test.ts +160 -0
- package/src/__tests__/p1-4-observability.test.ts +161 -0
- package/src/__tests__/parser.test.ts +142 -0
- package/src/__tests__/phase151-self-evolve.test.ts +161 -0
- package/src/__tests__/rate-limiter.test.ts +274 -0
- package/src/__tests__/self-hosting.test.ts +174 -0
- package/src/__tests__/semantic-preservation.test.ts +207 -0
- package/src/__tests__/setup.ts +34 -0
- package/src/__tests__/special-forms-advanced.test.ts +106 -0
- package/src/__tests__/stdlib-crypto-rsa.test.ts +122 -0
- package/src/__tests__/stdlib-f4.test.ts +159 -0
- package/src/__tests__/stdlib-helpers.test.ts +128 -0
- package/src/__tests__/stdlib-modules.test.ts +161 -0
- package/src/__tests__/stdlib-mongodb.test.ts +331 -0
- package/src/__tests__/stdlib-new.test.ts +269 -0
- package/src/__tests__/stdlib-perf.test.ts +125 -0
- package/src/__tests__/stdlib-phase-b.test.ts +249 -0
- package/src/__tests__/stdlib.test.ts +163 -0
- package/src/__tests__/v12-alpha.test.ts +205 -0
- package/src/__tests__/vm-optin.test.ts +141 -0
- package/src/__tests__/web-integration.test.ts +1452 -0
- package/src/__tests__/weblibs.test.ts +210 -0
- package/src/_aliases.json +1123 -0
- package/src/_mongodb_helper.js +272 -0
- package/src/_stdlib-signatures.json +1 -0
- package/src/agent-chain.ts +71 -0
- package/src/agent-dsl.fl +168 -0
- package/src/agent-example-error-handling.fl +51 -0
- package/src/agent-example-sequential.fl +66 -0
- package/src/agent-example-state-tracking.fl +70 -0
- package/src/agent.ts +393 -0
- package/src/align.ts +349 -0
- package/src/analogy.ts +78 -0
- package/src/ast-helpers.ts +199 -0
- package/src/ast.ts +817 -0
- package/src/async-runtime.ts +263 -0
- package/src/belief.ts +86 -0
- package/src/benchmark-self.ts +275 -0
- package/src/benchmarks/bench-interpreter.ts +73 -0
- package/src/benchmarks/bench-runner.ts +85 -0
- package/src/benchmarks/bench-vm.ts +128 -0
- package/src/browser-debug-panel.ts +220 -0
- package/src/browser-entry.ts +79 -0
- package/src/browser-stubs/child-process-stubs.ts +6 -0
- package/src/browser-stubs/crypto-stubs.ts +15 -0
- package/src/browser-stubs/misc-stubs.ts +4 -0
- package/src/browser-stubs/node-stubs.ts +17 -0
- package/src/browser-stubs/path-stubs.ts +6 -0
- package/src/bytecode.ts +41 -0
- package/src/causal.ts +258 -0
- package/src/chain-agents.ts +86 -0
- package/src/checkpoint.ts +106 -0
- package/src/ci-runner.ts +279 -0
- package/src/cli.ts +2136 -0
- package/src/codegen-js.ts +847 -0
- package/src/cognitive.ts +95 -0
- package/src/compete.ts +60 -0
- package/src/compiler.ts +267 -0
- package/src/compose-reason.ts +118 -0
- package/src/consensus.ts +109 -0
- package/src/context-window.ts +139 -0
- package/src/cot.ts +241 -0
- package/src/counterfactual.ts +268 -0
- package/src/critique.ts +77 -0
- package/src/crossover.ts +218 -0
- package/src/curiosity.ts +305 -0
- package/src/debate.ts +64 -0
- package/src/debug-api.ts +92 -0
- package/src/debugger.ts +185 -0
- package/src/delegate.ts +78 -0
- package/src/doc-extractor.ts +255 -0
- package/src/doc-renderer.ts +131 -0
- package/src/echo-server-demo.fl +17 -0
- package/src/error-formatter.ts +369 -0
- package/src/error-system.ts +88 -0
- package/src/errors.ts +281 -0
- package/src/ethics-check.ts +408 -0
- package/src/eval-ai-blocks.ts +182 -0
- package/src/eval-ai-handlers.ts +132 -0
- package/src/eval-builtins-ai.ts +1659 -0
- package/src/eval-builtins.ts +5956 -0
- package/src/eval-call-function.ts +665 -0
- package/src/eval-infra-blocks.ts +450 -0
- package/src/eval-module-system.ts +286 -0
- package/src/eval-pattern-match.ts +289 -0
- package/src/eval-phase150.ts +87 -0
- package/src/eval-reasoning-sequence.ts +218 -0
- package/src/eval-special-forms.ts +2154 -0
- package/src/eval-style-blocks.ts +193 -0
- package/src/eval-type-classes.ts +148 -0
- package/src/evolve.ts +276 -0
- package/src/explain.ts +345 -0
- package/src/express-advanced.fl +78 -0
- package/src/express-auth.fl +118 -0
- package/src/express-cache.fl +118 -0
- package/src/express-chat.fl +81 -0
- package/src/express-example.fl +67 -0
- package/src/express-test.fl +331 -0
- package/src/express.fl +92 -0
- package/src/fitness.ts +238 -0
- package/src/fl-app-demo.fl +19 -0
- package/src/fl-files/fl-fmt.fl +29 -0
- package/src/fl-files/fl-lint.fl +61 -0
- package/src/fl-files/fl-test.fl +52 -0
- package/src/fl-http-demo.fl +19 -0
- package/src/fl-list-utils.fl +108 -0
- package/src/fl-math-lib.fl +14 -0
- package/src/fl-sdk.ts +154 -0
- package/src/fl-server-demo.fl +74 -0
- package/src/fl-str-utils.fl +29 -0
- package/src/fl-tutor.ts +126 -0
- package/src/formatter.ts +581 -0
- package/src/freelang-codegen.fl +904 -0
- package/src/freelang-interpreter.fl +483 -0
- package/src/freelang-lexer.fl +337 -0
- package/src/freelang-parser.fl +349 -0
- package/src/freelang-stdlib.fl +246 -0
- package/src/freelang-typechecker.fl +422 -0
- package/src/freelang-v9-complete.ts +474 -0
- package/src/generation.ts +201 -0
- package/src/gpt-mini-p3.fl +316 -0
- package/src/hot-reload.ts +235 -0
- package/src/http-server-runner.ts +89 -0
- package/src/hypothesis.ts +62 -0
- package/src/immutable.ts +140 -0
- package/src/interpreter-context.ts +87 -0
- package/src/interpreter-scope.ts +140 -0
- package/src/interpreter.ts +2351 -0
- package/src/lazy-seq.ts +134 -0
- package/src/learned-facts-store.ts +306 -0
- package/src/lexer.ts +359 -0
- package/src/lint-rules.ts +584 -0
- package/src/linter.ts +237 -0
- package/src/logger.ts +128 -0
- package/src/logging-deterministic.fl +138 -0
- package/src/lsp-server.ts +379 -0
- package/src/macro-expander.ts +195 -0
- package/src/maybe-chain.ts +108 -0
- package/src/maybe-type.ts +163 -0
- package/src/memory-system.ts +142 -0
- package/src/meta-reason.ts +93 -0
- package/src/multi-agent-hub.ts +247 -0
- package/src/multi-agent.ts +101 -0
- package/src/mutate.ts +226 -0
- package/src/negotiate.ts +55 -0
- package/src/optimizer.ts +277 -0
- package/src/orchestrate.ts +154 -0
- package/src/package-manager.ts +375 -0
- package/src/parser.ts +2722 -0
- package/src/peer-review.ts +53 -0
- package/src/predict.ts +365 -0
- package/src/profiler.ts +150 -0
- package/src/prompt-compiler.ts +123 -0
- package/src/protocol.ts +114 -0
- package/src/prune.ts +195 -0
- package/src/quality-loop.ts +105 -0
- package/src/rag.ts +81 -0
- package/src/reasoning-debugger.ts +122 -0
- package/src/refactor-self.ts +362 -0
- package/src/reflect.ts +186 -0
- package/src/repl.ts +323 -0
- package/src/result-type.ts +126 -0
- package/src/return-signal.ts +10 -0
- package/src/runtime-entry.ts +8 -0
- package/src/runtime-helpers.ts +234 -0
- package/src/self-evolution-hub.ts +431 -0
- package/src/self-improve.ts +107 -0
- package/src/source-map.ts +114 -0
- package/src/stdlib-agent.js +164 -0
- package/src/stdlib-agent.ts +225 -0
- package/src/stdlib-ai-native.ts +176 -0
- package/src/stdlib-ai-workflow.ts +308 -0
- package/src/stdlib-ai.ts +180 -0
- package/src/stdlib-async.ts +179 -0
- package/src/stdlib-audit.ts +94 -0
- package/src/stdlib-auth.ts +196 -0
- package/src/stdlib-bits.ts +86 -0
- package/src/stdlib-blog.ts +127 -0
- package/src/stdlib-browser.ts +239 -0
- package/src/stdlib-cache.ts +147 -0
- package/src/stdlib-capture-error.ts +183 -0
- package/src/stdlib-channel.ts +96 -0
- package/src/stdlib-checkpoint.js +109 -0
- package/src/stdlib-checkpoint.ts +97 -0
- package/src/stdlib-cloud.ts +317 -0
- package/src/stdlib-collection.ts +227 -0
- package/src/stdlib-compile.ts +111 -0
- package/src/stdlib-cron.ts +219 -0
- package/src/stdlib-crypto-rsa.ts +82 -0
- package/src/stdlib-crypto.js +203 -0
- package/src/stdlib-crypto.ts +208 -0
- package/src/stdlib-data.ts +614 -0
- package/src/stdlib-db-query.ts +198 -0
- package/src/stdlib-db.ts +185 -0
- package/src/stdlib-distributed.ts +292 -0
- package/src/stdlib-error.ts +90 -0
- package/src/stdlib-fd.ts +130 -0
- package/src/stdlib-feed.ts +171 -0
- package/src/stdlib-file.ts +182 -0
- package/src/stdlib-helpers.ts +273 -0
- package/src/stdlib-http-macro.ts +178 -0
- package/src/stdlib-http-server.ts +1229 -0
- package/src/stdlib-http.ts +405 -0
- package/src/stdlib-image.ts +92 -0
- package/src/stdlib-kebab-aliases.ts +131 -0
- package/src/stdlib-lazy-registry.ts +106 -0
- package/src/stdlib-loader.ts +810 -0
- package/src/stdlib-mail.ts +251 -0
- package/src/stdlib-mariadb.ts +467 -0
- package/src/stdlib-markdown.ts +227 -0
- package/src/stdlib-matrix.ts +170 -0
- package/src/stdlib-middleware.ts +221 -0
- package/src/stdlib-module.ts +178 -0
- package/src/stdlib-mongodb.ts +174 -0
- package/src/stdlib-oci.ts +321 -0
- package/src/stdlib-optional.ts +56 -0
- package/src/stdlib-orm.ts +241 -0
- package/src/stdlib-perf.ts +140 -0
- package/src/stdlib-pg.ts +181 -0
- package/src/stdlib-plot.ts +196 -0
- package/src/stdlib-process.ts +120 -0
- package/src/stdlib-property.ts +157 -0
- package/src/stdlib-pubsub.ts +93 -0
- package/src/stdlib-queue-helpers.ts +92 -0
- package/src/stdlib-registry.ts +78 -0
- package/src/stdlib-resource.ts +553 -0
- package/src/stdlib-rest-crud.ts +146 -0
- package/src/stdlib-service.ts +206 -0
- package/src/stdlib-shell.ts +76 -0
- package/src/stdlib-stats.ts +172 -0
- package/src/stdlib-table.ts +200 -0
- package/src/stdlib-test-enhanced.ts +76 -0
- package/src/stdlib-test.ts +153 -0
- package/src/stdlib-time.js +217 -0
- package/src/stdlib-time.ts +282 -0
- package/src/stdlib-timer.ts +134 -0
- package/src/stdlib-totp.ts +110 -0
- package/src/stdlib-type-predicates.ts +136 -0
- package/src/stdlib-types.ts +107 -0
- package/src/stdlib-validation.ts +248 -0
- package/src/stdlib-verify.ts +181 -0
- package/src/stdlib-webauthn.ts +192 -0
- package/src/stdlib-workflow.js +715 -0
- package/src/stdlib-workflow.ts +950 -0
- package/src/stdlib-ws.ts +333 -0
- package/src/stdlib-wsc.test.ts +122 -0
- package/src/stdlib-wsc.ts +243 -0
- package/src/storage-unified.fl +279 -0
- package/src/streaming.ts +101 -0
- package/src/struct-system.ts +104 -0
- package/src/style-registry.ts +54 -0
- package/src/swarm.ts +89 -0
- package/src/tco.ts +31 -0
- package/src/test-advanced-patterns.ts +211 -0
- package/src/test-ast-debug.ts +20 -0
- package/src/test-ast-helpers.ts +208 -0
- package/src/test-async.ts +406 -0
- package/src/test-bootstrap-self-compile.ts +449 -0
- package/src/test-bootstrap-verification.ts +336 -0
- package/src/test-composition.ts +206 -0
- package/src/test-errors-phase6.ts +166 -0
- package/src/test-extended-monads.ts +313 -0
- package/src/test-field-parsing.ts +135 -0
- package/src/test-first-class-functions.ts +257 -0
- package/src/test-freelang-interpreter.ts +320 -0
- package/src/test-freelang-lexer.ts +306 -0
- package/src/test-freelang-parser.ts +268 -0
- package/src/test-fullstack-core.ts +258 -0
- package/src/test-fullstack-phase7-12.ts +305 -0
- package/src/test-fullstack-practical.ts +338 -0
- package/src/test-integration-stdlib.ts +195 -0
- package/src/test-interpreter-phase6.ts +305 -0
- package/src/test-lexer-comparison.ts +108 -0
- package/src/test-lexer-phase6.ts +271 -0
- package/src/test-modules.ts +325 -0
- package/src/test-monad-laws.ts +383 -0
- package/src/test-monads.ts +197 -0
- package/src/test-p0-checkpoint.ts +304 -0
- package/src/test-p0-conditional.ts +284 -0
- package/src/test-p0-error-handling.ts +231 -0
- package/src/test-p0-error-messages.ts +220 -0
- package/src/test-p1-1-parallel-tasks.js +214 -0
- package/src/test-parser-phase6.ts +222 -0
- package/src/test-performance.ts +206 -0
- package/src/test-phase10-data.ts +259 -0
- package/src/test-phase10-file.ts +216 -0
- package/src/test-phase100-stdlib-ai.ts +343 -0
- package/src/test-phase101-memory.ts +309 -0
- package/src/test-phase102-rag.ts +296 -0
- package/src/test-phase103-multi-agent.ts +418 -0
- package/src/test-phase104-try-reason.ts +459 -0
- package/src/test-phase105-streaming.ts +287 -0
- package/src/test-phase106-quality.ts +397 -0
- package/src/test-phase107-tutor.ts +305 -0
- package/src/test-phase108-debugger.ts +316 -0
- package/src/test-phase109-prompt-compiler.ts +333 -0
- package/src/test-phase11-12-complete.ts +275 -0
- package/src/test-phase11-error.ts +192 -0
- package/src/test-phase110-sdk.ts +320 -0
- package/src/test-phase111-hypothesis.ts +380 -0
- package/src/test-phase112-maybe-chain.ts +313 -0
- package/src/test-phase113-debate.ts +364 -0
- package/src/test-phase114-checkpoint.ts +348 -0
- package/src/test-phase115-meta-reason.ts +277 -0
- package/src/test-phase116-belief.ts +275 -0
- package/src/test-phase117-analogy.ts +325 -0
- package/src/test-phase118-critique.ts +308 -0
- package/src/test-phase119-compose.ts +434 -0
- package/src/test-phase12-http-shell.ts +120 -0
- package/src/test-phase120-cognitive.ts +297 -0
- package/src/test-phase121-consensus.ts +404 -0
- package/src/test-phase122-delegate.ts +411 -0
- package/src/test-phase123-vote.ts +339 -0
- package/src/test-phase124-negotiate.ts +403 -0
- package/src/test-phase125-swarm.ts +321 -0
- package/src/test-phase126-orchestrate.ts +343 -0
- package/src/test-phase127-peer-review.ts +279 -0
- package/src/test-phase128-chain-agents.ts +456 -0
- package/src/test-phase129-compete.ts +256 -0
- package/src/test-phase13-data.ts +223 -0
- package/src/test-phase130-hub.ts +390 -0
- package/src/test-phase131-evolve.ts +536 -0
- package/src/test-phase132-mutate.ts +268 -0
- package/src/test-phase133-crossover.ts +289 -0
- package/src/test-phase134-fitness.ts +306 -0
- package/src/test-phase135-generation.ts +328 -0
- package/src/test-phase136-prune.ts +228 -0
- package/src/test-phase137-refactor-self.ts +354 -0
- package/src/test-phase138-benchmark-self.ts +325 -0
- package/src/test-phase139-version-self.ts +278 -0
- package/src/test-phase14-collection.ts +254 -0
- package/src/test-phase140-self-evolution.ts +410 -0
- package/src/test-phase141-world-model.ts +387 -0
- package/src/test-phase142-causal.ts +384 -0
- package/src/test-phase143-counterfactual.ts +280 -0
- package/src/test-phase144-predict.ts +312 -0
- package/src/test-phase145-explain.ts +287 -0
- package/src/test-phase146-align.ts +439 -0
- package/src/test-phase147-ethics-check.ts +399 -0
- package/src/test-phase148-curiosity.ts +247 -0
- package/src/test-phase149-wisdom.ts +758 -0
- package/src/test-phase15-agent.ts +320 -0
- package/src/test-phase150-complete.ts +481 -0
- package/src/test-phase16-time.ts +292 -0
- package/src/test-phase17-crypto.ts +312 -0
- package/src/test-phase18-integration.ts +429 -0
- package/src/test-phase19-resource.ts +214 -0
- package/src/test-phase20-server-db.ts +160 -0
- package/src/test-phase21-ws-auth-cache-pubsub.ts +212 -0
- package/src/test-phase22-process.ts +166 -0
- package/src/test-phase23-selfhosting.ts +383 -0
- package/src/test-phase24-codegen.ts +236 -0
- package/src/test-phase25-bootstrap.ts +227 -0
- package/src/test-phase26-map-filter-reduce.ts +282 -0
- package/src/test-phase27-stdlib-codegen.ts +325 -0
- package/src/test-phase28-loop-recur.ts +182 -0
- package/src/test-phase29-import.ts +165 -0
- package/src/test-phase3-web-server.ts +234 -0
- package/src/test-phase30-selfcompile.ts +254 -0
- package/src/test-phase31-gen2-lexer.ts +251 -0
- package/src/test-phase33-gen3-bootstrap.ts +323 -0
- package/src/test-phase34-parser-tco.ts +268 -0
- package/src/test-phase35-error-messages.ts +280 -0
- package/src/test-phase36-sourcemap.ts +240 -0
- package/src/test-phase37-variadic.ts +228 -0
- package/src/test-phase38-destructuring.ts +261 -0
- package/src/test-phase39-do-block.ts +288 -0
- package/src/test-phase40-const-fold.ts +249 -0
- package/src/test-phase41-repl.ts +312 -0
- package/src/test-phase42-watch.ts +314 -0
- package/src/test-phase43-format.ts +377 -0
- package/src/test-phase44-check.ts +505 -0
- package/src/test-phase45-interpreter.ts +367 -0
- package/src/test-phase46-match.ts +390 -0
- package/src/test-phase47-file-io.ts +338 -0
- package/src/test-phase48-types.ts +308 -0
- package/src/test-phase49-stdlib.ts +365 -0
- package/src/test-phase5-week1.ts +160 -0
- package/src/test-phase50-fl-server.ts +159 -0
- package/src/test-phase51-transformer.ts +152 -0
- package/src/test-phase52-import.ts +161 -0
- package/src/test-phase53-training.ts +122 -0
- package/src/test-phase54-fl-utils.ts +122 -0
- package/src/test-phase55-http-client.ts +182 -0
- package/src/test-phase56-lexical-scope.ts +230 -0
- package/src/test-phase58-module-refactor.ts +298 -0
- package/src/test-phase59-errors.ts +226 -0
- package/src/test-phase6-compile.ts +227 -0
- package/src/test-phase60-types.ts +457 -0
- package/src/test-phase61-tco.ts +209 -0
- package/src/test-phase63-macros.ts +191 -0
- package/src/test-phase64-protocols.ts +451 -0
- package/src/test-phase65-patterns.ts +301 -0
- package/src/test-phase66-structs.ts +215 -0
- package/src/test-phase67-concurrency.ts +348 -0
- package/src/test-phase68-pipeline.ts +209 -0
- package/src/test-phase69-lazy.ts +237 -0
- package/src/test-phase7-registry.ts +236 -0
- package/src/test-phase70-immutable.ts +488 -0
- package/src/test-phase71-ai-native.ts +252 -0
- package/src/test-phase72-integration.ts +533 -0
- package/src/test-phase73-formatter.ts +361 -0
- package/src/test-phase74-linter.ts +565 -0
- package/src/test-phase75-repl.ts +227 -0
- package/src/test-phase76-testrunner.ts +439 -0
- package/src/test-phase77-doc.ts +416 -0
- package/src/test-phase78-debugger.ts +370 -0
- package/src/test-phase79-watch.ts +224 -0
- package/src/test-phase8-oci.ts +264 -0
- package/src/test-phase80-ci.ts +282 -0
- package/src/test-phase81-pkg.ts +383 -0
- package/src/test-phase82-profiler.ts +336 -0
- package/src/test-phase83-vm.ts +318 -0
- package/src/test-phase84-optimizer.ts +424 -0
- package/src/test-phase85-codegen.ts +380 -0
- package/src/test-phase86-lsp.ts +533 -0
- package/src/test-phase87-packages.ts +277 -0
- package/src/test-phase88-selfhost.ts +412 -0
- package/src/test-phase89-bench.ts +361 -0
- package/src/test-phase9-flnext-v2.ts +372 -0
- package/src/test-phase9-learn.ts +241 -0
- package/src/test-phase9-reasoning.ts +312 -0
- package/src/test-phase9-search.ts +212 -0
- package/src/test-phase90-release.ts +365 -0
- package/src/test-phase91-maybe.ts +257 -0
- package/src/test-phase92-cot.ts +438 -0
- package/src/test-phase93-tot.ts +462 -0
- package/src/test-phase94-reflect.ts +498 -0
- package/src/test-phase95-context.ts +268 -0
- package/src/test-phase96-errors.ts +296 -0
- package/src/test-phase97-tools.ts +344 -0
- package/src/test-phase98-agent.ts +370 -0
- package/src/test-phase99-self-improve.ts +394 -0
- package/src/test-phase9a-websearch.ts +283 -0
- package/src/test-phase9ab-integration.ts +140 -0
- package/src/test-phase9b-persistence.ts +448 -0
- package/src/test-phase9c-conditional.ts +251 -0
- package/src/test-phase9c-extension.ts +270 -0
- package/src/test-phase9c-feedback.ts +263 -0
- package/src/test-phase9c-loop.ts +239 -0
- package/src/test-selfhosting-sh1.ts +41 -0
- package/src/test-selfhosting-sh2.ts +84 -0
- package/src/test-selfhosting-sh3.ts +61 -0
- package/src/test-selfhosting-sh4.ts +65 -0
- package/src/test-type-classes-dispatch.ts +202 -0
- package/src/test-type-classes.ts +320 -0
- package/src/test-type-inference.ts +464 -0
- package/src/test-typeclass-parsing-final.ts +218 -0
- package/src/test-typeclass-parsing.ts +264 -0
- package/src/todo-server-30116.ts +53 -0
- package/src/token.ts +130 -0
- package/src/tool-registry.ts +195 -0
- package/src/tot.ts +258 -0
- package/src/try-reason.ts +109 -0
- package/src/type-check-static.ts +417 -0
- package/src/type-checker.ts +245 -0
- package/src/type-inference.ts +271 -0
- package/src/type-system.ts +169 -0
- package/src/version-self.ts +219 -0
- package/src/vm-eligible.ts +106 -0
- package/src/vm.ts +219 -0
- package/src/vote.ts +127 -0
- package/src/vpm/checksum-test.fl +193 -0
- package/src/vpm/checksum.fl +219 -0
- package/src/vpm/error-test.fl +211 -0
- package/src/vpm/error.fl +218 -0
- package/src/vpm/lock-file.fl +380 -0
- package/src/vpm/logging-test.fl +194 -0
- package/src/vpm/logging.fl +294 -0
- package/src/vpm/resolver-test.fl +117 -0
- package/src/vpm/resolver.fl +618 -0
- package/src/vpm/semver-test.fl +180 -0
- package/src/vpm/semver.fl +143 -0
- package/src/vpm-cli.ts +1955 -0
- package/src/web/app-router.ts +286 -0
- package/src/web/fl-executor.ts +655 -0
- package/src/web/image-optimizer.ts +206 -0
- package/src/web/index.ts +14 -0
- package/src/web/page-renderer.ts +287 -0
- package/src/web/server.ts +553 -0
- package/src/web-search-adapter.ts +348 -0
- package/src/wisdom.ts +441 -0
- package/src/world-model.ts +348 -0
- package/stdlib/cache.fl +42 -0
- package/stdlib/csv.fl +38 -0
- package/stdlib/date-ext.fl +68 -0
- package/stdlib/log.fl +44 -0
- package/stdlib/math-ext.fl +57 -0
- package/stdlib/number-ext.fl +47 -0
- package/stdlib/queue.fl +57 -0
- package/stdlib/string-ext.fl +45 -0
- package/stdlib/validate.fl +123 -0
- package/stdlib/web/components.fl +125 -0
- package/stdlib/web/csrf.fl +61 -0
- package/stdlib/web/format.fl +75 -0
- package/stdlib/web/forms.fl +94 -0
- package/stdlib/web/image.fl +77 -0
- package/stdlib/web/metadata.fl +85 -0
- package/stdlib/web/pagination.fl +62 -0
- package/stdlib/web/state.fl +167 -0
- package/stdlib/web/styles.fl +68 -0
- package/stdlib/web/toast.fl +62 -0
- package/stdlib/web/v9-stdlib-dom.fl +92 -0
- package/stdlib/web/v9-stdlib-fetch.fl +90 -0
- package/stdlib/web/v9-stdlib-storage.fl +70 -0
- package/stdlib/web/v9-stdlib-ui.fl +115 -0
- package/stdlib/web/ws-client.fl +125 -0
- package/tests/.v11-backup/test-migrate-sample.fl +22 -0
- package/tests/PHASE-C-VERIFICATION-REPORT.md +125 -0
- package/tests/benchmark-v11.1.js +103 -0
- package/tests/evidence/01-about.html +1 -0
- package/tests/evidence/02-post-hello.html +1 -0
- package/tests/evidence/02-post-world.html +1 -0
- package/tests/evidence/03-home.html +1 -0
- package/tests/evidence/04-dist/404.html +1 -0
- package/tests/evidence/04-dist/about/index.html +1 -0
- package/tests/evidence/04-dist/index.html +1 -0
- package/tests/evidence/04-dist/post/hello/index.html +1 -0
- package/tests/evidence/04-dist/post/world/index.html +1 -0
- package/tests/evidence/05-dist/404.html +1 -0
- package/tests/evidence/05-dist/about/index.html +1 -0
- package/tests/evidence/05-dist/index.html +1 -0
- package/tests/evidence/05-dist/post/hello/index.html +1 -0
- package/tests/evidence/05-dist/post/world/index.html +1 -0
- package/tests/evidence/06-dist/404.html +1 -0
- package/tests/evidence/06-dist/about/index.html +1 -0
- package/tests/evidence/06-dist/index.html +1 -0
- package/tests/evidence/06-dist/post/hello/index.html +1 -0
- package/tests/evidence/06-dist/post/world/index.html +1 -0
- package/tests/evidence/07-markdown.html +1 -0
- package/tests/evidence/08-rss.xml +25 -0
- package/tests/evidence/09-robots.txt +4 -0
- package/tests/evidence/09-sitemap.xml +12 -0
- package/tests/evidence/10-jsonld.html +1 -0
- package/tests/evidence/_results.txt +11 -0
- package/tests/evidence/about.html +1 -0
- package/tests/evidence/home.html +1 -0
- package/tests/evidence/missing.html +42 -0
- package/tests/evidence/post-hello.html +1 -0
- package/tests/evidence/post-world.html +1 -0
- package/tests/fixtures/basic-app/about/page.fl +1 -0
- package/tests/fixtures/basic-app/api/echo/route.fl +5 -0
- package/tests/fixtures/basic-app/layout.fl +1 -0
- package/tests/fixtures/basic-app/not-found.fl +1 -0
- package/tests/fixtures/basic-app/page.fl +1 -0
- package/tests/fixtures/basic-app/post/[slug]/generate-static-params.fl +1 -0
- package/tests/fixtures/basic-app/post/[slug]/page.fl +1 -0
- package/tests/fixtures/stdlib-probes/blog.fl +6 -0
- package/tests/fixtures/stdlib-probes/jsonld.fl +1 -0
- package/tests/fixtures/stdlib-probes/map-probe.fl +3 -0
- package/tests/fixtures/stdlib-probes/map-shape.fl +2 -0
- package/tests/fixtures/stdlib-probes/md.fl +1 -0
- package/tests/fixtures/stdlib-probes/robots.fl +1 -0
- package/tests/fixtures/stdlib-probes/rss.fl +4 -0
- package/tests/fixtures/stdlib-probes/sitemap.fl +1 -0
- package/tests/l2/case-01-arithmetic.fl +6 -0
- package/tests/l2/case-02-comparisons.fl +15 -0
- package/tests/l2/case-03-logic.fl +15 -0
- package/tests/l2/case-04-control-flow.fl +15 -0
- package/tests/l2/case-05-functions.fl +13 -0
- package/tests/l2/case-06-collections.fl +14 -0
- package/tests/l2/case-07-pattern-matching.fl +14 -0
- package/tests/l2/case-08-recursion.fl +19 -0
- package/tests/l2/case-09-strings.fl +13 -0
- package/tests/l2/case-10-loops.fl +17 -0
- package/tests/l2/case-11-higher-order.fl +13 -0
- package/tests/l2/case-12-edge-cases.fl +14 -0
- package/tests/l2/case-13-ai-vector.fl +22 -0
- package/tests/l2/case-14-ai-cosine.fl +25 -0
- package/tests/l2/case-15-ai-template.fl +22 -0
- package/tests/l2/case-16-ai-ranking.fl +20 -0
- package/tests/l2/case-17-stdlib-extended.fl +32 -0
- package/tests/l2-proof/01-arithmetic.bootstrap.js +141 -0
- package/tests/l2-proof/01-arithmetic.fl +15 -0
- package/tests/l2-proof/01-arithmetic.stage1.js +141 -0
- package/tests/l2-proof/02-comparisons.bootstrap.js +141 -0
- package/tests/l2-proof/02-comparisons.fl +17 -0
- package/tests/l2-proof/03-logic.bootstrap.js +141 -0
- package/tests/l2-proof/03-logic.fl +15 -0
- package/tests/l2-proof/04-control-flow.bootstrap.js +146 -0
- package/tests/l2-proof/04-control-flow.fl +24 -0
- package/tests/l2-proof/05-functions.bootstrap.js +143 -0
- package/tests/l2-proof/05-functions.fl +16 -0
- package/tests/l2-proof/06-collections.bootstrap.js +146 -0
- package/tests/l2-proof/06-collections.fl +27 -0
- package/tests/l2-proof/07-pattern-matching.bootstrap.js +142 -0
- package/tests/l2-proof/07-pattern-matching.fl +23 -0
- package/tests/l2-proof/08-async-errors.bootstrap.js +142 -0
- package/tests/l2-proof/08-async-errors.fl +17 -0
- package/tests/l2-proof/09-strings.bootstrap.js +141 -0
- package/tests/l2-proof/09-strings.fl +13 -0
- package/tests/l2-proof/10-type-checks.bootstrap.js +141 -0
- package/tests/l2-proof/10-type-checks.fl +17 -0
- package/tests/l2-proof/11-recursion.bootstrap.js +143 -0
- package/tests/l2-proof/11-recursion.fl +21 -0
- package/tests/l2-proof/12-edge-cases.bootstrap.js +141 -0
- package/tests/l2-proof/12-edge-cases.fl +17 -0
- package/tests/parity/01-app-router-static.sh +18 -0
- package/tests/parity/02-app-router-dynamic.sh +18 -0
- package/tests/parity/03-layout-children.sh +17 -0
- package/tests/parity/04-not-found.sh +22 -0
- package/tests/parity/05-ssg.sh +21 -0
- package/tests/parity/06-parallel-render.sh +21 -0
- package/tests/parity/07-markdown.sh +16 -0
- package/tests/parity/08-rss-atom.sh +18 -0
- package/tests/parity/09-sitemap-robots.sh +23 -0
- package/tests/parity/10-jsonld.sh +16 -0
- package/tests/parity/11-blog-helpers.sh +28 -0
- package/tests/parity/12-api-routes.sh +25 -0
- package/tests/parity/_lib.sh +53 -0
- package/tests/parity/run-all.sh +89 -0
- package/tests/parity/score.sh +20 -0
- package/tests/phase-c-fuzzing.fl +89 -0
- package/tests/phase-c-property-testing.fl +137 -0
- package/tests/phase-c-sha-verification.fl +117 -0
- package/tests/phase-c-validation.fl +194 -0
- package/tests/property-testing.sh +47 -0
- package/tests/regen/let-in-expr-01.fl +5 -0
- package/tests/regen/let-in-expr-02.fl +6 -0
- package/tests/regen/let-in-expr-03.fl +4 -0
- package/tests/regen/let-in-expr-04.fl +6 -0
- package/tests/regen/let-in-expr-05.fl +5 -0
- package/tests/test-ai-library.fl +36 -0
- package/tests/test-andor.fl +2 -0
- package/tests/test-bootstrap-match.fl +5 -0
- package/tests/test-cg-final.fl +5 -0
- package/tests/test-cli.fl +19 -0
- package/tests/test-codegen.fl +4 -0
- package/tests/test-cond-flat.fl +1 -0
- package/tests/test-fl-exec-op.fl +1 -0
- package/tests/test-fp.fl +10 -0
- package/tests/test-funcs.fl +11 -0
- package/tests/test-fuzz-crash.fl +3 -0
- package/tests/test-http-get.fl +3 -0
- package/tests/test-json-load.fl +32 -0
- package/tests/test-let-flat.fl +2 -0
- package/tests/test-let-order.fl +3 -0
- package/tests/test-let-simple.fl +3 -0
- package/tests/test-let-syntax.fl +2 -0
- package/tests/test-let.fl +3 -0
- package/tests/test-lex-debug.fl +75 -0
- package/tests/test-loop-bug.fl +5 -0
- package/tests/test-map-entries.fl +1 -0
- package/tests/test-map-pattern.fl +3 -0
- package/tests/test-match-syntax.fl +5 -0
- package/tests/test-migrate-sample.fl +22 -0
- package/tests/test-neg.fl +1 -0
- package/tests/test-nested-let.fl +4 -0
- package/tests/test-node-to-pattern.fl +8 -0
- package/tests/test-quant-lib.fl +114 -0
- package/tests/test-reduce.fl +10 -0
- package/tests/test-server.fl +3 -0
- package/tests/test-simple-map.fl +4 -0
- package/tests/test-simple-match.fl +3 -0
- package/tests/test-simple.fl +1 -0
- package/tests/test-try-bootstrap.fl +7 -0
- package/tests/test-try-catch.fl +3 -0
- package/tests/test-watchdog-lib.fl +69 -0
- package/tests/test-which-lex.fl +4 -0
- package/tsconfig.json +39 -0
|
@@ -0,0 +1,1659 @@
|
|
|
1
|
+
// eval-builtins-ai.ts — AI Phase 함수들 분리 모듈
|
|
2
|
+
// Phase 137: REFACTOR-SELF
|
|
3
|
+
// Phase 141: WORLD-MODEL
|
|
4
|
+
// Phase 143: COUNTERFACTUAL
|
|
5
|
+
// Phase 144: PREDICT
|
|
6
|
+
// Phase 145: EXPLAIN
|
|
7
|
+
// Phase 146: ALIGN
|
|
8
|
+
// Phase 147: ETHICS-CHECK
|
|
9
|
+
// Phase 148: CURIOSITY
|
|
10
|
+
// Phase 149: WISDOM
|
|
11
|
+
// (eval-builtins.ts에서 lines 5162-6793 분리)
|
|
12
|
+
|
|
13
|
+
import { Interpreter } from "./interpreter";
|
|
14
|
+
import { PruneResult } from "./prune";
|
|
15
|
+
import { SelfRefactorer, globalRefactorer, RefactorSuggestion, RefactorResult } from "./refactor-self";
|
|
16
|
+
import { AlignmentSystem, globalAlignment, Goal, Value, Action } from "./align";
|
|
17
|
+
import { globalEthics, EthicsChecker, EthicsViolation, EthicsCheckResult, EthicsPrinciple, EthicsFramework } from "./ethics-check";
|
|
18
|
+
import { CuriosityEngine, globalCuriosity, KnowledgeGap, ExplorationResult, CuriosityState } from "./curiosity";
|
|
19
|
+
import { WisdomEngine, globalWisdom, Experience, Heuristic, WisdomJudgment } from "./wisdom";
|
|
20
|
+
import { CausalGraph, globalCausal, CausalNode, CausalEdge, CausalChain, CausalExplanation, whyCaused } from "./causal";
|
|
21
|
+
import { globalExplainer, DecisionExplanation, FeatureImportance, LocalExplanation } from "./explain";
|
|
22
|
+
import { globalWorldModel } from "./world-model";
|
|
23
|
+
import { globalCounterfactual, CounterfactualReasoner, Scenario } from "./counterfactual";
|
|
24
|
+
import { globalPredictor } from "./predict";
|
|
25
|
+
import { SelfBenchmark, globalBenchmark, BenchmarkResult, ComparisonResult, BenchmarkSuite } from "./benchmark-self";
|
|
26
|
+
|
|
27
|
+
// Phase 136: PruneResult → Map 변환 헬퍼
|
|
28
|
+
function pruneResultToMap<T>(result: PruneResult<T>): Map<string, any> {
|
|
29
|
+
const statsMap = new Map<string, any>([
|
|
30
|
+
["originalCount", result.stats.originalCount],
|
|
31
|
+
["keptCount", result.stats.keptCount],
|
|
32
|
+
["removedCount", result.stats.removedCount],
|
|
33
|
+
["avgFitnessKept", result.stats.avgFitnessKept],
|
|
34
|
+
["avgFitnessRemoved", result.stats.avgFitnessRemoved],
|
|
35
|
+
]);
|
|
36
|
+
return new Map<string, any>([
|
|
37
|
+
["kept", result.kept],
|
|
38
|
+
["removed", result.removed],
|
|
39
|
+
["keptRatio", result.keptRatio],
|
|
40
|
+
["strategy", result.strategy],
|
|
41
|
+
["stats", statsMap],
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// === Phase 137: REFACTOR-SELF 독립 헬퍼 ===
|
|
46
|
+
// (eval-builtins.ts 내 switch 블록 외부에서 refactor-* op 처리를 위해 export)
|
|
47
|
+
export function evalRefactorSelf(op: string, args: any[]): any | null {
|
|
48
|
+
if (op === "refactor-analyze") {
|
|
49
|
+
const code = String(args[0] ?? "");
|
|
50
|
+
const result = globalRefactorer.refactor(code, true);
|
|
51
|
+
return new Map<string, any>([
|
|
52
|
+
["suggestions", result.suggestions.map((s: RefactorSuggestion) => new Map<string, any>([
|
|
53
|
+
["pattern", s.pattern], ["location", s.location], ["original", s.original],
|
|
54
|
+
["suggested", s.suggested], ["reason", s.reason], ["impact", s.impact],
|
|
55
|
+
]))],
|
|
56
|
+
["applied", result.applied],
|
|
57
|
+
["skipped", result.skipped],
|
|
58
|
+
["score", new Map<string, any>([
|
|
59
|
+
["before", result.score.before], ["after", result.score.after], ["improvement", result.score.improvement],
|
|
60
|
+
])],
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
63
|
+
if (op === "refactor-suggest") {
|
|
64
|
+
const code = String(args[0] ?? "");
|
|
65
|
+
return globalRefactorer.suggest(code).map((s: RefactorSuggestion) => new Map<string, any>([
|
|
66
|
+
["pattern", s.pattern], ["location", s.location], ["original", s.original],
|
|
67
|
+
["suggested", s.suggested], ["reason", s.reason], ["impact", s.impact],
|
|
68
|
+
]));
|
|
69
|
+
}
|
|
70
|
+
if (op === "refactor-apply") {
|
|
71
|
+
const code = String(args[0] ?? "");
|
|
72
|
+
const rawSuggestions = Array.isArray(args[1]) ? args[1] : [];
|
|
73
|
+
const suggestions: RefactorSuggestion[] = rawSuggestions.map((s: any) => {
|
|
74
|
+
if (s instanceof Map) return {
|
|
75
|
+
pattern: s.get("pattern") ?? "extract-duplicate", location: s.get("location") ?? "",
|
|
76
|
+
original: s.get("original") ?? "", suggested: s.get("suggested") ?? "",
|
|
77
|
+
reason: s.get("reason") ?? "", impact: s.get("impact") ?? "low",
|
|
78
|
+
} as RefactorSuggestion;
|
|
79
|
+
return s as RefactorSuggestion;
|
|
80
|
+
});
|
|
81
|
+
const applyResult = globalRefactorer.apply(code, suggestions);
|
|
82
|
+
return new Map<string, any>([
|
|
83
|
+
["code", applyResult.code],
|
|
84
|
+
["applied", applyResult.applied.map((s: RefactorSuggestion) => new Map<string, any>([
|
|
85
|
+
["pattern", s.pattern], ["location", s.location], ["impact", s.impact],
|
|
86
|
+
]))],
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
if (op === "refactor-complexity") {
|
|
90
|
+
const code = String(args[0] ?? "");
|
|
91
|
+
const c = globalRefactorer.analyzeComplexity(code);
|
|
92
|
+
return new Map<string, any>([["lines", c.lines], ["depth", c.depth], ["conditions", c.conditions], ["score", c.score]]);
|
|
93
|
+
}
|
|
94
|
+
if (op === "refactor-quality") {
|
|
95
|
+
const code = String(args[0] ?? "");
|
|
96
|
+
return globalRefactorer.qualityScore(code);
|
|
97
|
+
}
|
|
98
|
+
if (op === "refactor-naming") {
|
|
99
|
+
const code = String(args[0] ?? "");
|
|
100
|
+
const n = globalRefactorer.analyzeNaming(code);
|
|
101
|
+
return new Map<string, any>([
|
|
102
|
+
["issues", n.issues.map((i: { name: string; suggestion: string; reason: string }) => new Map<string, any>([
|
|
103
|
+
["name", i.name], ["suggestion", i.suggestion], ["reason", i.reason],
|
|
104
|
+
]))],
|
|
105
|
+
["score", n.score],
|
|
106
|
+
]);
|
|
107
|
+
}
|
|
108
|
+
if (op === "refactor-duplicates") {
|
|
109
|
+
const code = String(args[0] ?? "");
|
|
110
|
+
return globalRefactorer.findDuplicates(code).map((s: RefactorSuggestion) => new Map<string, any>([
|
|
111
|
+
["pattern", s.pattern], ["location", s.location], ["original", s.original],
|
|
112
|
+
["suggested", s.suggested], ["reason", s.reason], ["impact", s.impact],
|
|
113
|
+
]));
|
|
114
|
+
}
|
|
115
|
+
if (op === "refactor-score") {
|
|
116
|
+
const r = args[0];
|
|
117
|
+
if (r instanceof Map) {
|
|
118
|
+
const score = r.get("score");
|
|
119
|
+
if (score instanceof Map) return new Map<string, any>([
|
|
120
|
+
["before", score.get("before") ?? 0], ["after", score.get("after") ?? 0], ["improvement", score.get("improvement") ?? 0],
|
|
121
|
+
]);
|
|
122
|
+
}
|
|
123
|
+
return new Map<string, any>([["before", 0], ["after", 0], ["improvement", 0]]);
|
|
124
|
+
}
|
|
125
|
+
// === Phase 142: CAUSAL ===
|
|
126
|
+
// (causal-add-node :id "rain" :name "비" :desc "강수")
|
|
127
|
+
if (op === "causal-add-node") {
|
|
128
|
+
const kw: Record<string, any> = {};
|
|
129
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
130
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
131
|
+
kw[key] = args[i + 1];
|
|
132
|
+
}
|
|
133
|
+
const node: CausalNode = {
|
|
134
|
+
id: String(kw["id"] ?? ""),
|
|
135
|
+
name: String(kw["name"] ?? kw["id"] ?? ""),
|
|
136
|
+
description: String(kw["desc"] ?? kw["description"] ?? ""),
|
|
137
|
+
value: kw["value"] !== undefined ? Number(kw["value"]) : undefined,
|
|
138
|
+
};
|
|
139
|
+
globalCausal.addNode(node);
|
|
140
|
+
return new Map<string, any>([["id", node.id], ["name", node.name], ["description", node.description]]);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// (causal-add-edge :from "rain" :to "wet-road" :strength 0.9 :confidence 0.95)
|
|
144
|
+
if (op === "causal-add-edge") {
|
|
145
|
+
const kw: Record<string, any> = {};
|
|
146
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
147
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
148
|
+
kw[key] = args[i + 1];
|
|
149
|
+
}
|
|
150
|
+
const edge: CausalEdge = {
|
|
151
|
+
from: String(kw["from"] ?? ""),
|
|
152
|
+
to: String(kw["to"] ?? ""),
|
|
153
|
+
strength: Number(kw["strength"] ?? 1),
|
|
154
|
+
confidence: Number(kw["confidence"] ?? 1),
|
|
155
|
+
delay: kw["delay"] !== undefined ? Number(kw["delay"]) : undefined,
|
|
156
|
+
mechanism: kw["mechanism"] !== undefined ? String(kw["mechanism"]) : undefined,
|
|
157
|
+
};
|
|
158
|
+
globalCausal.addEdge(edge);
|
|
159
|
+
return new Map<string, any>([["from", edge.from], ["to", edge.to], ["strength", edge.strength], ["confidence", edge.confidence]]);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// (causal-explain "wet-road") → CausalExplanation
|
|
163
|
+
if (op === "causal-explain") {
|
|
164
|
+
const effectId = String(args[0] ?? "");
|
|
165
|
+
const expl = globalCausal.explain(effectId);
|
|
166
|
+
return new Map<string, any>([
|
|
167
|
+
["effect", expl.effect],
|
|
168
|
+
["primaryCause", expl.primaryCause],
|
|
169
|
+
["explanation", expl.explanation],
|
|
170
|
+
["confidence", expl.confidence],
|
|
171
|
+
["causes", expl.causes.map(c => new Map<string, any>([
|
|
172
|
+
["cause", c.cause], ["contribution", c.contribution],
|
|
173
|
+
["chain", new Map<string, any>([
|
|
174
|
+
["path", c.chain.path], ["totalStrength", c.chain.totalStrength],
|
|
175
|
+
["explanation", c.chain.explanation], ["confidence", c.chain.confidence],
|
|
176
|
+
])],
|
|
177
|
+
]))],
|
|
178
|
+
]);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// (causal-chains "rain" "accident") → CausalChain[]
|
|
182
|
+
if (op === "causal-chains") {
|
|
183
|
+
const causeId = String(args[0] ?? "");
|
|
184
|
+
const effectId = String(args[1] ?? "");
|
|
185
|
+
const chains = globalCausal.findCausalChains(causeId, effectId);
|
|
186
|
+
return chains.map(c => new Map<string, any>([
|
|
187
|
+
["path", c.path], ["totalStrength", c.totalStrength],
|
|
188
|
+
["explanation", c.explanation], ["confidence", c.confidence],
|
|
189
|
+
]));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// (causal-causes "wet-road") → 직접 원인들
|
|
193
|
+
if (op === "causal-causes") {
|
|
194
|
+
const nodeId = String(args[0] ?? "");
|
|
195
|
+
const causes = globalCausal.getDirectCauses(nodeId);
|
|
196
|
+
return causes.map(e => new Map<string, any>([
|
|
197
|
+
["from", e.from], ["to", e.to], ["strength", e.strength], ["confidence", e.confidence],
|
|
198
|
+
]));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// (causal-effects "rain") → 직접 결과들
|
|
202
|
+
if (op === "causal-effects") {
|
|
203
|
+
const nodeId = String(args[0] ?? "");
|
|
204
|
+
const effects = globalCausal.getDirectEffects(nodeId);
|
|
205
|
+
return effects.map(e => new Map<string, any>([
|
|
206
|
+
["from", e.from], ["to", e.to], ["strength", e.strength], ["confidence", e.confidence],
|
|
207
|
+
]));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// (causal-roots "accident") → 루트 원인들
|
|
211
|
+
if (op === "causal-roots") {
|
|
212
|
+
const nodeId = String(args[0] ?? "");
|
|
213
|
+
return globalCausal.findRootCauses(nodeId);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// (causal-simulate {:rain 1.0}) → 파급효과 맵
|
|
217
|
+
if (op === "causal-simulate") {
|
|
218
|
+
const arg = args[0];
|
|
219
|
+
const interventions: Record<string, number> = {};
|
|
220
|
+
if (arg instanceof Map) {
|
|
221
|
+
for (const [k, v] of arg.entries()) {
|
|
222
|
+
interventions[String(k)] = Number(v);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const result = globalCausal.simulate(interventions);
|
|
226
|
+
return new Map<string, any>(Object.entries(result));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// (causal-why "effect-id" "cause-id") → CausalChain or nil
|
|
230
|
+
if (op === "causal-why") {
|
|
231
|
+
const effectId = String(args[0] ?? "");
|
|
232
|
+
const causeId = String(args[1] ?? "");
|
|
233
|
+
const chain = whyCaused(effectId, causeId);
|
|
234
|
+
if (chain === null) return null;
|
|
235
|
+
return new Map<string, any>([
|
|
236
|
+
["path", chain.path], ["totalStrength", chain.totalStrength],
|
|
237
|
+
["explanation", chain.explanation], ["confidence", chain.confidence],
|
|
238
|
+
]);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// (causal-summary "rain") → 요약 문자열
|
|
242
|
+
if (op === "causal-summary") {
|
|
243
|
+
const nodeId = String(args[0] ?? "");
|
|
244
|
+
return globalCausal.summarize(nodeId);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
// === Phase 146: ALIGN ===
|
|
250
|
+
export function evalAlign(op: string, args: any[]): any | null {
|
|
251
|
+
// (align-add-goal :id "g1" :desc "설명" :priority 9 :measurable true :metric "m" :target 100)
|
|
252
|
+
if (op === "align-add-goal") {
|
|
253
|
+
const kw: Record<string, any> = {};
|
|
254
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
255
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
256
|
+
kw[key] = args[i + 1];
|
|
257
|
+
}
|
|
258
|
+
const goal: Goal = {
|
|
259
|
+
id: String(kw["id"] ?? `goal_${Date.now()}`),
|
|
260
|
+
description: String(kw["desc"] ?? kw["description"] ?? ""),
|
|
261
|
+
priority: Number(kw["priority"] ?? 5),
|
|
262
|
+
measurable: Boolean(kw["measurable"] ?? false),
|
|
263
|
+
metric: kw["metric"] !== undefined ? String(kw["metric"]) : undefined,
|
|
264
|
+
target: kw["target"] !== undefined ? Number(kw["target"]) : undefined,
|
|
265
|
+
};
|
|
266
|
+
globalAlignment.addGoal(goal);
|
|
267
|
+
return new Map<string, any>([
|
|
268
|
+
["id", goal.id], ["description", goal.description],
|
|
269
|
+
["priority", goal.priority], ["measurable", goal.measurable],
|
|
270
|
+
]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// (align-add-value :id "v1" :name "정직" :desc "거짓말 안 함" :weight 0.9)
|
|
274
|
+
if (op === "align-add-value") {
|
|
275
|
+
const kw: Record<string, any> = {};
|
|
276
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
277
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
278
|
+
kw[key] = args[i + 1];
|
|
279
|
+
}
|
|
280
|
+
const value: Value = {
|
|
281
|
+
id: String(kw["id"] ?? `value_${Date.now()}`),
|
|
282
|
+
name: String(kw["name"] ?? ""),
|
|
283
|
+
description: String(kw["desc"] ?? kw["description"] ?? ""),
|
|
284
|
+
weight: Number(kw["weight"] ?? 0.5),
|
|
285
|
+
};
|
|
286
|
+
globalAlignment.addValue(value);
|
|
287
|
+
return new Map<string, any>([
|
|
288
|
+
["id", value.id], ["name", value.name],
|
|
289
|
+
["description", value.description], ["weight", value.weight],
|
|
290
|
+
]);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// (align-score $action) → AlignmentScore
|
|
294
|
+
if (op === "align-score") {
|
|
295
|
+
const actionRaw = args[0];
|
|
296
|
+
// FL map은 Map 또는 일반 object를 반환할 수 있음
|
|
297
|
+
const _getF = (obj: any, key: string): any => obj instanceof Map ? obj.get(key) : (obj && typeof obj === "object" ? obj[key] : undefined);
|
|
298
|
+
const _getEO = (obj: any): Record<string, number> => {
|
|
299
|
+
const eo = _getF(obj, "expectedOutcomes");
|
|
300
|
+
if (eo instanceof Map) return Object.fromEntries(eo);
|
|
301
|
+
if (eo && typeof eo === "object") return Object.fromEntries(Object.entries(eo).map(([k, v]) => [k, Number(v)]));
|
|
302
|
+
return {};
|
|
303
|
+
};
|
|
304
|
+
const action: Action = {
|
|
305
|
+
id: String(_getF(actionRaw, "id") ?? ""),
|
|
306
|
+
description: String(_getF(actionRaw, "description") ?? ""),
|
|
307
|
+
expectedOutcomes: _getEO(actionRaw),
|
|
308
|
+
risks: Array.isArray(_getF(actionRaw, "risks")) ? _getF(actionRaw, "risks") : [],
|
|
309
|
+
};
|
|
310
|
+
const result = globalAlignment.score(action);
|
|
311
|
+
return new Map<string, any>([
|
|
312
|
+
["action", actionRaw],
|
|
313
|
+
["goalAlignment", new Map(Object.entries(result.goalAlignment))],
|
|
314
|
+
["valueAlignment", new Map(Object.entries(result.valueAlignment))],
|
|
315
|
+
["overallScore", result.overallScore],
|
|
316
|
+
["conflicts", result.conflicts.map(c => new Map([["goal1", c.goal1], ["goal2", c.goal2], ["severity", c.severity]]))],
|
|
317
|
+
["recommendation", result.recommendation],
|
|
318
|
+
["reasons", result.reasons],
|
|
319
|
+
]);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// (align-best $actions) → 최적 Action
|
|
323
|
+
if (op === "align-best") {
|
|
324
|
+
const actionsList = Array.isArray(args[0]) ? args[0] : [];
|
|
325
|
+
const _getF2 = (obj: any, key: string): any => obj instanceof Map ? obj.get(key) : (obj && typeof obj === "object" ? obj[key] : undefined);
|
|
326
|
+
const _getEO2 = (obj: any): Record<string, number> => {
|
|
327
|
+
const eo = _getF2(obj, "expectedOutcomes");
|
|
328
|
+
if (eo instanceof Map) return Object.fromEntries(eo);
|
|
329
|
+
if (eo && typeof eo === "object") return Object.fromEntries(Object.entries(eo).map(([k, v]) => [k, Number(v)]));
|
|
330
|
+
return {};
|
|
331
|
+
};
|
|
332
|
+
const actions: Action[] = actionsList.map((m: any) => ({
|
|
333
|
+
id: String(_getF2(m, "id") ?? ""),
|
|
334
|
+
description: String(_getF2(m, "description") ?? ""),
|
|
335
|
+
expectedOutcomes: _getEO2(m),
|
|
336
|
+
risks: Array.isArray(_getF2(m, "risks")) ? _getF2(m, "risks") : [],
|
|
337
|
+
}));
|
|
338
|
+
if (actions.length === 0) return null;
|
|
339
|
+
const best = globalAlignment.selectBestAligned(actions);
|
|
340
|
+
return new Map<string, any>([
|
|
341
|
+
["id", best.id], ["description", best.description],
|
|
342
|
+
]);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// (align-conflicts) → 충돌 목록
|
|
346
|
+
if (op === "align-conflicts") {
|
|
347
|
+
const conflicts = globalAlignment.detectConflicts();
|
|
348
|
+
return conflicts.map(c => new Map<string, any>([
|
|
349
|
+
["goal1", c.goal1], ["goal2", c.goal2], ["description", c.description],
|
|
350
|
+
]));
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// (align-plan $actions) → 계획 평가
|
|
354
|
+
if (op === "align-plan") {
|
|
355
|
+
const actionsList = Array.isArray(args[0]) ? args[0] : [];
|
|
356
|
+
const _gFP = (obj: any, key: string): any => obj instanceof Map ? obj.get(key) : (obj && typeof obj === "object" ? obj[key] : undefined);
|
|
357
|
+
const _gEOP = (obj: any): Record<string, number> => {
|
|
358
|
+
const eo = _gFP(obj, "expectedOutcomes");
|
|
359
|
+
if (eo instanceof Map) return Object.fromEntries(eo);
|
|
360
|
+
if (eo && typeof eo === "object") return Object.fromEntries(Object.entries(eo).map(([k, v]) => [k, Number(v)]));
|
|
361
|
+
return {};
|
|
362
|
+
};
|
|
363
|
+
const actions: Action[] = actionsList.map((m: any) => ({
|
|
364
|
+
id: String(_gFP(m, "id") ?? ""),
|
|
365
|
+
description: String(_gFP(m, "description") ?? ""),
|
|
366
|
+
expectedOutcomes: _gEOP(m),
|
|
367
|
+
risks: Array.isArray(_gFP(m, "risks")) ? _gFP(m, "risks") : [],
|
|
368
|
+
}));
|
|
369
|
+
const result = globalAlignment.evaluatePlan(actions);
|
|
370
|
+
return new Map<string, any>([
|
|
371
|
+
["overallAlignment", result.overallAlignment],
|
|
372
|
+
["weakLinks", result.weakLinks.map(a => new Map([["id", a.id], ["description", a.description]]))],
|
|
373
|
+
["summary", result.summary],
|
|
374
|
+
]);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// (align-improve $action) → 개선 제안 목록
|
|
378
|
+
if (op === "align-improve") {
|
|
379
|
+
const actionRaw3 = args[0];
|
|
380
|
+
const _getF3 = (obj: any, key: string): any => obj instanceof Map ? obj.get(key) : (obj && typeof obj === "object" ? obj[key] : undefined);
|
|
381
|
+
const _getEO3 = (obj: any): Record<string, number> => {
|
|
382
|
+
const eo = _getF3(obj, "expectedOutcomes");
|
|
383
|
+
if (eo instanceof Map) return Object.fromEntries(eo);
|
|
384
|
+
if (eo && typeof eo === "object") return Object.fromEntries(Object.entries(eo).map(([k, v]) => [k, Number(v)]));
|
|
385
|
+
return {};
|
|
386
|
+
};
|
|
387
|
+
const action: Action = {
|
|
388
|
+
id: String(_getF3(actionRaw3, "id") ?? ""),
|
|
389
|
+
description: String(_getF3(actionRaw3, "description") ?? ""),
|
|
390
|
+
expectedOutcomes: _getEO3(actionRaw3),
|
|
391
|
+
risks: Array.isArray(_getF3(actionRaw3, "risks")) ? _getF3(actionRaw3, "risks") : [],
|
|
392
|
+
};
|
|
393
|
+
return globalAlignment.suggestImprovements(action);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// (align-goals) → 우선순위 정렬된 Goal 목록
|
|
397
|
+
if (op === "align-goals") {
|
|
398
|
+
const goals = globalAlignment.prioritizeGoals();
|
|
399
|
+
return goals.map(g => new Map<string, any>([
|
|
400
|
+
["id", g.id], ["description", g.description],
|
|
401
|
+
["priority", g.priority], ["measurable", g.measurable],
|
|
402
|
+
]));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// NOTE: Phase 144 code below is in separate evalPredict (called by evalBuiltin)
|
|
409
|
+
export function evalPredict_PHASE144(op: string, args: any[]): any | null {
|
|
410
|
+
// === Phase 144: PREDICT ===
|
|
411
|
+
// (predict-linear [1 2 3 4 5] :horizon 3) → Prediction
|
|
412
|
+
if (op === "predict-linear") {
|
|
413
|
+
const data144 = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
414
|
+
let horizon144 = 1;
|
|
415
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
416
|
+
const k = String(args[i]).replace(/^:/, "");
|
|
417
|
+
if (k === "horizon") horizon144 = Number(args[i + 1]);
|
|
418
|
+
}
|
|
419
|
+
const p144 = globalPredictor.linearRegression(data144, horizon144);
|
|
420
|
+
return new Map<string, any>([
|
|
421
|
+
["value", p144.value], ["lower", p144.lower], ["upper", p144.upper],
|
|
422
|
+
["confidence", p144.confidence], ["method", p144.method], ["horizon", p144.horizon ?? 1],
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// (predict-ma [1 2 3 4 5] :window 3 :horizon 2) → Prediction
|
|
427
|
+
if (op === "predict-ma") {
|
|
428
|
+
const data144ma = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
429
|
+
let window144 = 3;
|
|
430
|
+
let horizon144ma = 1;
|
|
431
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
432
|
+
const k = String(args[i]).replace(/^:/, "");
|
|
433
|
+
if (k === "window") window144 = Number(args[i + 1]);
|
|
434
|
+
else if (k === "horizon") horizon144ma = Number(args[i + 1]);
|
|
435
|
+
}
|
|
436
|
+
const pma = globalPredictor.movingAverage(data144ma, window144, horizon144ma);
|
|
437
|
+
return new Map<string, any>([
|
|
438
|
+
["value", pma.value], ["lower", pma.lower], ["upper", pma.upper],
|
|
439
|
+
["confidence", pma.confidence], ["method", pma.method], ["horizon", pma.horizon ?? 1],
|
|
440
|
+
]);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// (predict-exp [1 2 3 4 5] :alpha 0.3 :horizon 2) → Prediction
|
|
444
|
+
if (op === "predict-exp") {
|
|
445
|
+
const data144exp = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
446
|
+
let alpha144 = 0.3;
|
|
447
|
+
let horizon144exp = 1;
|
|
448
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
449
|
+
const k = String(args[i]).replace(/^:/, "");
|
|
450
|
+
if (k === "alpha") alpha144 = Number(args[i + 1]);
|
|
451
|
+
else if (k === "horizon") horizon144exp = Number(args[i + 1]);
|
|
452
|
+
}
|
|
453
|
+
const pexp = globalPredictor.exponentialSmoothing(data144exp, alpha144, horizon144exp);
|
|
454
|
+
return new Map<string, any>([
|
|
455
|
+
["value", pexp.value], ["lower", pexp.lower], ["upper", pexp.upper],
|
|
456
|
+
["confidence", pexp.confidence], ["method", pexp.method], ["horizon", pexp.horizon ?? 1],
|
|
457
|
+
]);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// (predict-forecast [1 2 3 4 5 4 3 4 5] :steps 3) → TimeSeriesPrediction
|
|
461
|
+
if (op === "predict-forecast") {
|
|
462
|
+
const data144ts = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
463
|
+
let steps144 = 3;
|
|
464
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
465
|
+
const k = String(args[i]).replace(/^:/, "");
|
|
466
|
+
if (k === "steps") steps144 = Number(args[i + 1]);
|
|
467
|
+
}
|
|
468
|
+
const tsResult = globalPredictor.forecastTimeSeries(data144ts, steps144);
|
|
469
|
+
return new Map<string, any>([
|
|
470
|
+
["predictions", tsResult.predictions.map(p => new Map<string, any>([
|
|
471
|
+
["value", p.value], ["lower", p.lower], ["upper", p.upper],
|
|
472
|
+
["confidence", p.confidence], ["method", p.method], ["horizon", p.horizon ?? 1],
|
|
473
|
+
]))],
|
|
474
|
+
["trend", tsResult.trend],
|
|
475
|
+
["seasonality", tsResult.seasonality ?? null],
|
|
476
|
+
["accuracy", tsResult.accuracy ?? null],
|
|
477
|
+
]);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// (predict-ci [1.1 1.2 0.9 1.0 1.3] :confidence 0.95) → {lower, upper}
|
|
481
|
+
if (op === "predict-ci") {
|
|
482
|
+
const samples144 = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
483
|
+
let conf144 = 0.95;
|
|
484
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
485
|
+
const k = String(args[i]).replace(/^:/, "");
|
|
486
|
+
if (k === "confidence") conf144 = Number(args[i + 1]);
|
|
487
|
+
}
|
|
488
|
+
const ci = globalPredictor.confidenceInterval(samples144, conf144);
|
|
489
|
+
return new Map<string, any>([["lower", ci.lower], ["upper", ci.upper]]);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// (predict-classify {:age 25 :income 50000} $training) → ClassificationPrediction
|
|
493
|
+
if (op === "predict-classify") {
|
|
494
|
+
const rawFeatures = args[0];
|
|
495
|
+
const features144: Record<string, number> = {};
|
|
496
|
+
if (rawFeatures instanceof Map) {
|
|
497
|
+
rawFeatures.forEach((v: any, k: any) => {
|
|
498
|
+
features144[String(k).replace(/^:/, "")] = Number(v);
|
|
499
|
+
});
|
|
500
|
+
} else if (typeof rawFeatures === "object" && rawFeatures !== null) {
|
|
501
|
+
Object.entries(rawFeatures).forEach(([k, v]) => {
|
|
502
|
+
features144[k.replace(/^:/, "")] = Number(v);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
const rawTraining = Array.isArray(args[1]) ? args[1] : [];
|
|
506
|
+
const trainingData144 = rawTraining.map((item: any) => {
|
|
507
|
+
if (item instanceof Map) {
|
|
508
|
+
const rawF = item.get("features") ?? item.get(":features");
|
|
509
|
+
const label = String(item.get("label") ?? item.get(":label") ?? "unknown");
|
|
510
|
+
const feats: Record<string, number> = {};
|
|
511
|
+
if (rawF instanceof Map) {
|
|
512
|
+
rawF.forEach((v: any, k: any) => { feats[String(k).replace(/^:/, "")] = Number(v); });
|
|
513
|
+
}
|
|
514
|
+
return { features: feats, label };
|
|
515
|
+
}
|
|
516
|
+
return { features: {}, label: "unknown" };
|
|
517
|
+
});
|
|
518
|
+
const clf = globalPredictor.classify(features144, trainingData144);
|
|
519
|
+
return new Map<string, any>([
|
|
520
|
+
["classes", clf.classes.map(c => new Map<string, any>([["label", c.label], ["probability", c.probability]]))],
|
|
521
|
+
["predicted", clf.predicted],
|
|
522
|
+
["confidence", clf.confidence],
|
|
523
|
+
]);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// (predict-evaluate [1 2 3] [1.1 2.2 2.9]) → {mae, rmse, mape}
|
|
527
|
+
if (op === "predict-evaluate") {
|
|
528
|
+
const preds144 = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
529
|
+
const actuals144 = Array.isArray(args[1]) ? args[1].map(Number) : [];
|
|
530
|
+
const evalResult = globalPredictor.evaluate(preds144, actuals144);
|
|
531
|
+
return new Map<string, any>([
|
|
532
|
+
["mae", evalResult.mae], ["rmse", evalResult.rmse], ["mape", evalResult.mape],
|
|
533
|
+
]);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// (predict-trend [1 2 3 4 5]) → "up"/"down"/"flat"/"volatile"
|
|
537
|
+
if (op === "predict-trend") {
|
|
538
|
+
const data144tr = Array.isArray(args[0]) ? args[0].map(Number) : [];
|
|
539
|
+
return globalPredictor.detectTrend(data144tr);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
// === Phase 148: CURIOSITY ===
|
|
548
|
+
export function evalCuriosity(op: string, args: any[], callFn?: (fn: any, a: any[]) => any): any | null {
|
|
549
|
+
// (curiosity-score "주제" ["알려진것1" "알려진것2"]) → 0~1 호기심 점수
|
|
550
|
+
if (op === "curiosity-score") {
|
|
551
|
+
const topic = String(args[0] ?? "");
|
|
552
|
+
const knownFacts: string[] = Array.isArray(args[1])
|
|
553
|
+
? args[1].map((f: any) => String(f))
|
|
554
|
+
: [];
|
|
555
|
+
return globalCuriosity.computeCuriosity(topic, knownFacts);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// (curiosity-next) → 다음 탐색 주제 or null
|
|
559
|
+
if (op === "curiosity-next") {
|
|
560
|
+
return globalCuriosity.selectNextTopic();
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// (curiosity-explore "주제" $explorer-fn) → ExplorationResult as Map
|
|
564
|
+
if (op === "curiosity-explore") {
|
|
565
|
+
const topic = String(args[0] ?? "");
|
|
566
|
+
const fn = args[1];
|
|
567
|
+
const explorerFunc = (t: string) => {
|
|
568
|
+
const result = callFn ? callFn(fn, [t]) : (typeof fn === "function" ? fn(t) : null);
|
|
569
|
+
if (result instanceof Map) {
|
|
570
|
+
const facts = Array.isArray(result.get("facts")) ? result.get("facts").map(String) : [];
|
|
571
|
+
const questions = Array.isArray(result.get("questions")) ? result.get("questions").map(String) : [];
|
|
572
|
+
return { facts, questions };
|
|
573
|
+
}
|
|
574
|
+
return { facts: [], questions: [] };
|
|
575
|
+
};
|
|
576
|
+
const res: ExplorationResult = globalCuriosity.explore(topic, explorerFunc);
|
|
577
|
+
return new Map<string, any>([
|
|
578
|
+
["topic", res.topic],
|
|
579
|
+
["discovered", res.discovered],
|
|
580
|
+
["newQuestions", res.newQuestions],
|
|
581
|
+
["informationGain", res.informationGain],
|
|
582
|
+
["surpriseLevel", res.surpriseLevel],
|
|
583
|
+
["relatedTopics", res.relatedTopics],
|
|
584
|
+
]);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// (curiosity-gaps ["알려진것들"] ["전체목록"]) → KnowledgeGap[] as Map[]
|
|
588
|
+
if (op === "curiosity-gaps") {
|
|
589
|
+
const known: string[] = Array.isArray(args[0]) ? args[0].map((s: any) => String(s)) : [];
|
|
590
|
+
const all: string[] = Array.isArray(args[1]) ? args[1].map((s: any) => String(s)) : [];
|
|
591
|
+
const gaps: KnowledgeGap[] = globalCuriosity.identifyGaps(known, all);
|
|
592
|
+
return gaps.map((g: KnowledgeGap) => new Map<string, any>([
|
|
593
|
+
["topic", g.topic],
|
|
594
|
+
["unknownAspects", g.unknownAspects],
|
|
595
|
+
["priority", g.priority],
|
|
596
|
+
["explorationCost", g.explorationCost],
|
|
597
|
+
["expectedGain", g.expectedGain],
|
|
598
|
+
]));
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// (curiosity-questions "주제" ["맥락1" "맥락2"]) → 질문 배열
|
|
602
|
+
if (op === "curiosity-questions") {
|
|
603
|
+
const topic = String(args[0] ?? "");
|
|
604
|
+
const context: string[] = Array.isArray(args[1]) ? args[1].map((s: any) => String(s)) : [];
|
|
605
|
+
return globalCuriosity.generateQuestions(topic, context);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// (curiosity-prioritize ["주제1" "주제2" "주제3"]) → 우선순위 정렬된 배열
|
|
609
|
+
if (op === "curiosity-prioritize") {
|
|
610
|
+
const topics: string[] = Array.isArray(args[0]) ? args[0].map((s: any) => String(s)) : [];
|
|
611
|
+
return globalCuriosity.prioritize(topics);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// (curiosity-analyze) → 탐색 이력 분석 Map
|
|
615
|
+
if (op === "curiosity-analyze") {
|
|
616
|
+
const analysis = globalCuriosity.analyzeExplorationHistory();
|
|
617
|
+
return new Map<string, any>([
|
|
618
|
+
["totalExplored", analysis.totalExplored],
|
|
619
|
+
["avgInfoGain", analysis.avgInfoGain],
|
|
620
|
+
["mostSurprising", analysis.mostSurprising],
|
|
621
|
+
["recommendations", analysis.recommendations],
|
|
622
|
+
]);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// (curiosity-state) → CuriosityState as Map
|
|
626
|
+
if (op === "curiosity-state") {
|
|
627
|
+
const st: CuriosityState = globalCuriosity.getState();
|
|
628
|
+
return new Map<string, any>([
|
|
629
|
+
["explored", Array.from(st.explored)],
|
|
630
|
+
["frontier", st.frontier],
|
|
631
|
+
["knowledgeGaps", st.knowledgeGaps.map((g: KnowledgeGap) => new Map<string, any>([
|
|
632
|
+
["topic", g.topic],
|
|
633
|
+
["unknownAspects", g.unknownAspects],
|
|
634
|
+
["priority", g.priority],
|
|
635
|
+
["explorationCost", g.explorationCost],
|
|
636
|
+
["expectedGain", g.expectedGain],
|
|
637
|
+
]))],
|
|
638
|
+
["curiosityScore", st.curiosityScore],
|
|
639
|
+
["explorationHistory", st.explorationHistory.map(h => new Map<string, any>([
|
|
640
|
+
["topic", h.topic],
|
|
641
|
+
["gain", h.gain],
|
|
642
|
+
["timestamp", h.timestamp.toISOString()],
|
|
643
|
+
]))],
|
|
644
|
+
]);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// === Phase 149: WISDOM ===
|
|
648
|
+
// (wisdom-add-exp :situation "..." :action "..." :outcome "..." :lesson "..." :success true :importance 0.8 :domain "engineering")
|
|
649
|
+
if (op === "wisdom-add-exp") {
|
|
650
|
+
const kwargs: Record<string, any> = {};
|
|
651
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
652
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
653
|
+
kwargs[key] = args[i + 1];
|
|
654
|
+
}
|
|
655
|
+
const exp = globalWisdom.addExperience({
|
|
656
|
+
situation: String(kwargs["situation"] ?? ""),
|
|
657
|
+
action: String(kwargs["action"] ?? ""),
|
|
658
|
+
outcome: String(kwargs["outcome"] ?? ""),
|
|
659
|
+
lesson: String(kwargs["lesson"] ?? ""),
|
|
660
|
+
success: kwargs["success"] === true || kwargs["success"] === "true",
|
|
661
|
+
importance: typeof kwargs["importance"] === "number" ? kwargs["importance"] : 0.5,
|
|
662
|
+
domain: String(kwargs["domain"] ?? "general"),
|
|
663
|
+
});
|
|
664
|
+
return new Map<string, any>([
|
|
665
|
+
["id", exp.id],
|
|
666
|
+
["situation", exp.situation],
|
|
667
|
+
["action", exp.action],
|
|
668
|
+
["outcome", exp.outcome],
|
|
669
|
+
["lesson", exp.lesson],
|
|
670
|
+
["success", exp.success],
|
|
671
|
+
["importance", exp.importance],
|
|
672
|
+
["domain", exp.domain],
|
|
673
|
+
["timestamp", exp.timestamp.toISOString()],
|
|
674
|
+
]);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// (wisdom-judge "현재 상황 설명")
|
|
678
|
+
if (op === "wisdom-judge") {
|
|
679
|
+
const situation = String(args[0] ?? "");
|
|
680
|
+
const judgment = globalWisdom.judge(situation);
|
|
681
|
+
return new Map<string, any>([
|
|
682
|
+
["situation", judgment.situation],
|
|
683
|
+
["recommendation", judgment.recommendation],
|
|
684
|
+
["reasoning", judgment.reasoning],
|
|
685
|
+
["relevantExperiences", judgment.relevantExperiences.map(e => new Map<string, any>([
|
|
686
|
+
["id", e.id], ["situation", e.situation], ["lesson", e.lesson],
|
|
687
|
+
["success", e.success], ["importance", e.importance], ["domain", e.domain],
|
|
688
|
+
]))],
|
|
689
|
+
["applicableHeuristics", judgment.applicableHeuristics.map(h => new Map<string, any>([
|
|
690
|
+
["id", h.id], ["rule", h.rule], ["confidence", h.confidence],
|
|
691
|
+
["successCount", h.successCount], ["totalCount", h.totalCount], ["domain", h.domain],
|
|
692
|
+
]))],
|
|
693
|
+
["confidence", judgment.confidence],
|
|
694
|
+
["caveats", judgment.caveats],
|
|
695
|
+
["alternatives", judgment.alternatives],
|
|
696
|
+
]);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// (wisdom-heuristics)
|
|
700
|
+
if (op === "wisdom-heuristics") {
|
|
701
|
+
return globalWisdom.getHeuristics().map(h => new Map<string, any>([
|
|
702
|
+
["id", h.id],
|
|
703
|
+
["rule", h.rule],
|
|
704
|
+
["confidence", h.confidence],
|
|
705
|
+
["successCount", h.successCount],
|
|
706
|
+
["totalCount", h.totalCount],
|
|
707
|
+
["domain", h.domain],
|
|
708
|
+
["derivedFrom", h.derivedFrom],
|
|
709
|
+
]));
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// (wisdom-extract)
|
|
713
|
+
if (op === "wisdom-extract") {
|
|
714
|
+
const heuristics = globalWisdom.extractHeuristics();
|
|
715
|
+
return heuristics.map(h => new Map<string, any>([
|
|
716
|
+
["id", h.id],
|
|
717
|
+
["rule", h.rule],
|
|
718
|
+
["confidence", h.confidence],
|
|
719
|
+
["successCount", h.successCount],
|
|
720
|
+
["totalCount", h.totalCount],
|
|
721
|
+
["domain", h.domain],
|
|
722
|
+
["derivedFrom", h.derivedFrom],
|
|
723
|
+
]));
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// (wisdom-relevant "상황")
|
|
727
|
+
if (op === "wisdom-relevant") {
|
|
728
|
+
const situation = String(args[0] ?? "");
|
|
729
|
+
const limit = typeof args[1] === "number" ? args[1] : 5;
|
|
730
|
+
return globalWisdom.findRelevantExperiences(situation, limit).map(e => new Map<string, any>([
|
|
731
|
+
["id", e.id],
|
|
732
|
+
["situation", e.situation],
|
|
733
|
+
["action", e.action],
|
|
734
|
+
["outcome", e.outcome],
|
|
735
|
+
["lesson", e.lesson],
|
|
736
|
+
["success", e.success],
|
|
737
|
+
["importance", e.importance],
|
|
738
|
+
["domain", e.domain],
|
|
739
|
+
]));
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// (wisdom-lessons :domain "engineering")
|
|
743
|
+
if (op === "wisdom-lessons") {
|
|
744
|
+
let domain: string | undefined;
|
|
745
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
746
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
747
|
+
if (key === "domain") domain = String(args[i + 1]);
|
|
748
|
+
}
|
|
749
|
+
return globalWisdom.getLessons(domain);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// (wisdom-score)
|
|
753
|
+
if (op === "wisdom-score") {
|
|
754
|
+
return globalWisdom.wisdomScore();
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// (wisdom-domain "engineering")
|
|
758
|
+
if (op === "wisdom-domain") {
|
|
759
|
+
const domain = String(args[0] ?? "general");
|
|
760
|
+
const summary = globalWisdom.summarizeDomain(domain);
|
|
761
|
+
return new Map<string, any>([
|
|
762
|
+
["topLessons", summary.topLessons],
|
|
763
|
+
["bestHeuristics", summary.bestHeuristics.map(h => new Map<string, any>([
|
|
764
|
+
["id", h.id], ["rule", h.rule], ["confidence", h.confidence],
|
|
765
|
+
["successCount", h.successCount], ["totalCount", h.totalCount],
|
|
766
|
+
]))],
|
|
767
|
+
["successRate", summary.successRate],
|
|
768
|
+
]);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// (wisdom-valid? $experience)
|
|
772
|
+
if (op === "wisdom-valid?") {
|
|
773
|
+
const expMap = args[0];
|
|
774
|
+
if (!(expMap instanceof Map)) return false;
|
|
775
|
+
const exp: Experience = {
|
|
776
|
+
id: String(expMap.get("id") ?? ""),
|
|
777
|
+
situation: String(expMap.get("situation") ?? ""),
|
|
778
|
+
action: String(expMap.get("action") ?? ""),
|
|
779
|
+
outcome: String(expMap.get("outcome") ?? ""),
|
|
780
|
+
lesson: String(expMap.get("lesson") ?? ""),
|
|
781
|
+
success: expMap.get("success") === true,
|
|
782
|
+
importance: Number(expMap.get("importance") ?? 0.5),
|
|
783
|
+
timestamp: new Date(String(expMap.get("timestamp") ?? new Date().toISOString())),
|
|
784
|
+
domain: String(expMap.get("domain") ?? "general"),
|
|
785
|
+
};
|
|
786
|
+
return globalWisdom.isStillValid(exp);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
// (wisdom-similar "상황")
|
|
790
|
+
if (op === "wisdom-similar") {
|
|
791
|
+
const situation = String(args[0] ?? "");
|
|
792
|
+
return globalWisdom.findSimilarCases(situation).map(e => new Map<string, any>([
|
|
793
|
+
["id", e.id],
|
|
794
|
+
["situation", e.situation],
|
|
795
|
+
["action", e.action],
|
|
796
|
+
["outcome", e.outcome],
|
|
797
|
+
["lesson", e.lesson],
|
|
798
|
+
["success", e.success],
|
|
799
|
+
["importance", e.importance],
|
|
800
|
+
["domain", e.domain],
|
|
801
|
+
]));
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// === Phase 147: ETHICS-CHECK ===
|
|
808
|
+
export function evalEthicsCheck(interp: Interpreter, op: string, args: any[]): any | null {
|
|
809
|
+
const callFnVal = (fn: any, a: any[]) => (interp as any).callFunctionValue(fn, a);
|
|
810
|
+
|
|
811
|
+
// (ethics-check "내용" {:context "의료 AI"}) → EthicsCheckResult Map
|
|
812
|
+
if (op === "ethics-check") {
|
|
813
|
+
const subject = String(args[0] ?? "");
|
|
814
|
+
const ctx: Record<string, unknown> = {};
|
|
815
|
+
if (args[1] instanceof Map) {
|
|
816
|
+
for (const [k, v] of (args[1] as Map<string, unknown>).entries()) {
|
|
817
|
+
ctx[String(k)] = v;
|
|
818
|
+
}
|
|
819
|
+
} else if (args[1] && typeof args[1] === 'object') {
|
|
820
|
+
Object.assign(ctx, args[1]);
|
|
821
|
+
}
|
|
822
|
+
const result = globalEthics.check(subject, ctx);
|
|
823
|
+
const fwMap = new Map<string, any>();
|
|
824
|
+
for (const [fw, data] of Object.entries(result.frameworks)) {
|
|
825
|
+
fwMap.set(fw, new Map<string, any>([["passed", data.passed], ["score", data.score]]));
|
|
826
|
+
}
|
|
827
|
+
return new Map<string, any>([
|
|
828
|
+
["subject", result.subject],
|
|
829
|
+
["passed", result.passed],
|
|
830
|
+
["violations", result.violations.map((v: EthicsViolation) => new Map<string, any>([
|
|
831
|
+
["principle", v.principle], ["severity", v.severity],
|
|
832
|
+
["description", v.description], ["suggestion", v.suggestion],
|
|
833
|
+
["framework", v.framework],
|
|
834
|
+
]))],
|
|
835
|
+
["score", result.score],
|
|
836
|
+
["frameworks", fwMap],
|
|
837
|
+
["recommendation", result.recommendation],
|
|
838
|
+
["requiresHumanReview", result.requiresHumanReview],
|
|
839
|
+
]);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// (ethics-check-framework "내용" "utilitarian") → {passed, score, violations}
|
|
843
|
+
if (op === "ethics-check-framework") {
|
|
844
|
+
const subject = String(args[0] ?? "");
|
|
845
|
+
const framework = String(args[1] ?? "utilitarian") as EthicsFramework;
|
|
846
|
+
const result = globalEthics.checkByFramework(subject, framework);
|
|
847
|
+
return new Map<string, any>([
|
|
848
|
+
["passed", result.passed],
|
|
849
|
+
["score", result.score],
|
|
850
|
+
["violations", result.violations.map((v: EthicsViolation) => new Map<string, any>([
|
|
851
|
+
["principle", v.principle], ["severity", v.severity],
|
|
852
|
+
["description", v.description], ["suggestion", v.suggestion],
|
|
853
|
+
["framework", v.framework],
|
|
854
|
+
]))],
|
|
855
|
+
]);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// (ethics-is-ethical "내용") → boolean
|
|
859
|
+
if (op === "ethics-is-ethical") {
|
|
860
|
+
const subject = String(args[0] ?? "");
|
|
861
|
+
const ctx: Record<string, unknown> = {};
|
|
862
|
+
if (args[1] instanceof Map) {
|
|
863
|
+
for (const [k, v] of (args[1] as Map<string, unknown>).entries()) {
|
|
864
|
+
ctx[String(k)] = v;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return globalEthics.isEthical(subject, ctx);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// (ethics-add-principle :id "p1" :name "해악금지" :framework "deontological")
|
|
871
|
+
if (op === "ethics-add-principle") {
|
|
872
|
+
const kw: Record<string, any> = {};
|
|
873
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
874
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
875
|
+
kw[key] = args[i + 1];
|
|
876
|
+
}
|
|
877
|
+
const principle: EthicsPrinciple = {
|
|
878
|
+
id: String(kw["id"] ?? "custom-principle"),
|
|
879
|
+
name: String(kw["name"] ?? "커스텀 원칙"),
|
|
880
|
+
description: String(kw["description"] ?? kw["desc"] ?? ""),
|
|
881
|
+
framework: (String(kw["framework"] ?? "virtue")) as EthicsFramework,
|
|
882
|
+
check: typeof kw["check-fn"] === "function"
|
|
883
|
+
? (subject: string, ctx: Record<string, unknown>) => {
|
|
884
|
+
const r = callFnVal(kw["check-fn"], [subject, ctx]);
|
|
885
|
+
if (r instanceof Map) {
|
|
886
|
+
return { passed: Boolean(r.get("passed")), reason: String(r.get("reason") ?? "") };
|
|
887
|
+
}
|
|
888
|
+
return { passed: Boolean(r), reason: "" };
|
|
889
|
+
}
|
|
890
|
+
: (_subject: string, _ctx: Record<string, unknown>) => ({ passed: true, reason: "커스텀 원칙 통과" }),
|
|
891
|
+
};
|
|
892
|
+
globalEthics.addPrinciple(principle);
|
|
893
|
+
return new Map<string, any>([
|
|
894
|
+
["id", principle.id], ["name", principle.name],
|
|
895
|
+
["framework", principle.framework], ["description", principle.description],
|
|
896
|
+
]);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// (ethics-suggest "내용" $violations) → 윤리적 대안 문자열
|
|
900
|
+
if (op === "ethics-suggest") {
|
|
901
|
+
const subject = String(args[0] ?? "");
|
|
902
|
+
const rawViolations = args[1];
|
|
903
|
+
const violations: EthicsViolation[] = [];
|
|
904
|
+
if (Array.isArray(rawViolations)) {
|
|
905
|
+
for (const rv of rawViolations) {
|
|
906
|
+
if (rv instanceof Map) {
|
|
907
|
+
violations.push({
|
|
908
|
+
principle: String(rv.get("principle") ?? ""),
|
|
909
|
+
severity: (rv.get("severity") ?? "low") as EthicsViolation["severity"],
|
|
910
|
+
description: String(rv.get("description") ?? ""),
|
|
911
|
+
suggestion: String(rv.get("suggestion") ?? ""),
|
|
912
|
+
framework: (rv.get("framework") ?? "virtue") as EthicsFramework,
|
|
913
|
+
});
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
return globalEthics.suggestEthicalAlternative(subject, violations);
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
// (ethics-risk $result) → "none"/"low"/"medium"/"high"/"critical"
|
|
921
|
+
if (op === "ethics-risk") {
|
|
922
|
+
const rawResult = args[0];
|
|
923
|
+
if (rawResult instanceof Map) {
|
|
924
|
+
const violations: EthicsViolation[] = [];
|
|
925
|
+
const rawViolations = rawResult.get("violations") ?? [];
|
|
926
|
+
if (Array.isArray(rawViolations)) {
|
|
927
|
+
for (const rv of rawViolations) {
|
|
928
|
+
if (rv instanceof Map) {
|
|
929
|
+
violations.push({
|
|
930
|
+
principle: String(rv.get("principle") ?? ""),
|
|
931
|
+
severity: (rv.get("severity") ?? "low") as EthicsViolation["severity"],
|
|
932
|
+
description: String(rv.get("description") ?? ""),
|
|
933
|
+
suggestion: String(rv.get("suggestion") ?? ""),
|
|
934
|
+
framework: (rv.get("framework") ?? "virtue") as EthicsFramework,
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
const result: EthicsCheckResult = {
|
|
940
|
+
subject: String(rawResult.get("subject") ?? ""),
|
|
941
|
+
passed: Boolean(rawResult.get("passed")),
|
|
942
|
+
violations,
|
|
943
|
+
score: Number(rawResult.get("score") ?? 1),
|
|
944
|
+
frameworks: {} as EthicsCheckResult["frameworks"],
|
|
945
|
+
recommendation: String(rawResult.get("recommendation") ?? ""),
|
|
946
|
+
requiresHumanReview: Boolean(rawResult.get("requiresHumanReview")),
|
|
947
|
+
};
|
|
948
|
+
return globalEthics.riskLevel(result);
|
|
949
|
+
}
|
|
950
|
+
return "none";
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
// (ethics-violations $result) → EthicsViolation[]
|
|
954
|
+
if (op === "ethics-violations") {
|
|
955
|
+
const rawResult = args[0];
|
|
956
|
+
if (rawResult instanceof Map) {
|
|
957
|
+
return rawResult.get("violations") ?? [];
|
|
958
|
+
}
|
|
959
|
+
return [];
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// (ethics-score $result) → 0~1 점수
|
|
963
|
+
if (op === "ethics-score") {
|
|
964
|
+
const rawResult = args[0];
|
|
965
|
+
if (rawResult instanceof Map) {
|
|
966
|
+
return Number(rawResult.get("score") ?? 1);
|
|
967
|
+
}
|
|
968
|
+
return 1;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
return null;
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// === Phase 145: EXPLAIN (appended) ===
|
|
975
|
+
// These functions are registered inside evalBuiltin via the module-level append pattern.
|
|
976
|
+
// See explain.ts for the Explainer class.
|
|
977
|
+
|
|
978
|
+
// NOTE: Phase 145 EXPLAIN functions are added as patches below.
|
|
979
|
+
// The evalBuiltin function above handles them via the explain-* op prefix.
|
|
980
|
+
// Due to the multi-function file structure, we use a separate registration approach.
|
|
981
|
+
|
|
982
|
+
// === Phase 143: COUNTERFACTUAL 빌트인 헬퍼 ===
|
|
983
|
+
export function evalCounterfactual(op: string, args: any[], callFn: (fn: any, a: any[]) => any): any {
|
|
984
|
+
// (cf-scenario :id "s1" :name "비오는날" :vars {:rain true :speed 60} :outcome "accident")
|
|
985
|
+
if (op === "cf-scenario") {
|
|
986
|
+
const kw: Record<string, any> = {};
|
|
987
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
988
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
989
|
+
kw[key] = args[i + 1];
|
|
990
|
+
}
|
|
991
|
+
const id = String(kw["id"] ?? `s-${Date.now()}`);
|
|
992
|
+
const name = String(kw["name"] ?? id);
|
|
993
|
+
let variables: Record<string, unknown> = {};
|
|
994
|
+
if (kw["vars"] instanceof Map) {
|
|
995
|
+
for (const [k, v] of kw["vars"]) variables[String(k).replace(/^:/, "")] = v;
|
|
996
|
+
} else if (kw["vars"] && typeof kw["vars"] === "object") {
|
|
997
|
+
variables = kw["vars"] as Record<string, unknown>;
|
|
998
|
+
}
|
|
999
|
+
const outcome = kw["outcome"] ?? null;
|
|
1000
|
+
const scenario: Scenario = { id, name, variables, outcome };
|
|
1001
|
+
globalCounterfactual.registerScenario(scenario);
|
|
1002
|
+
return new Map<string, any>([
|
|
1003
|
+
["id", id], ["name", name],
|
|
1004
|
+
["variables", new Map(Object.entries(variables))],
|
|
1005
|
+
["outcome", outcome],
|
|
1006
|
+
]);
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
// (cf-what-if $vars $change $outcome-fn)
|
|
1010
|
+
if (op === "cf-what-if") {
|
|
1011
|
+
let variables: Record<string, unknown> = {};
|
|
1012
|
+
let change: Record<string, unknown> = {};
|
|
1013
|
+
if (args[0] instanceof Map) {
|
|
1014
|
+
for (const [k, v] of (args[0] as Map<any,any>)) variables[String(k).replace(/^:/, "")] = v;
|
|
1015
|
+
}
|
|
1016
|
+
if (args[1] instanceof Map) {
|
|
1017
|
+
for (const [k, v] of (args[1] as Map<any,any>)) change[String(k).replace(/^:/, "")] = v;
|
|
1018
|
+
}
|
|
1019
|
+
const fn = args[2];
|
|
1020
|
+
const outcomeFunc = (vars: Record<string, unknown>) => callFn(fn, [new Map(Object.entries(vars))]);
|
|
1021
|
+
const cf = globalCounterfactual.whatIf(variables, change, outcomeFunc);
|
|
1022
|
+
return new Map<string, any>([
|
|
1023
|
+
["id", cf.id],
|
|
1024
|
+
["intervention", new Map(Object.entries(cf.intervention))],
|
|
1025
|
+
["counterfactualOutcome", cf.counterfactualOutcome],
|
|
1026
|
+
["delta", new Map(Object.entries(cf.delta))],
|
|
1027
|
+
["probability", cf.probability],
|
|
1028
|
+
["explanation", cf.explanation],
|
|
1029
|
+
]);
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
// (cf-analyze "s1" $interventions $outcome-fn)
|
|
1033
|
+
if (op === "cf-analyze") {
|
|
1034
|
+
const scenarioId = String(args[0] ?? "");
|
|
1035
|
+
const interventionsList: Array<Record<string, unknown>> = [];
|
|
1036
|
+
if (Array.isArray(args[1])) {
|
|
1037
|
+
for (const iv of args[1]) {
|
|
1038
|
+
const obj: Record<string, unknown> = {};
|
|
1039
|
+
if (iv instanceof Map) {
|
|
1040
|
+
for (const [k, v] of (iv as Map<any,any>)) obj[String(k).replace(/^:/, "")] = v;
|
|
1041
|
+
}
|
|
1042
|
+
interventionsList.push(obj);
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
const fn = args[2];
|
|
1046
|
+
const outcomeFunc = (vars: Record<string, unknown>) => callFn(fn, [new Map(Object.entries(vars))]);
|
|
1047
|
+
const analysis = globalCounterfactual.analyze(scenarioId, interventionsList, outcomeFunc);
|
|
1048
|
+
return new Map<string, any>([
|
|
1049
|
+
["original", new Map<string, any>([
|
|
1050
|
+
["id", analysis.original.id], ["name", analysis.original.name], ["outcome", analysis.original.outcome],
|
|
1051
|
+
])],
|
|
1052
|
+
["counterfactuals", analysis.counterfactuals.map(cf => new Map<string, any>([
|
|
1053
|
+
["id", cf.id], ["probability", cf.probability], ["counterfactualOutcome", cf.counterfactualOutcome],
|
|
1054
|
+
["explanation", cf.explanation],
|
|
1055
|
+
]))],
|
|
1056
|
+
["mostLikelyAlternative", new Map<string, any>([
|
|
1057
|
+
["id", analysis.mostLikelyAlternative.id],
|
|
1058
|
+
["probability", analysis.mostLikelyAlternative.probability],
|
|
1059
|
+
["counterfactualOutcome", analysis.mostLikelyAlternative.counterfactualOutcome],
|
|
1060
|
+
["explanation", analysis.mostLikelyAlternative.explanation],
|
|
1061
|
+
])],
|
|
1062
|
+
["keyFactors", analysis.keyFactors],
|
|
1063
|
+
["sensitivity", new Map(Object.entries(analysis.sensitivity))],
|
|
1064
|
+
]);
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// (cf-minimal "s1" "no-accident" $outcome-fn)
|
|
1068
|
+
if (op === "cf-minimal") {
|
|
1069
|
+
const scenarioId = String(args[0] ?? "");
|
|
1070
|
+
const targetOutcome = args[1];
|
|
1071
|
+
const fn = args[2];
|
|
1072
|
+
const outcomeFunc = (vars: Record<string, unknown>) => callFn(fn, [new Map(Object.entries(vars))]);
|
|
1073
|
+
const minimal = globalCounterfactual.findMinimalIntervention(scenarioId, targetOutcome, outcomeFunc);
|
|
1074
|
+
if (minimal === null) return null;
|
|
1075
|
+
return new Map(Object.entries(minimal));
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// (cf-sensitivity $vars $fn)
|
|
1079
|
+
if (op === "cf-sensitivity") {
|
|
1080
|
+
let variables: Record<string, unknown> = {};
|
|
1081
|
+
const rawVars = args[0];
|
|
1082
|
+
if (rawVars instanceof Map) {
|
|
1083
|
+
for (const [k, v] of (rawVars as Map<any,any>)) variables[String(k).replace(/^:/, "")] = v;
|
|
1084
|
+
} else if (rawVars && typeof rawVars === "object" && !Array.isArray(rawVars)) {
|
|
1085
|
+
// FL {: } map literal은 plain object로 평가됨
|
|
1086
|
+
for (const [k, v] of Object.entries(rawVars)) variables[String(k).replace(/^:/, "")] = v;
|
|
1087
|
+
}
|
|
1088
|
+
const fn = args[1];
|
|
1089
|
+
// FL imm-get은 plain object m[k]를 사용하므로 plain object로 전달
|
|
1090
|
+
const outcomeFunc = (vars: Record<string, unknown>) => {
|
|
1091
|
+
try { return Number(callFn(fn, [vars as any])); } catch { return 0; }
|
|
1092
|
+
};
|
|
1093
|
+
const sens = globalCounterfactual.sensitivityAnalysis(variables, outcomeFunc);
|
|
1094
|
+
return new Map(Object.entries(sens));
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// (cf-key-factors $analysis)
|
|
1098
|
+
if (op === "cf-key-factors") {
|
|
1099
|
+
const analysis = args[0];
|
|
1100
|
+
if (analysis instanceof Map) {
|
|
1101
|
+
const factors = (analysis as Map<any,any>).get("keyFactors");
|
|
1102
|
+
if (Array.isArray(factors)) return factors;
|
|
1103
|
+
}
|
|
1104
|
+
return [];
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// (cf-best-alt $analysis)
|
|
1108
|
+
if (op === "cf-best-alt") {
|
|
1109
|
+
const analysis = args[0];
|
|
1110
|
+
if (analysis instanceof Map) {
|
|
1111
|
+
return (analysis as Map<any,any>).get("mostLikelyAlternative") ?? null;
|
|
1112
|
+
}
|
|
1113
|
+
return null;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// (cf-explain $counterfactual)
|
|
1117
|
+
if (op === "cf-explain") {
|
|
1118
|
+
const cf = args[0];
|
|
1119
|
+
if (cf instanceof Map) {
|
|
1120
|
+
return (cf as Map<any,any>).get("explanation") ?? "";
|
|
1121
|
+
}
|
|
1122
|
+
return "";
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
|
|
1126
|
+
// === Phase 145: EXPLAIN ===
|
|
1127
|
+
|
|
1128
|
+
// (explain-decision $decision {:accuracy 0.9 :speed 0.7} "context")
|
|
1129
|
+
if (op === "explain-decision") {
|
|
1130
|
+
const decision = args[0];
|
|
1131
|
+
const rawFactors = args[1];
|
|
1132
|
+
const context = args[2] !== undefined ? String(args[2]) : undefined;
|
|
1133
|
+
const factors: Record<string, number> = {};
|
|
1134
|
+
if (rawFactors instanceof Map) {
|
|
1135
|
+
for (const [k, v] of rawFactors.entries()) factors[String(k).replace(/^:/, "")] = Number(v);
|
|
1136
|
+
} else if (rawFactors && typeof rawFactors === "object") {
|
|
1137
|
+
for (const [k, v] of Object.entries(rawFactors)) factors[String(k).replace(/^:/, "")] = Number(v);
|
|
1138
|
+
}
|
|
1139
|
+
const explanation = globalExplainer.explain(decision, factors, context);
|
|
1140
|
+
return new Map<string, any>([
|
|
1141
|
+
["decision", explanation.decision],
|
|
1142
|
+
["reasoning", explanation.reasoning],
|
|
1143
|
+
["features", explanation.features.map((f: FeatureImportance) => new Map<string, any>([
|
|
1144
|
+
["feature", f.feature], ["importance", f.importance],
|
|
1145
|
+
["direction", f.direction], ["description", f.description],
|
|
1146
|
+
]))],
|
|
1147
|
+
["confidence", explanation.confidence],
|
|
1148
|
+
["alternatives", explanation.alternatives.map((a: any) => new Map<string, any>([
|
|
1149
|
+
["decision", a.decision], ["reason", a.reason], ["probability", a.probability],
|
|
1150
|
+
]))],
|
|
1151
|
+
["summary", explanation.summary],
|
|
1152
|
+
["audience", explanation.audience],
|
|
1153
|
+
]);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// (explain-features {:x 1 :y 2} {:out 0.8})
|
|
1157
|
+
if (op === "explain-features") {
|
|
1158
|
+
const toRecord145 = (v: any): Record<string, number> => {
|
|
1159
|
+
const result: Record<string, number> = {};
|
|
1160
|
+
if (v instanceof Map) {
|
|
1161
|
+
for (const [k, val] of v.entries()) result[String(k).replace(/^:/, "")] = Number(val);
|
|
1162
|
+
} else if (v && typeof v === "object") {
|
|
1163
|
+
for (const [k, val] of Object.entries(v)) result[String(k).replace(/^:/, "")] = Number(val);
|
|
1164
|
+
}
|
|
1165
|
+
return result;
|
|
1166
|
+
};
|
|
1167
|
+
const inputs145 = toRecord145(args[0]);
|
|
1168
|
+
const outputs145 = toRecord145(args[1]);
|
|
1169
|
+
const baseline145 = args[2] !== undefined ? toRecord145(args[2]) : undefined;
|
|
1170
|
+
const features145 = globalExplainer.featureImportance(inputs145, outputs145, baseline145);
|
|
1171
|
+
return features145.map((f: FeatureImportance) => new Map<string, any>([
|
|
1172
|
+
["feature", f.feature], ["importance", f.importance],
|
|
1173
|
+
["direction", f.direction], ["description", f.description],
|
|
1174
|
+
]));
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// (explain-local {:age 25} "approved" $model)
|
|
1178
|
+
if (op === "explain-local") {
|
|
1179
|
+
const rawInput145 = args[0];
|
|
1180
|
+
const output145 = args[1];
|
|
1181
|
+
const modelFn145 = args[2];
|
|
1182
|
+
const input145: Record<string, unknown> = {};
|
|
1183
|
+
if (rawInput145 instanceof Map) {
|
|
1184
|
+
for (const [k, v] of rawInput145.entries()) input145[String(k).replace(/^:/, "")] = v;
|
|
1185
|
+
} else if (rawInput145 && typeof rawInput145 === "object") {
|
|
1186
|
+
for (const [k, v] of Object.entries(rawInput145)) input145[String(k).replace(/^:/, "")] = v;
|
|
1187
|
+
}
|
|
1188
|
+
const model145 = (inp: Record<string, unknown>): unknown => {
|
|
1189
|
+
if (modelFn145) {
|
|
1190
|
+
try { return callFn(modelFn145, [new Map(Object.entries(inp))]); }
|
|
1191
|
+
catch { return output145; }
|
|
1192
|
+
}
|
|
1193
|
+
return output145;
|
|
1194
|
+
};
|
|
1195
|
+
const local145 = globalExplainer.localExplain(input145, output145, model145);
|
|
1196
|
+
return new Map<string, any>([
|
|
1197
|
+
["input", new Map(Object.entries(local145.input))],
|
|
1198
|
+
["output", local145.output],
|
|
1199
|
+
["topFactors", local145.topFactors.map((f: FeatureImportance) => new Map<string, any>([
|
|
1200
|
+
["feature", f.feature], ["importance", f.importance],
|
|
1201
|
+
["direction", f.direction], ["description", f.description],
|
|
1202
|
+
]))],
|
|
1203
|
+
["counterfactual", local145.counterfactual],
|
|
1204
|
+
["confidence", local145.confidence],
|
|
1205
|
+
]);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// (explain-natural $explanation :audience "general")
|
|
1209
|
+
if (op === "explain-natural") {
|
|
1210
|
+
const rawExpl145 = args[0];
|
|
1211
|
+
let audience145: 'technical' | 'general' = 'technical';
|
|
1212
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
1213
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
1214
|
+
if (key === "audience") audience145 = String(args[i + 1]) as 'technical' | 'general';
|
|
1215
|
+
}
|
|
1216
|
+
if (!(rawExpl145 instanceof Map)) return "설명을 변환할 수 없습니다";
|
|
1217
|
+
const featuresRaw145 = rawExpl145.get("features") ?? [];
|
|
1218
|
+
const features145n: FeatureImportance[] = (Array.isArray(featuresRaw145) ? featuresRaw145 : []).map((f: any) => {
|
|
1219
|
+
if (f instanceof Map) {
|
|
1220
|
+
return {
|
|
1221
|
+
feature: String(f.get("feature") ?? ""),
|
|
1222
|
+
importance: Number(f.get("importance") ?? 0),
|
|
1223
|
+
direction: String(f.get("direction") ?? "positive") as 'positive' | 'negative',
|
|
1224
|
+
description: String(f.get("description") ?? ""),
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
return { feature: "", importance: 0, direction: "positive" as const, description: "" };
|
|
1228
|
+
});
|
|
1229
|
+
const altsRaw145 = rawExpl145.get("alternatives") ?? [];
|
|
1230
|
+
const alternatives145 = (Array.isArray(altsRaw145) ? altsRaw145 : []).map((a: any) => {
|
|
1231
|
+
if (a instanceof Map) return { decision: a.get("decision"), reason: String(a.get("reason") ?? ""), probability: Number(a.get("probability") ?? 0) };
|
|
1232
|
+
return { decision: null, reason: "", probability: 0 };
|
|
1233
|
+
});
|
|
1234
|
+
const explanation145n: DecisionExplanation = {
|
|
1235
|
+
decision: rawExpl145.get("decision"),
|
|
1236
|
+
reasoning: rawExpl145.get("reasoning") ?? [],
|
|
1237
|
+
features: features145n,
|
|
1238
|
+
confidence: Number(rawExpl145.get("confidence") ?? 0.5),
|
|
1239
|
+
alternatives: alternatives145,
|
|
1240
|
+
summary: String(rawExpl145.get("summary") ?? ""),
|
|
1241
|
+
audience: (rawExpl145.get("audience") ?? "technical") as 'technical' | 'general',
|
|
1242
|
+
};
|
|
1243
|
+
return globalExplainer.toNaturalLanguage(explanation145n, audience145);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
// (explain-contrast "approved" "denied" {:score 0.8})
|
|
1247
|
+
if (op === "explain-contrast") {
|
|
1248
|
+
const decision145c = args[0];
|
|
1249
|
+
const alternative145c = args[1];
|
|
1250
|
+
const rawFactors145c = args[2];
|
|
1251
|
+
const factors145c: Record<string, number> = {};
|
|
1252
|
+
if (rawFactors145c instanceof Map) {
|
|
1253
|
+
for (const [k, v] of rawFactors145c.entries()) factors145c[String(k).replace(/^:/, "")] = Number(v);
|
|
1254
|
+
} else if (rawFactors145c && typeof rawFactors145c === "object") {
|
|
1255
|
+
for (const [k, v] of Object.entries(rawFactors145c)) factors145c[String(k).replace(/^:/, "")] = Number(v);
|
|
1256
|
+
}
|
|
1257
|
+
return globalExplainer.contrastiveExplain(decision145c, alternative145c, factors145c);
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
// (explain-rules $examples)
|
|
1261
|
+
if (op === "explain-rules") {
|
|
1262
|
+
const rawExamples145 = args[0];
|
|
1263
|
+
const examples145: Array<{ input: Record<string, unknown>; output: unknown }> = [];
|
|
1264
|
+
const toRecord145r = (v: any): Record<string, unknown> => {
|
|
1265
|
+
const result: Record<string, unknown> = {};
|
|
1266
|
+
if (v instanceof Map) {
|
|
1267
|
+
for (const [k, val] of v.entries()) result[String(k).replace(/^:/, "")] = val;
|
|
1268
|
+
} else if (v && typeof v === "object") {
|
|
1269
|
+
Object.assign(result, v);
|
|
1270
|
+
}
|
|
1271
|
+
return result;
|
|
1272
|
+
};
|
|
1273
|
+
if (Array.isArray(rawExamples145)) {
|
|
1274
|
+
for (const ex of rawExamples145) {
|
|
1275
|
+
if (ex instanceof Map) {
|
|
1276
|
+
examples145.push({ input: toRecord145r(ex.get("input")), output: ex.get("output") });
|
|
1277
|
+
} else if (ex && typeof ex === "object") {
|
|
1278
|
+
examples145.push({ input: toRecord145r((ex as any).input), output: (ex as any).output });
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
const rules145 = globalExplainer.extractRules(examples145);
|
|
1283
|
+
return rules145.map((r: any) => new Map<string, any>([
|
|
1284
|
+
["condition", r.condition], ["outcome", r.outcome], ["support", r.support],
|
|
1285
|
+
]));
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
// (explain-top-factors $explanation :n 3)
|
|
1289
|
+
if (op === "explain-top-factors") {
|
|
1290
|
+
const rawExpl145tf = args[0];
|
|
1291
|
+
let n145 = 3;
|
|
1292
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
1293
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
1294
|
+
if (key === "n") n145 = Number(args[i + 1]);
|
|
1295
|
+
}
|
|
1296
|
+
let features145tf: any[] = [];
|
|
1297
|
+
if (rawExpl145tf instanceof Map) features145tf = rawExpl145tf.get("features") ?? [];
|
|
1298
|
+
if (!Array.isArray(features145tf)) features145tf = [];
|
|
1299
|
+
return features145tf.slice(0, n145);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// (explain-summary $explanation)
|
|
1303
|
+
if (op === "explain-summary") {
|
|
1304
|
+
const rawExpl145s = args[0];
|
|
1305
|
+
if (rawExpl145s instanceof Map) return String(rawExpl145s.get("summary") ?? "");
|
|
1306
|
+
return "";
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
return null;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// === Phase 149: WISDOM ===
|
|
1313
|
+
export function evalWisdom(op: string, args: any[]): any | null {
|
|
1314
|
+
|
|
1315
|
+
if (op === "wisdom-add-exp") {
|
|
1316
|
+
const kwargs: Record<string, any> = {};
|
|
1317
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
1318
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
1319
|
+
kwargs[key] = args[i + 1];
|
|
1320
|
+
}
|
|
1321
|
+
const exp = globalWisdom.addExperience({
|
|
1322
|
+
situation: String(kwargs["situation"] ?? ""),
|
|
1323
|
+
action: String(kwargs["action"] ?? ""),
|
|
1324
|
+
outcome: String(kwargs["outcome"] ?? ""),
|
|
1325
|
+
lesson: String(kwargs["lesson"] ?? ""),
|
|
1326
|
+
success: kwargs["success"] === true || kwargs["success"] === "true",
|
|
1327
|
+
importance: typeof kwargs["importance"] === "number" ? kwargs["importance"] : 0.5,
|
|
1328
|
+
domain: String(kwargs["domain"] ?? "general"),
|
|
1329
|
+
});
|
|
1330
|
+
return new Map<string, any>([
|
|
1331
|
+
["id", exp.id], ["situation", exp.situation], ["action", exp.action],
|
|
1332
|
+
["outcome", exp.outcome], ["lesson", exp.lesson], ["success", exp.success],
|
|
1333
|
+
["importance", exp.importance], ["domain", exp.domain],
|
|
1334
|
+
["timestamp", exp.timestamp.toISOString()],
|
|
1335
|
+
]);
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
if (op === "wisdom-judge") {
|
|
1339
|
+
const situation = String(args[0] ?? "");
|
|
1340
|
+
const judgment = globalWisdom.judge(situation);
|
|
1341
|
+
return new Map<string, any>([
|
|
1342
|
+
["situation", judgment.situation],
|
|
1343
|
+
["recommendation", judgment.recommendation],
|
|
1344
|
+
["reasoning", judgment.reasoning],
|
|
1345
|
+
["relevantExperiences", judgment.relevantExperiences.map((e: Experience) => new Map<string, any>([
|
|
1346
|
+
["id", e.id], ["situation", e.situation], ["lesson", e.lesson],
|
|
1347
|
+
["success", e.success], ["importance", e.importance], ["domain", e.domain],
|
|
1348
|
+
]))],
|
|
1349
|
+
["applicableHeuristics", judgment.applicableHeuristics.map((h: Heuristic) => new Map<string, any>([
|
|
1350
|
+
["id", h.id], ["rule", h.rule], ["confidence", h.confidence],
|
|
1351
|
+
["successCount", h.successCount], ["totalCount", h.totalCount], ["domain", h.domain],
|
|
1352
|
+
]))],
|
|
1353
|
+
["confidence", judgment.confidence],
|
|
1354
|
+
["caveats", judgment.caveats],
|
|
1355
|
+
["alternatives", judgment.alternatives],
|
|
1356
|
+
]);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
if (op === "wisdom-heuristics") {
|
|
1360
|
+
return globalWisdom.getHeuristics().map((h: Heuristic) => new Map<string, any>([
|
|
1361
|
+
["id", h.id], ["rule", h.rule], ["confidence", h.confidence],
|
|
1362
|
+
["successCount", h.successCount], ["totalCount", h.totalCount],
|
|
1363
|
+
["domain", h.domain], ["derivedFrom", h.derivedFrom],
|
|
1364
|
+
]));
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
if (op === "wisdom-extract") {
|
|
1368
|
+
const heuristics = globalWisdom.extractHeuristics();
|
|
1369
|
+
return heuristics.map((h: Heuristic) => new Map<string, any>([
|
|
1370
|
+
["id", h.id], ["rule", h.rule], ["confidence", h.confidence],
|
|
1371
|
+
["successCount", h.successCount], ["totalCount", h.totalCount],
|
|
1372
|
+
["domain", h.domain], ["derivedFrom", h.derivedFrom],
|
|
1373
|
+
]));
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
if (op === "wisdom-relevant") {
|
|
1377
|
+
const situation = String(args[0] ?? "");
|
|
1378
|
+
const limit = typeof args[1] === "number" ? args[1] : 5;
|
|
1379
|
+
return globalWisdom.findRelevantExperiences(situation, limit).map((e: Experience) => new Map<string, any>([
|
|
1380
|
+
["id", e.id], ["situation", e.situation], ["action", e.action],
|
|
1381
|
+
["outcome", e.outcome], ["lesson", e.lesson], ["success", e.success],
|
|
1382
|
+
["importance", e.importance], ["domain", e.domain],
|
|
1383
|
+
]));
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
if (op === "wisdom-lessons") {
|
|
1387
|
+
let domain: string | undefined;
|
|
1388
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
1389
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
1390
|
+
if (key === "domain") domain = String(args[i + 1]);
|
|
1391
|
+
}
|
|
1392
|
+
return globalWisdom.getLessons(domain);
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
if (op === "wisdom-score") {
|
|
1396
|
+
return globalWisdom.wisdomScore();
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
if (op === "wisdom-domain") {
|
|
1400
|
+
const domain = String(args[0] ?? "general");
|
|
1401
|
+
const summary = globalWisdom.summarizeDomain(domain);
|
|
1402
|
+
return new Map<string, any>([
|
|
1403
|
+
["topLessons", summary.topLessons],
|
|
1404
|
+
["bestHeuristics", summary.bestHeuristics.map((h: Heuristic) => new Map<string, any>([
|
|
1405
|
+
["id", h.id], ["rule", h.rule], ["confidence", h.confidence],
|
|
1406
|
+
["successCount", h.successCount], ["totalCount", h.totalCount],
|
|
1407
|
+
]))],
|
|
1408
|
+
["successRate", summary.successRate],
|
|
1409
|
+
]);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
if (op === "wisdom-valid?") {
|
|
1413
|
+
const expMap = args[0];
|
|
1414
|
+
if (!(expMap instanceof Map)) return false;
|
|
1415
|
+
const exp: Experience = {
|
|
1416
|
+
id: String(expMap.get("id") ?? ""),
|
|
1417
|
+
situation: String(expMap.get("situation") ?? ""),
|
|
1418
|
+
action: String(expMap.get("action") ?? ""),
|
|
1419
|
+
outcome: String(expMap.get("outcome") ?? ""),
|
|
1420
|
+
lesson: String(expMap.get("lesson") ?? ""),
|
|
1421
|
+
success: expMap.get("success") === true,
|
|
1422
|
+
importance: Number(expMap.get("importance") ?? 0.5),
|
|
1423
|
+
timestamp: new Date(String(expMap.get("timestamp") ?? new Date().toISOString())),
|
|
1424
|
+
domain: String(expMap.get("domain") ?? "general"),
|
|
1425
|
+
};
|
|
1426
|
+
return globalWisdom.isStillValid(exp);
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
if (op === "wisdom-similar") {
|
|
1430
|
+
const situation = String(args[0] ?? "");
|
|
1431
|
+
return globalWisdom.findSimilarCases(situation).map((e: Experience) => new Map<string, any>([
|
|
1432
|
+
["id", e.id], ["situation", e.situation], ["action", e.action],
|
|
1433
|
+
["outcome", e.outcome], ["lesson", e.lesson], ["success", e.success],
|
|
1434
|
+
["importance", e.importance], ["domain", e.domain],
|
|
1435
|
+
]));
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// === Phase 145: EXPLAIN ===
|
|
1442
|
+
export function evalExplain_PHASE145(op: string, args: any[], callFnVal?: (fn: any, a: any[]) => any): any | null {
|
|
1443
|
+
if (op === "explain-decision") {
|
|
1444
|
+
const decision = args[0];
|
|
1445
|
+
const rawFactors = args[1];
|
|
1446
|
+
const context = args[2] !== undefined ? String(args[2]) : undefined;
|
|
1447
|
+
const factors: Record<string, number> = {};
|
|
1448
|
+
if (rawFactors instanceof Map) {
|
|
1449
|
+
for (const [k, v] of rawFactors.entries()) factors[String(k).replace(/^:/, "")] = Number(v);
|
|
1450
|
+
} else if (rawFactors && typeof rawFactors === "object") {
|
|
1451
|
+
for (const [k, v] of Object.entries(rawFactors)) factors[String(k).replace(/^:/, "")] = Number(v);
|
|
1452
|
+
}
|
|
1453
|
+
const explanation = globalExplainer.explain(decision, factors, context);
|
|
1454
|
+
return new Map<string, any>([
|
|
1455
|
+
["decision", explanation.decision],
|
|
1456
|
+
["reasoning", explanation.reasoning],
|
|
1457
|
+
["features", explanation.features.map((f: FeatureImportance) => new Map<string, any>([
|
|
1458
|
+
["feature", f.feature], ["importance", f.importance],
|
|
1459
|
+
["direction", f.direction], ["description", f.description],
|
|
1460
|
+
]))],
|
|
1461
|
+
["confidence", explanation.confidence],
|
|
1462
|
+
["alternatives", explanation.alternatives.map((a: any) => new Map<string, any>([
|
|
1463
|
+
["decision", a.decision], ["reason", a.reason], ["probability", a.probability],
|
|
1464
|
+
]))],
|
|
1465
|
+
["summary", explanation.summary],
|
|
1466
|
+
["audience", explanation.audience],
|
|
1467
|
+
]);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
if (op === "explain-features") {
|
|
1471
|
+
const toRecord = (v: any): Record<string, number> => {
|
|
1472
|
+
const result: Record<string, number> = {};
|
|
1473
|
+
if (v instanceof Map) {
|
|
1474
|
+
for (const [k, val] of v.entries()) result[String(k).replace(/^:/, "")] = Number(val);
|
|
1475
|
+
} else if (v && typeof v === "object") {
|
|
1476
|
+
for (const [k, val] of Object.entries(v)) result[String(k).replace(/^:/, "")] = Number(val);
|
|
1477
|
+
}
|
|
1478
|
+
return result;
|
|
1479
|
+
};
|
|
1480
|
+
const features = globalExplainer.featureImportance(toRecord(args[0]), toRecord(args[1]), args[2] !== undefined ? toRecord(args[2]) : undefined);
|
|
1481
|
+
return features.map((f: FeatureImportance) => new Map<string, any>([
|
|
1482
|
+
["feature", f.feature], ["importance", f.importance],
|
|
1483
|
+
["direction", f.direction], ["description", f.description],
|
|
1484
|
+
]));
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
if (op === "explain-local") {
|
|
1488
|
+
const rawInput = args[0];
|
|
1489
|
+
const output = args[1];
|
|
1490
|
+
const modelFn = args[2];
|
|
1491
|
+
const input: Record<string, unknown> = {};
|
|
1492
|
+
if (rawInput instanceof Map) {
|
|
1493
|
+
for (const [k, v] of rawInput.entries()) input[String(k).replace(/^:/, "")] = v;
|
|
1494
|
+
} else if (rawInput && typeof rawInput === "object") {
|
|
1495
|
+
for (const [k, v] of Object.entries(rawInput)) input[String(k).replace(/^:/, "")] = v;
|
|
1496
|
+
}
|
|
1497
|
+
const model = (inp: Record<string, unknown>): unknown => {
|
|
1498
|
+
if (modelFn && callFnVal) {
|
|
1499
|
+
try { return callFnVal(modelFn, [new Map(Object.entries(inp))]); }
|
|
1500
|
+
catch { return output; }
|
|
1501
|
+
}
|
|
1502
|
+
return output;
|
|
1503
|
+
};
|
|
1504
|
+
const local = globalExplainer.localExplain(input, output, model);
|
|
1505
|
+
return new Map<string, any>([
|
|
1506
|
+
["input", new Map(Object.entries(local.input))],
|
|
1507
|
+
["output", local.output],
|
|
1508
|
+
["topFactors", local.topFactors.map((f: FeatureImportance) => new Map<string, any>([
|
|
1509
|
+
["feature", f.feature], ["importance", f.importance],
|
|
1510
|
+
["direction", f.direction], ["description", f.description],
|
|
1511
|
+
]))],
|
|
1512
|
+
["counterfactual", local.counterfactual],
|
|
1513
|
+
["confidence", local.confidence],
|
|
1514
|
+
]);
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
if (op === "explain-natural") {
|
|
1518
|
+
const rawExpl = args[0];
|
|
1519
|
+
let audience: 'technical' | 'general' = 'technical';
|
|
1520
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
1521
|
+
const key = String(args[i]).replace(/^:/, "");
|
|
1522
|
+
if (key === "audience") audience = String(args[i + 1]) as 'technical' | 'general';
|
|
1523
|
+
}
|
|
1524
|
+
if (!(rawExpl instanceof Map)) return "설명을 변환할 수 없습니다";
|
|
1525
|
+
const featuresRaw = rawExpl.get("features") ?? [];
|
|
1526
|
+
const features: FeatureImportance[] = (Array.isArray(featuresRaw) ? featuresRaw : []).map((f: any) => {
|
|
1527
|
+
if (f instanceof Map) {
|
|
1528
|
+
return {
|
|
1529
|
+
feature: String(f.get("feature") ?? ""),
|
|
1530
|
+
importance: Number(f.get("importance") ?? 0),
|
|
1531
|
+
direction: String(f.get("direction") ?? "positive") as 'positive' | 'negative',
|
|
1532
|
+
description: String(f.get("description") ?? ""),
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
return { feature: "", importance: 0, direction: "positive" as const, description: "" };
|
|
1536
|
+
});
|
|
1537
|
+
const altsRaw = rawExpl.get("alternatives") ?? [];
|
|
1538
|
+
const alternatives = (Array.isArray(altsRaw) ? altsRaw : []).map((a: any) => {
|
|
1539
|
+
if (a instanceof Map) return { decision: a.get("decision"), reason: String(a.get("reason") ?? ""), probability: Number(a.get("probability") ?? 0) };
|
|
1540
|
+
return { decision: null, reason: "", probability: 0 };
|
|
1541
|
+
});
|
|
1542
|
+
const explanation: DecisionExplanation = {
|
|
1543
|
+
decision: rawExpl.get("decision"),
|
|
1544
|
+
reasoning: rawExpl.get("reasoning") ?? [],
|
|
1545
|
+
features,
|
|
1546
|
+
confidence: Number(rawExpl.get("confidence") ?? 0.5),
|
|
1547
|
+
alternatives,
|
|
1548
|
+
summary: String(rawExpl.get("summary") ?? ""),
|
|
1549
|
+
audience: (rawExpl.get("audience") ?? "technical") as 'technical' | 'general',
|
|
1550
|
+
};
|
|
1551
|
+
return globalExplainer.toNaturalLanguage(explanation, audience);
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
if (op === "explain-contrast") {
|
|
1555
|
+
const factors: Record<string, number> = {};
|
|
1556
|
+
const rawF = args[2];
|
|
1557
|
+
if (rawF instanceof Map) {
|
|
1558
|
+
for (const [k, v] of rawF.entries()) factors[String(k).replace(/^:/, "")] = Number(v);
|
|
1559
|
+
} else if (rawF && typeof rawF === "object") {
|
|
1560
|
+
for (const [k, v] of Object.entries(rawF)) factors[String(k).replace(/^:/, "")] = Number(v);
|
|
1561
|
+
}
|
|
1562
|
+
return globalExplainer.contrastiveExplain(args[0], args[1], factors);
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
if (op === "explain-rules") {
|
|
1566
|
+
const examples: Array<{ input: Record<string, unknown>; output: unknown }> = [];
|
|
1567
|
+
const toRec = (v: any): Record<string, unknown> => {
|
|
1568
|
+
const r: Record<string, unknown> = {};
|
|
1569
|
+
if (v instanceof Map) { for (const [k, val] of v.entries()) r[String(k).replace(/^:/, "")] = val; }
|
|
1570
|
+
else if (v && typeof v === "object") { Object.assign(r, v); }
|
|
1571
|
+
return r;
|
|
1572
|
+
};
|
|
1573
|
+
if (Array.isArray(args[0])) {
|
|
1574
|
+
for (const ex of args[0]) {
|
|
1575
|
+
if (ex instanceof Map) examples.push({ input: toRec(ex.get("input")), output: ex.get("output") });
|
|
1576
|
+
else if (ex && typeof ex === "object") examples.push({ input: toRec((ex as any).input), output: (ex as any).output });
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return globalExplainer.extractRules(examples).map((r: any) => new Map<string, any>([
|
|
1580
|
+
["condition", r.condition], ["outcome", r.outcome], ["support", r.support],
|
|
1581
|
+
]));
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
if (op === "explain-top-factors") {
|
|
1585
|
+
let n = 3;
|
|
1586
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
1587
|
+
if (String(args[i]).replace(/^:/, "") === "n") n = Number(args[i + 1]);
|
|
1588
|
+
}
|
|
1589
|
+
const rawExpl = args[0];
|
|
1590
|
+
let features: any[] = [];
|
|
1591
|
+
if (rawExpl instanceof Map) features = rawExpl.get("features") ?? [];
|
|
1592
|
+
if (!Array.isArray(features)) features = [];
|
|
1593
|
+
return features.slice(0, n);
|
|
1594
|
+
}
|
|
1595
|
+
|
|
1596
|
+
if (op === "explain-summary") {
|
|
1597
|
+
const rawExpl = args[0];
|
|
1598
|
+
if (rawExpl instanceof Map) return String(rawExpl.get("summary") ?? "");
|
|
1599
|
+
return "";
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
return null;
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
// === Phase 141: WORLD-MODEL ===
|
|
1606
|
+
export function evalWorldModel141(op: string, args: any[]): any {
|
|
1607
|
+
if (op === "world-add-entity") {
|
|
1608
|
+
const kw: Record<string, any> = {};
|
|
1609
|
+
for (let i = 0; i < args.length - 1; i += 2) { kw[String(args[i]).replace(/^:/, "")] = args[i + 1]; }
|
|
1610
|
+
const rawP = kw["props"] ?? kw["properties"] ?? {};
|
|
1611
|
+
const props: Record<string, unknown> = rawP instanceof Map ? Object.fromEntries(rawP.entries()) : (typeof rawP === "object" && rawP !== null ? rawP : {});
|
|
1612
|
+
const e = globalWorldModel.addEntity({ id: String(kw["id"] ?? `entity-${Date.now()}`), type: String(kw["type"] ?? "unknown"), confidence: typeof kw["confidence"] === "number" ? kw["confidence"] : 1.0, properties: props });
|
|
1613
|
+
return new Map<string, any>([["id", e.id], ["type", e.type], ["properties", new Map(Object.entries(e.properties))], ["confidence", e.confidence], ["lastUpdated", e.lastUpdated.toISOString()]]);
|
|
1614
|
+
}
|
|
1615
|
+
if (op === "world-update-entity") {
|
|
1616
|
+
const rawPu = args[1] ?? {};
|
|
1617
|
+
const propsu: Record<string, unknown> = rawPu instanceof Map ? Object.fromEntries(rawPu.entries()) : (typeof rawPu === "object" && rawPu !== null ? rawPu : {});
|
|
1618
|
+
const eu = globalWorldModel.updateEntity(String(args[0] ?? ""), propsu);
|
|
1619
|
+
if (!eu) return null;
|
|
1620
|
+
return new Map<string, any>([["id", eu.id], ["type", eu.type], ["properties", new Map(Object.entries(eu.properties))], ["confidence", eu.confidence], ["lastUpdated", eu.lastUpdated.toISOString()]]);
|
|
1621
|
+
}
|
|
1622
|
+
if (op === "world-get-entity") {
|
|
1623
|
+
const eg = globalWorldModel.getEntity(String(args[0] ?? ""));
|
|
1624
|
+
if (!eg) return null;
|
|
1625
|
+
return new Map<string, any>([["id", eg.id], ["type", eg.type], ["properties", new Map(Object.entries(eg.properties))], ["confidence", eg.confidence], ["lastUpdated", eg.lastUpdated.toISOString()]]);
|
|
1626
|
+
}
|
|
1627
|
+
if (op === "world-remove-entity") { return globalWorldModel.removeEntity(String(args[0] ?? "")); }
|
|
1628
|
+
if (op === "world-add-relation") {
|
|
1629
|
+
const kwr: Record<string, any> = {};
|
|
1630
|
+
for (let i = 0; i < args.length - 1; i += 2) { kwr[String(args[i]).replace(/^:/, "")] = args[i + 1]; }
|
|
1631
|
+
const rel = globalWorldModel.addRelation({ from: String(kwr["from"] ?? ""), to: String(kwr["to"] ?? ""), type: String(kwr["type"] ?? "related"), strength: typeof kwr["strength"] === "number" ? kwr["strength"] : 1.0, bidirectional: kwr["bidirectional"] === true });
|
|
1632
|
+
return new Map<string, any>([["id", rel.id], ["from", rel.from], ["to", rel.to], ["type", rel.type], ["strength", rel.strength], ["bidirectional", rel.bidirectional]]);
|
|
1633
|
+
}
|
|
1634
|
+
if (op === "world-get-relations") {
|
|
1635
|
+
return globalWorldModel.getRelations(String(args[0] ?? "")).map(r => new Map<string, any>([["id", r.id], ["from", r.from], ["to", r.to], ["type", r.type], ["strength", r.strength], ["bidirectional", r.bidirectional]]));
|
|
1636
|
+
}
|
|
1637
|
+
if (op === "world-find-path") { return globalWorldModel.findPath(String(args[0] ?? ""), String(args[1] ?? "")); }
|
|
1638
|
+
if (op === "world-set-fact") { globalWorldModel.setFact(String(args[0] ?? ""), args[1]); return null; }
|
|
1639
|
+
if (op === "world-get-fact") { return globalWorldModel.getFact(String(args[0] ?? "")); }
|
|
1640
|
+
if (op === "world-add-rule") {
|
|
1641
|
+
const kwrule: Record<string, any> = {};
|
|
1642
|
+
for (let i = 0; i < args.length - 1; i += 2) { kwrule[String(args[i]).replace(/^:/, "")] = args[i + 1]; }
|
|
1643
|
+
const rule = globalWorldModel.addRule({ condition: String(kwrule["condition"] ?? ""), consequence: String(kwrule["consequence"] ?? ""), confidence: typeof kwrule["confidence"] === "number" ? kwrule["confidence"] : 0.8 });
|
|
1644
|
+
return new Map<string, any>([["id", rule.id], ["condition", rule.condition], ["consequence", rule.consequence], ["confidence", rule.confidence]]);
|
|
1645
|
+
}
|
|
1646
|
+
if (op === "world-apply-rules") { return globalWorldModel.applyRules().map(u => new Map<string, any>([["type", u.type], ["source", u.source], ["timestamp", u.timestamp.toISOString()]])); }
|
|
1647
|
+
if (op === "world-query") {
|
|
1648
|
+
const kwq: Record<string, any> = {};
|
|
1649
|
+
for (let i = 0; i < args.length - 1; i += 2) { kwq[String(args[i]).replace(/^:/, "")] = args[i + 1]; }
|
|
1650
|
+
return globalWorldModel.query(kwq["type"] !== undefined ? String(kwq["type"]) : undefined, kwq["min-confidence"] !== undefined ? Number(kwq["min-confidence"]) : undefined).map(e => new Map<string, any>([["id", e.id], ["type", e.type], ["properties", new Map(Object.entries(e.properties))], ["confidence", e.confidence], ["lastUpdated", e.lastUpdated.toISOString()]]));
|
|
1651
|
+
}
|
|
1652
|
+
if (op === "world-snapshot") {
|
|
1653
|
+
const snap = globalWorldModel.snapshot();
|
|
1654
|
+
return new Map<string, any>([["entityCount", snap.entities.size], ["relationCount", snap.relations.length], ["factCount", snap.facts.size], ["ruleCount", snap.rules.length], ["version", snap.version], ["timestamp", snap.timestamp.toISOString()]]);
|
|
1655
|
+
}
|
|
1656
|
+
if (op === "world-summarize") { return globalWorldModel.summarize(); }
|
|
1657
|
+
if (op === "world-history") { return globalWorldModel.getHistory().map(u => new Map<string, any>([["type", u.type], ["source", u.source], ["timestamp", u.timestamp.toISOString()]])); }
|
|
1658
|
+
return undefined;
|
|
1659
|
+
}
|