failproofai 1.0.2-beta.1 → 1.0.2-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +5 -5
  3. package/.next/standalone/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error/page/build-manifest.json +2 -2
  6. package/.next/standalone/.next/server/app/_global-error/page/server-reference-manifest.json +1 -1
  7. package/.next/standalone/.next/server/app/_global-error/page.js.nft.json +1 -1
  8. package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.rsc +7 -7
  11. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +6 -6
  12. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +7 -7
  13. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_not-found/page/build-manifest.json +2 -2
  15. package/.next/standalone/.next/server/app/_not-found/page/server-reference-manifest.json +1 -1
  16. package/.next/standalone/.next/server/app/_not-found/page.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  19. package/.next/standalone/.next/server/app/_not-found.rsc +14 -14
  20. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +14 -14
  21. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +13 -13
  22. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  23. package/.next/standalone/.next/server/app/api/audit/invite/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/audit/run/route.js.nft.json +1 -1
  25. package/.next/standalone/.next/server/app/api/audit/status/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/auth/login-request/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/auth/login-verify/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/auth/logout/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/auth/status/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/download/[project]/[session]/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/audit/page/build-manifest.json +2 -2
  32. package/.next/standalone/.next/server/app/audit/page/server-reference-manifest.json +2 -2
  33. package/.next/standalone/.next/server/app/audit/page.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/audit/page_client-reference-manifest.js +1 -1
  35. package/.next/standalone/.next/server/app/index.html +1 -1
  36. package/.next/standalone/.next/server/app/index.rsc +14 -14
  37. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +13 -13
  38. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +14 -14
  39. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  40. package/.next/standalone/.next/server/app/page/build-manifest.json +2 -2
  41. package/.next/standalone/.next/server/app/page/server-reference-manifest.json +1 -1
  42. package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
  43. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  44. package/.next/standalone/.next/server/app/policies/page/build-manifest.json +2 -2
  45. package/.next/standalone/.next/server/app/policies/page/server-reference-manifest.json +14 -14
  46. package/.next/standalone/.next/server/app/policies/page.js.nft.json +1 -1
  47. package/.next/standalone/.next/server/app/policies/page_client-reference-manifest.js +1 -1
  48. package/.next/standalone/.next/server/app/project/[name]/page/build-manifest.json +2 -2
  49. package/.next/standalone/.next/server/app/project/[name]/page/server-reference-manifest.json +1 -1
  50. package/.next/standalone/.next/server/app/project/[name]/page.js.nft.json +1 -1
  51. package/.next/standalone/.next/server/app/project/[name]/page_client-reference-manifest.js +1 -1
  52. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/build-manifest.json +2 -2
  53. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/react-loadable-manifest.json +2 -2
  54. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page/server-reference-manifest.json +2 -2
  55. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page.js.nft.json +1 -1
  56. package/.next/standalone/.next/server/app/project/[name]/session/[sessionId]/page_client-reference-manifest.js +1 -1
  57. package/.next/standalone/.next/server/app/projects/page/build-manifest.json +2 -2
  58. package/.next/standalone/.next/server/app/projects/page/server-reference-manifest.json +1 -1
  59. package/.next/standalone/.next/server/app/projects/page.js.nft.json +1 -1
  60. package/.next/standalone/.next/server/app/projects/page_client-reference-manifest.js +1 -1
  61. package/.next/standalone/.next/server/app/settings/page/build-manifest.json +2 -2
  62. package/.next/standalone/.next/server/app/settings/page/server-reference-manifest.json +4 -4
  63. package/.next/standalone/.next/server/app/settings/page.js.nft.json +1 -1
  64. package/.next/standalone/.next/server/app/settings/page_client-reference-manifest.js +1 -1
  65. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0o07qi9._.js +1 -1
  66. package/.next/standalone/.next/server/chunks/_0tovk6q._.js +1 -1
  67. package/.next/standalone/.next/server/chunks/_0trp3yc._.js +1 -1
  68. package/.next/standalone/.next/server/chunks/package_json_[json]_cjs_1nxcc4v._.js +1 -1
  69. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__013jr2b._.js +2 -2
  70. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__01wy8d-._.js +2 -2
  71. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__02npjtd._.js +2 -2
  72. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__07gm3zl._.js +3 -3
  73. package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__0l4748x._.js → [root-of-the-server]__090sxxw._.js} +2 -2
  74. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0da85px._.js +2 -2
  75. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0ftmoxc._.js +2 -2
  76. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0oa1lav._.js +1 -1
  77. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0p-5p8u._.js +2 -2
  78. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__0s740oi._.js +2 -2
  79. package/.next/standalone/.next/server/chunks/ssr/[root-of-the-server]__1p2otjt._.js +2 -2
  80. package/.next/standalone/.next/server/chunks/ssr/_08x1r5t._.js +1 -1
  81. package/.next/standalone/.next/server/chunks/ssr/{_0bwu160._.js → _0wb8osu._.js} +2 -2
  82. package/.next/standalone/.next/server/chunks/ssr/{_0ns6k3a._.js → _1oggjel._.js} +1 -1
  83. package/.next/standalone/.next/server/chunks/ssr/_1u8-lu2._.js +1 -1
  84. package/.next/standalone/.next/server/chunks/ssr/_1zopuov._.js +1 -1
  85. package/.next/standalone/.next/server/chunks/ssr/app_audit__components_audit-dashboard_tsx_0p9ud47._.js +1 -1
  86. package/.next/standalone/.next/server/chunks/ssr/app_global-error_tsx_1kp6l3x._.js +1 -1
  87. package/.next/standalone/.next/server/chunks/ssr/app_policies_hooks-client_tsx_19dqvpc._.js +1 -1
  88. package/.next/standalone/.next/server/chunks/ssr/app_settings_settings-client_tsx_20lq-mq._.js +1 -1
  89. package/.next/standalone/.next/server/middleware-build-manifest.js +5 -5
  90. package/.next/standalone/.next/server/pages/404.html +1 -1
  91. package/.next/standalone/.next/server/pages/500.html +1 -1
  92. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  93. package/.next/standalone/.next/server/server-reference-manifest.json +19 -19
  94. package/.next/standalone/.next/static/chunks/{1tynnrrh711lr.js → 0nnbtp0w4sxrr.js} +1 -1
  95. package/.next/standalone/.next/static/chunks/{22rqvlr7p_1mv.js → 0ykd_go4oahan.js} +1 -1
  96. package/.next/standalone/.next/static/chunks/{3tbbs_d8xrvyp.js → 140ip21rqmelt.js} +1 -1
  97. package/.next/standalone/.next/static/chunks/{0izgu7nqh2zp-.js → 1da5a_a-3btas.js} +1 -1
  98. package/.next/standalone/.next/static/chunks/{1oml7c7env4-g.js → 1fac8krph-zgp.js} +1 -1
  99. package/.next/standalone/.next/static/chunks/{2whxqyskpirbk.js → 1nzy5jc_vf9e0.js} +1 -1
  100. package/.next/standalone/.next/static/chunks/1yw71gn8vqco1.js +6 -0
  101. package/.next/standalone/.next/static/chunks/29eh4k77otcw6.js +1 -0
  102. package/.next/standalone/.next/static/chunks/2axi5ehjbld9h.js +1 -0
  103. package/.next/standalone/.next/static/chunks/{3ms6gxfm82t6s.js → 2fzxl7n717pbc.js} +1 -1
  104. package/.next/standalone/.next/static/chunks/{01u1cf8js2yd6.js → 3jjmdqqzem21x.js} +1 -1
  105. package/.next/standalone/.next/static/chunks/{turbopack-3kjgdgwci4tqf.js → turbopack-2vqpa-dts1gy4.js} +1 -1
  106. package/.next/standalone/package.json +9 -9
  107. package/.next/standalone/server.js +1 -1
  108. package/bin/failproofai.mjs +4 -4
  109. package/dist/cli.mjs +95 -154
  110. package/dist/worker.mjs +1 -2
  111. package/package.json +9 -9
  112. package/src/hooks/configure-wizard.ts +22 -86
  113. package/src/hooks/fp-reset.ts +9 -26
  114. package/src/hooks/manager.ts +44 -16
  115. package/src/hooks/pack-cli.ts +65 -0
  116. package/src/hooks/tui.ts +24 -8
  117. package/.next/standalone/.next/static/chunks/0u4-org_e7zde.js +0 -1
  118. package/.next/standalone/.next/static/chunks/31mwk8k0q3_3g.js +0 -6
  119. package/.next/standalone/.next/static/chunks/43nlc236oo898.js +0 -1
  120. /package/.next/standalone/.next/static/{I5kEb9kSgYS63j4iqfVLO → A7czO1PZdTcNzLGa_H1sm}/_buildManifest.js +0 -0
  121. /package/.next/standalone/.next/static/{I5kEb9kSgYS63j4iqfVLO → A7czO1PZdTcNzLGa_H1sm}/_clientMiddlewareManifest.js +0 -0
  122. /package/.next/standalone/.next/static/{I5kEb9kSgYS63j4iqfVLO → A7czO1PZdTcNzLGa_H1sm}/_ssgManifest.js +0 -0
@@ -89,7 +89,6 @@ import {
89
89
  import {
90
90
  detectSetupState,
91
91
  isConfigured,
92
- buildTargetChoices,
93
92
  scopesFor,
94
93
  type SetupTarget,
95
94
  } from "./setup-state";
@@ -893,86 +892,24 @@ export async function runConfigureWizard(io: WizardIO = {}): Promise<WizardResul
893
892
 
894
893
  // 0 — Recommended, or choose everything yourself?
895
894
  //
896
- // Setup used to open by asking four questions — scope, policy bundles,
897
- // harnesses, cloud — of somebody who has just installed the tool and does not
898
- // yet know what any of them mean. Every one of those answers has a defensible
899
- // default, so asking for all four up front is making the person least able to
900
- // answer do the most work.
895
+ // ONE linear flow, and no opening fork.
901
896
  //
902
- // Recommended is not a shortcut past the decisions; it IS a decision, taken
903
- // once, here, on their behalf: global scope, the CLIs actually on this
904
- // machine, and `RECOMMENDED_POLICIES` which is written out in
905
- // policy-presets.ts with the reasoning for every inclusion and every
906
- // omission, because "what does Recommended do" has to be answerable without
907
- // reading code.
897
+ // Setup used to ask "Recommended or Customize?" before anything else, which
898
+ // is a question about the wizard rather than about the machine you cannot
899
+ // answer it until you know what the alternatives are, and you only learn that
900
+ // by picking one. Recommended then silently took global scope, the detected
901
+ // CLIs, and fifteen policies nobody had seen.
908
902
  //
909
- // Customize is the wizard exactly as it was. Nothing is removed and nothing
910
- // is hidden; it stops being the only way through.
911
- const detectedNow = detectInstalledClis();
912
- const recommendedClis = detectedNow.filter((id) => clisSupportingScope("user").includes(id));
913
- const mode = await selectOne<"recommended" | "customize">({
914
- message: "Set up failproofai",
915
- choices: [
916
- {
917
- label: "Recommended",
918
- value: "recommended",
919
- hint: recommendedClis.length
920
- ? `${recommendedClis.length} detected ${recommendedClis.length === 1 ? "CLI" : "CLIs"} · global`
921
- : "global",
922
- },
923
- {
924
- label: "Customize",
925
- value: "customize",
926
- hint: "choose scope and harnesses",
927
- },
928
- ],
929
- stdin,
930
- stdout,
931
- });
932
- if (mode === null) return cancel();
933
-
934
- // 1 — Where? Inferred from cwd, then confirmed.
935
- //
936
- // Running from inside a project and running from a home directory are two
937
- // different intents, and asking a context-free "global or project?" made the
938
- // user restate something they had already expressed by choosing where to run
939
- // the command. So the choices are built from what actually exists here — and
940
- // labelled Update vs Set up accordingly — with the likelier target first.
941
- const setupState = detectSetupState(cwd);
942
- const targetChoices = buildTargetChoices(setupState);
943
-
944
- let target: SetupTarget;
945
- if (mode === "recommended") {
946
- // Global, always. A project-scoped install guards the one directory the
947
- // command happened to be run from and silently leaves every other repo on
948
- // the machine unguarded — which is the opposite of what somebody choosing
949
- // "Recommended" is asking for.
950
- target = "user";
951
- } else if (targetChoices.length === 1) {
952
- // From a home directory there is no project to configure, so there is no
953
- // question to ask. Say what is about to happen rather than silently
954
- // deciding it.
955
- target = targetChoices[0].value;
956
- stdout.write(`Configuring ${targetChoices[0].label.toLowerCase()} — ${targetChoices[0].hint}.\n\n`);
957
- } else {
958
- const chosen = await selectOne<SetupTarget>({
959
- message: "What are we configuring?",
960
- choices: targetChoices.map((c) => ({
961
- label: c.label,
962
- value: c.value,
963
- hint: c.hint,
964
- })),
965
- stdin,
966
- stdout,
967
- });
968
- if (chosen === null) return cancel();
969
- target = chosen;
970
- }
903
+ // What is left is three questions, in the order the machine needs them:
904
+ // the daemon (already installed above, because it is the only step that needs
905
+ // a password), then which harnesses, then whether to connect. Scope is not
906
+ // among them: it is GLOBAL, always. A project-scoped install guards the one
907
+ // directory the command happened to be run from and silently leaves every
908
+ // other repo on the machine unguarded — `failproofai policies --install
909
+ // --scope project` is still there for someone who genuinely wants that, and
910
+ // knows they do.
911
+ const target: SetupTarget = "user";
971
912
  const scopes = scopesFor(target);
972
- // The scope whose CURRENT state seeds the pickers below. With "Both" the
973
- // project is the more specific of the two and the one the user is standing
974
- // in, so it wins; anything it does not define still falls back to global at
975
- // merge time, which is exactly the layering the policy loader already does.
976
913
  const primaryScope: HookScope = scopes.includes("project") ? "project" : "user";
977
914
 
978
915
  // 2 — Which harnesses?
@@ -1001,15 +938,14 @@ export async function runConfigureWizard(io: WizardIO = {}): Promise<WizardResul
1001
938
  // An "Everything available" row protects every supported CLI (detected +
1002
939
  // set-up-ahead); when ticked it wins over the individual boxes.
1003
940
  //
1004
- // No `allowBack`: with the policy step gone there is nothing before this
1005
- // inside setup to return to the scope question is frequently not asked at
1006
- // all (a single choice is stated, not prompted), so a here would sometimes
1007
- // go nowhere. That also retires the loop this step used to sit in, and the
1008
- // carried-selection machinery the loop needed.
941
+ // Always asked, never inferred. This is the one decision setup genuinely
942
+ // cannot make for you: which agents on this machine should be guarded. The
943
+ // detected ones are pre-ticked, so the common answer is a single keypress.
944
+ //
945
+ // No `allowBack`: with the policy step and the scope fork both gone, there is
946
+ // nothing inside setup to return to.
1009
947
  let clisSel: string[];
1010
- if (mode === "recommended") {
1011
- clisSel = recommendedClis;
1012
- } else {
948
+ {
1013
949
  const picked = await multiSelect<string>({
1014
950
  message: "Which harnesses should it protect?",
1015
951
  choices: [
@@ -98,7 +98,6 @@ import {
98
98
  isDaemonSupportedPlatform,
99
99
  probeDaemonEndToEnd,
100
100
  } from "./daemon-service";
101
- import { readHooksConfig } from "./hooks-config";
102
101
 
103
102
  export interface ResetOutcome {
104
103
  /** Paths that existed and were removed. */
@@ -965,33 +964,17 @@ export function resetHome(from: number, to: number = LAYOUT_VERSION): ResetOutco
965
964
  // straight out of the same file. Both paths end at the same key, and only one
966
965
  // of them represents something a person typed.
967
966
  if (telemetryOptOut) updateConfig({ telemetry: { enabled: false } });
968
- // `packs/` is resettable, but the package's default pack is also the offline
969
- // enforcement floor. Restore it from the installed package before declaring
970
- // the migration complete; third-party packs remain explicitly re-fetchable.
967
+ // No pack is installed here, deliberately.
971
968
  //
972
- // Carrying `enabledPolicies` INTO the selection, not installing defaults over
973
- // it. This is the upgrade path every existing user takes, and installing
974
- // defaults meant a machine that had switched `block-force-push` and
975
- // `block-kubectl` on came back with them off guards that were denying
976
- // before the upgrade and allowing after, with nothing said.
977
- const carried = (() => {
978
- try {
979
- const names = readHooksConfig().enabledPolicies ?? [];
980
- return names.length > 0 ? { only: names } : undefined;
981
- } catch {
982
- return undefined;
983
- }
984
- })();
985
- // Deliberately does NOT install a pack. There is no copy in this package to
986
- // install any more, and `resetHome` is synchronous and runs inside
987
- // `failproofai update` — an upgrade that blocks on github.com, and fails when
988
- // it is unreachable, is a worse upgrade than one that finishes.
969
+ // There is no copy in this package to install — our policies are fetched from
970
+ // their GitHub release like anybody else's and `resetHome` is SYNCHRONOUS
971
+ // and runs inside `failproofai update`. An upgrade that blocks on github.com,
972
+ // and fails when it is unreachable, is a worse upgrade than one that finishes.
989
973
  //
990
- // The carried names stay in config, which is what the no-pack fallback reads,
991
- // so a machine mid-upgrade keeps enforcing exactly what it enforced before.
992
- // `failproofai policies add core` turns them into a real pack when the user
993
- // is online, and carries this selection into it.
994
- void carried;
974
+ // Nothing needs carrying either: `enabledPolicies` is left exactly where it
975
+ // is, and the no-pack fallback reads it, so a machine mid-upgrade keeps
976
+ // enforcing precisely what it enforced before. `failproofai policies add core`
977
+ // turns those names into a real pack, carrying the same selection into it.
995
978
  // The step's OWN target, not LAYOUT_VERSION.
996
979
  //
997
980
  // Every step used to end stamping the current layout, which was harmless
@@ -867,25 +867,53 @@ export async function listHooks(cwd?: string): Promise<void> {
867
867
  return 0;
868
868
  }
869
869
  })();
870
- groups.push(
871
- title(
872
- "failproofai policies",
873
- installedScopes.length === 0
874
- ? "not installed"
875
- : `${installedScopes.join(" + ")} · ${packCount} on`,
876
- opts,
877
- ),
878
- );
870
+ // `installedScopes` is about HOOKS — whether any agent CLI is wired to call
871
+ // us — and it says nothing about whether policies exist. Reporting it as
872
+ // "not installed" above a listing of an installed pack was a flat
873
+ // contradiction, and it hid the state that actually matters: a machine can
874
+ // hold thirty-eight policies and enforce none of them, because nothing is
875
+ // calling failproofai at all. That is the worst of the three states and it
876
+ // used to read like the emptiest.
877
+ const packsPresent = (() => {
878
+ try {
879
+ return readInstalledPacks().packs.length > 0;
880
+ } catch {
881
+ return false;
882
+ }
883
+ })();
884
+ const subtitle =
885
+ installedScopes.length > 0
886
+ ? `${installedScopes.join(" + ")} · ${packCount} on`
887
+ : packsPresent
888
+ ? `${packCount} on · NOT ENFORCING`
889
+ : "nothing installed";
890
+ groups.push(title("failproofai policies", subtitle, opts));
879
891
 
880
892
  if (installedScopes.length === 0) {
881
893
  groups.push(
882
- nextStep(
883
- "failproofai policies --install",
884
- config.enabledPolicies.length > 0
885
- ? "These are configured but NOT installed no hook is running them:"
886
- : "Nothing is installed yet. Get started with:",
887
- opts,
888
- ),
894
+ packsPresent
895
+ ? warning(
896
+ [
897
+ // ONE string, not four hand-broken ones. `warning` wraps each
898
+ // element to the terminal, so pre-wrapped prose keeps its author's
899
+ // line breaks as paragraph breaks and then wraps again inside
900
+ // them — which at 60 columns left the word "them." alone on a
901
+ // line. The command stays separate because it is not prose and
902
+ // must never be split across a wrap.
903
+ "These policies are installed but NOTHING is running them. No agent " +
904
+ "CLI on this machine is wired to call failproofai, so every policy " +
905
+ "below is inert. Wire it up with:",
906
+ " failproofai config",
907
+ ],
908
+ opts,
909
+ )
910
+ : nextStep(
911
+ "failproofai config",
912
+ config.enabledPolicies.length > 0
913
+ ? "These are configured but NOT installed — no hook is running them:"
914
+ : "Nothing is set up yet. Get started with:",
915
+ opts,
916
+ ),
889
917
  );
890
918
  }
891
919
  // Held back to the end rather than printed here. Everything below this point
@@ -601,6 +601,46 @@ export async function runPublishCommand(rest: string[]): Promise<PackCliResult>
601
601
  return publish(rest);
602
602
  }
603
603
 
604
+ /**
605
+ * The pack's own list, defaults pre-ticked, before anything is installed.
606
+ *
607
+ * Reads the MANIFEST only — `fetchPackPreview` never downloads the entry
608
+ * artifact — so the code of a pack you are still deciding about is never
609
+ * fetched, let alone imported.
610
+ *
611
+ * Returns null when the user cancelled, which must not be confused with an
612
+ * empty selection: one means "install nothing", the other means "do nothing".
613
+ */
614
+ async function pickFromSource(
615
+ source: string,
616
+ io: { stdin: TTYIn; stdout: TTYOut },
617
+ ): Promise<string[] | null> {
618
+ const preview = await fetchPackPreview(source);
619
+ const categories = [...new Set(preview.policies.map((p) => p.category))];
620
+ const rows: MultiChoice<string>[] = [];
621
+ for (const category of categories) {
622
+ for (const policy of preview.policies.filter((p) => p.category === category)) {
623
+ rows.push({
624
+ label: policy.name,
625
+ value: policy.name,
626
+ hint: policy.description,
627
+ checked: policy.defaultEnabled,
628
+ section: `${category} · ${slugifyCategory(category)}`,
629
+ });
630
+ }
631
+ }
632
+ const on = preview.policies.filter((p) => p.defaultEnabled).length;
633
+ const picked = await multiSelect<string>({
634
+ message: `${preview.id}@${preview.version} — which of these should be on?`,
635
+ choices: rows,
636
+ summaryNoun: "policies",
637
+ hint: `space toggles · ctrl+a all · ↵ confirm · ${on} of ${rows.length} are the publisher's defaults`,
638
+ stdin: io.stdin,
639
+ stdout: io.stdout,
640
+ });
641
+ return picked;
642
+ }
643
+
604
644
  async function add(rest: string[]): Promise<PackCliResult> {
605
645
  const source = packAddSource(rest);
606
646
  const selection = selectionFrom(rest);
@@ -627,6 +667,31 @@ async function add(rest: string[]): Promise<PackCliResult> {
627
667
  return fail(["--category needs at least one category, comma-separated"]);
628
668
  }
629
669
 
670
+ // CHOOSE, then install. A pack's `defaultEnabled` flags are the publisher's
671
+ // recommendation, and taking them silently turns a recommendation into a
672
+ // decision made on the user's behalf — announced only afterwards, by which
673
+ // point the policies are already on their machine.
674
+ //
675
+ // So a human at a terminal who named no flags gets the list first, with the
676
+ // publisher's defaults pre-ticked. The manifest is read WITHOUT downloading
677
+ // the entry artifact, so deciding about a stranger's pack still never runs a
678
+ // stranger's code.
679
+ //
680
+ // Skipped entirely when a selection was passed (`--policy`, `--category`,
681
+ // `--all`) or when there is no terminal: a script asked a precise question and
682
+ // must get a precise answer, not a prompt it cannot see.
683
+ const io = { stdin: process.stdin as TTYIn, stdout: process.stdout as TTYOut };
684
+ const chose = !selection.only && !selection.categories && !selection.all;
685
+ if (chose && io.stdin.isTTY && io.stdout.isTTY) {
686
+ const picked = await pickFromSource(resolvedSource!, io);
687
+ if (picked === null) return ok(["Nothing installed."]);
688
+ selection.only = picked;
689
+ // An empty pick is a real answer — install the pack, enable none of it —
690
+ // but `{only: []}` is indistinguishable from "no selection" downstream, so
691
+ // it is carried as an explicit empty list the resolver can see.
692
+ if (picked.length === 0) selection.only = [];
693
+ }
694
+
630
695
  try {
631
696
  const result = await addPack(resolvedSource!, selection);
632
697
  const lines = [
package/src/hooks/tui.ts CHANGED
@@ -108,7 +108,7 @@ const RADIO_OFF = "○";
108
108
  export const CHECK_ON = "◼";
109
109
  export const CHECK_OFF = "◻";
110
110
  export const CARET = "❯";
111
- const FLOWER = "";
111
+ const MARK = "\u25AE\u25AE"; // ▮▮ — the brand mark, per the design system
112
112
 
113
113
  // ── color ─────────────────────────────────────────────────────────────────
114
114
  // The single source of truth for the brand palette — exported (via `paint`)
@@ -380,7 +380,7 @@ export function renderBrandLogo(stdout: TTYOut = process.stdout): string[] {
380
380
  const c = paint(colorsEnabled(stdout));
381
381
  const cols = stdout.columns || 80;
382
382
  if (cols < LOGO_MIN_COLS) {
383
- return [`${c.guide(FLOWER)} fa${c.pink("il")}proof ai ${c.dim("· " + TAGLINE)}`];
383
+ return [`${c.pink(MARK)} fa${c.pink("il")}proof ai ${c.dim("· " + TAGLINE)}`];
384
384
  }
385
385
  // NO_COLOR / non-TTY forces `basic`, which renderLogo draws monochrome — so
386
386
  // the mark never emits an escape byte on a stream that asked for none.
@@ -491,9 +491,25 @@ type Region = { lastCount: number };
491
491
 
492
492
  const WINDOW = 8; // visible rows before the checklist scrolls
493
493
 
494
+ /**
495
+ * Redraw the region as ONE atomic frame.
496
+ *
497
+ * Two things make it atomic, and both are needed. The cursor-up-and-clear used
498
+ * to be its own `write()`, so a terminal could render the CLEARED state before
499
+ * the new lines arrived — a blank flash on every keystroke, invisible locally
500
+ * and obvious over SSH or inside tmux, where the two writes cross a network or
501
+ * a multiplexer between frames. They are one string now.
502
+ *
503
+ * And that string is wrapped in synchronized output (DECSET 2026), which tells
504
+ * the terminal to hold what it has until the reset rather than painting each
505
+ * chunk as it lands. Terminals that do not implement it ignore an unknown
506
+ * private mode, so it costs nothing where it does not help.
507
+ */
494
508
  function repaint(out: TTYOut, region: Region, lines: string[]): void {
495
- if (region.lastCount > 0) out.write(`${ESC}[${region.lastCount}A${ESC}[J`);
496
- writeLines(out, lines);
509
+ const cols = out.columns || 80;
510
+ const body = lines.map((l) => (l === "" ? l : truncate(l, cols))).join("\n") + "\n";
511
+ const clear = region.lastCount > 0 ? `${ESC}[${region.lastCount}A${ESC}[J` : "";
512
+ out.write(`${ESC}[?2026h${clear}${body}${ESC}[?2026l`);
497
513
  region.lastCount = lines.length;
498
514
  }
499
515
 
@@ -1238,9 +1254,9 @@ export function rule(label?: string, opts?: RenderOpts): string[] {
1238
1254
  const { cols, c } = ctx(opts);
1239
1255
  const width = Math.max(4, cols - INDENT.length * 2);
1240
1256
  if (!label) return [`${INDENT}${c.dim("─".repeat(width))}`];
1241
- const head = `── ${label} `;
1257
+ const head = `━━ ${label} `;
1242
1258
  const tail = Math.max(3, width - head.length);
1243
- return [`${INDENT}${c.dim(head + "".repeat(tail))}`];
1259
+ return [`${INDENT}${c.dim(head + "".repeat(tail))}`];
1244
1260
  }
1245
1261
 
1246
1262
  export interface Row {
@@ -1415,7 +1431,7 @@ const CHIP_LABELS: Record<ChipState, string> = {
1415
1431
  locked: "✓ LOCK",
1416
1432
  cloud: "✓ CLOUD",
1417
1433
  pack: "✓ PACK",
1418
- failed: " FAIL",
1434
+ failed: "\u25B2 FAIL",
1419
1435
  observe: "◉ OBS",
1420
1436
  };
1421
1437
 
@@ -1486,7 +1502,7 @@ function gutterBlock(symbol: string, lines: string[], opts?: RenderOpts): string
1486
1502
  * scopes or six about the daemon. */
1487
1503
  export function warning(lines: string[], opts?: RenderOpts): string[] {
1488
1504
  const { c } = ctx(opts);
1489
- return gutterBlock(c.warn(""), lines, opts);
1505
+ return gutterBlock(c.warn("\u25B2"), lines, opts);
1490
1506
  }
1491
1507
 
1492
1508
  /** The same, for the ones that destroy something. */
@@ -1 +0,0 @@
1
- (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,3831,e=>{"use strict";var t=e.i(95187);let a=(0,t.createServerReference)("602351c202b85b8076570a2308b7d8dbbbb5512b78",t.callServer,void 0,t.findSourceMapURL,"searchHookActivityAction");e.s(["searchHookActivityAction",0,a])},73520,e=>{"use strict";var t=e.i(43476),a=e.i(24071),r=e.i(67927);e.s(["default",0,function({currentPage:e,totalPages:l,onPageChange:s}){if(l<=1)return null;let o=e=>`px-3 py-2 text-sm rounded-md transition-colors flex items-center gap-1 bg-muted text-muted-foreground ${e?"opacity-50 cursor-not-allowed":"hover:bg-muted/80"}`;return(0,t.jsxs)("div",{className:"flex items-center justify-center gap-2 py-4",children:[(0,t.jsxs)("button",{onClick:()=>s(e-1),disabled:1===e,className:o(1===e),"aria-label":"Previous page",children:[(0,t.jsx)(a.ChevronLeft,{className:"w-4 h-4"}),(0,t.jsx)("span",{className:"hidden sm:inline",children:"Previous"})]}),(0,t.jsx)("div",{className:"flex items-center gap-1",children:(()=>{if(l<=7)return Array.from({length:l},(e,t)=>t+1);let t=[1],a=Math.max(2,e-1),r=Math.min(l-1,e+1);e<=3&&(r=Math.min(5,l-1)),e>=l-2&&(a=Math.max(2,l-4)),a>2&&t.push("ellipsis-start");for(let e=a;e<=r;e++)t.push(e);return r<l-1&&t.push("ellipsis-end"),t.push(l),t})().map(a=>"string"==typeof a?(0,t.jsx)("span",{className:"px-2 text-muted-foreground",children:"..."},a):(0,t.jsx)("button",{onClick:()=>s(a),className:`min-w-[2.5rem] px-3 py-2 text-sm rounded-md transition-colors ${e===a?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground hover:bg-muted/80"}`,"aria-label":`Page ${a}`,"aria-current":e===a?"page":void 0,children:a},a))}),(0,t.jsxs)("button",{onClick:()=>s(e+1),disabled:e===l,className:o(e===l),"aria-label":"Next page",children:[(0,t.jsx)("span",{className:"hidden sm:inline",children:"Next"}),(0,t.jsx)(r.ChevronRight,{className:"w-4 h-4"})]})]})}])},24578,e=>{"use strict";let t={claude:{id:"claude",label:"Claude Code",badgeClasses:"bg-orange-500/10 text-orange-400 border-orange-500/20"},codex:{id:"codex",label:"OpenAI Codex",badgeClasses:"bg-purple-500/10 text-purple-400 border-purple-500/20"},copilot:{id:"copilot",label:"GitHub Copilot",badgeClasses:"bg-blue-500/10 text-blue-400 border-blue-500/20"},cursor:{id:"cursor",label:"Cursor Agent",badgeClasses:"bg-emerald-500/10 text-emerald-400 border-emerald-500/20"},opencode:{id:"opencode",label:"OpenCode",badgeClasses:"bg-amber-500/10 text-amber-400 border-amber-500/20"},pi:{id:"pi",label:"Pi",badgeClasses:"bg-pink-500/10 text-pink-400 border-pink-500/20"},hermes:{id:"hermes",label:"Hermes",badgeClasses:"bg-indigo-500/10 text-indigo-400 border-indigo-500/20"},openclaw:{id:"openclaw",label:"OpenClaw",badgeClasses:"bg-teal-500/10 text-teal-400 border-teal-500/20"},factory:{id:"factory",label:"Factory Droid",badgeClasses:"bg-rose-500/10 text-rose-400 border-rose-500/20"},devin:{id:"devin",label:"Devin CLI",badgeClasses:"bg-violet-500/10 text-violet-400 border-violet-500/20"},antigravity:{id:"antigravity",label:"Antigravity CLI",badgeClasses:"bg-cyan-500/10 text-cyan-400 border-cyan-500/20"},goose:{id:"goose",label:"Goose",badgeClasses:"bg-lime-500/10 text-lime-400 border-lime-500/20"}};e.s(["KNOWN_CLI_IDS",0,["claude","codex","copilot","cursor","opencode","pi","hermes","openclaw","factory","devin","antigravity","goose"],"getCliBadgeClasses",0,function(e){return t[e]?.badgeClasses??t.claude.badgeClasses},"getCliLabel",0,function(e){return t[e]?.label??e},"isKnownCli",0,function(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(t,e)}])},34713,e=>{"use strict";e.s(["formatDuration",0,function(e){if(e<1e3)return`${e}ms`;let t=Math.round(e/100);if(t<600)return`${(t/10).toFixed(1)}s`;let a=Math.round(e/1e3);if(a<3600){let e=Math.floor(a/60);return`${e}m ${a%60}s`}let r=Math.round(e/6e4),l=Math.floor(r/60);return`${l}h ${r%60}m`},"formatRelativeTime",0,function(e){let t=Date.now()-e;return t<6e4?`${Math.max(1,Math.floor(t/1e3))}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:t<864e5?`${Math.floor(t/36e5)}h ago`:`${Math.floor(t/864e5)}d ago`}])},80060,2711,e=>{"use strict";var t=e.i(18566),a=e.i(71645);function r(e){let t=e.getFullYear(),a=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${t}-${a}-${r}`}function l(e){var t;if(!e||(t=e,!/^\d{4}-\d{2}-\d{2}$/.test(t)||isNaN(Date.parse(t))))return null;let[a,r,l]=e.split("-").map(Number);return new Date(a,r-1,l,12,0,0)}e.s(["useUrlParams",0,function(){let e=(0,t.useSearchParams)(),r=(0,t.useRouter)(),l=(0,t.usePathname)(),s=(0,a.useRef)(null),o=(0,a.useCallback)(t=>e.get(t),[e]),i=(0,a.useCallback)(()=>new URLSearchParams(e.toString()),[e]),n=(0,a.useCallback)(t=>{s.current&&clearTimeout(s.current),s.current=setTimeout(()=>{let a=new URLSearchParams(e.toString());for(let[e,r]of Object.entries(t))void 0===r||""===r?a.delete(e):a.set(e,r);let s=a.toString(),o=s?`${l}?${s}`:l;r.replace(o,{scroll:!1})},150)},[e,l,r]);return(0,a.useEffect)(()=>()=>{s.current&&clearTimeout(s.current)},[]),{get:o,getAll:i,setAll:n}}],80060),e.s(["dateRangeToParams",0,function(e){let t={};return e.from&&(t.from=r(e.from)),e.to&&(t.to=r(e.to)),t},"keywordsToParam",0,function(e){if(0!==e.length)return e.map(e=>encodeURIComponent(e)).join(",")},"pageToParam",0,function(e){return e<=1?void 0:String(e)},"paramToKeywords",0,function(e){return e?e.split(",").map(e=>decodeURIComponent(e.trim())).filter(e=>e.length>0):[]},"paramToPage",0,function(e){if(!e)return 1;let t=parseInt(e,10);return Number.isFinite(t)&&t>=1?t:1},"paramToPreset",0,function(e){return e&&["all","last-hour","today","last-7-days","last-30-days","custom"].includes(e)?e:"all"},"paramsToDateRange",0,function(e,t){return{from:l(e),to:l(t)}},"presetToParam",0,function(e){return"all"===e?void 0:e}],2711)},89664,e=>{"use strict";let t=(0,e.i(56420).default)("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);e.s(["Check",0,t],89664)},24071,e=>{"use strict";let t=(0,e.i(56420).default)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]);e.s(["ChevronLeft",0,t],24071)},67927,e=>{"use strict";let t=(0,e.i(56420).default)("chevron-right",[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]);e.s(["ChevronRight",0,t],67927)},8734,e=>{"use strict";let t=(0,e.i(56420).default)("copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]);e.s(["Copy",0,t],8734)},16306,e=>{"use strict";let t=(0,e.i(56420).default)("shield-alert",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]]);e.s(["ShieldAlert",0,t],16306)},84026,29407,e=>{"use strict";var t=e.i(56420);let a=(0,t.default)("shield-check",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);e.s(["ShieldCheck",0,a],84026);let r=(0,t.default)("shield-x",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);e.s(["ShieldX",0,r],29407)},82954,e=>{"use strict";let t=(0,e.i(56420).default)("shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]);e.s(["Shield",0,t],82954)},63676,e=>{"use strict";let t=(0,e.i(56420).default)("x",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]);e.s(["X",0,t],63676)}]);
@@ -1,6 +0,0 @@
1
- (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,64245,e=>{"use strict";var t=e.i(43476),s=e.i(71645),r=e.i(74080),n=e.i(22016),a=e.i(89664),o=e.i(16327),l=e.i(56420);let i=(0,l.default)("code",[["path",{d:"m16 18 6-6-6-6",key:"eg8j8"}],["path",{d:"m8 6-6 6 6 6",key:"ppft3o"}]]);var c=e.i(8734);let d=(0,l.default)("package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]),m=(0,l.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]);var u=e.i(66794),x=e.i(82954),p=e.i(16306),h=e.i(84026),b=e.i(29407);let f=(0,l.default)("trash-2",[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]]),g=(0,l.default)("triangle-alert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);var v=e.i(63676),j=e.i(73520),y=e.i(95187);let N=(0,y.createServerReference)("40a3b79742d87941c9f146cb0a91ca46ab0fc4c319",y.callServer,void 0,y.findSourceMapURL,"getHookActivityAction");var k=e.i(3831);let w=(0,y.createServerReference)("00c080892c671c20bdd41d01d514bd948c5848679e",y.callServer,void 0,y.findSourceMapURL,"getActivePausesAction");function S({pauses:e,now:r}){let[n,a]=(0,s.useState)(()=>Date.now());(0,s.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(e)},[]);let o=r??n,l=e.filter(e=>e.expiresAt>o);if(0===l.length)return null;let i=l.reduce((e,t)=>e.expiresAt<t.expiresAt?e:t);return(0,t.jsxs)("div",{role:"status",className:"mb-4 flex items-start gap-2.5 rounded border border-amber-500/40 bg-amber-500/[0.07] px-3 py-2.5",children:[(0,t.jsx)(p.ShieldAlert,{className:"h-4 w-4 shrink-0 text-amber-500 mt-0.5","aria-hidden":"true"}),(0,t.jsxs)("div",{className:"text-xs leading-relaxed",children:[(0,t.jsxs)("p",{className:"font-medium text-foreground",children:["Enforcement is paused for ",l.length," session",1===l.length?"":"s"," —"," ",function(e){if(e<=0)return"expiring now";if(e<6e4)return"under a minute";let t=Math.round(e/6e4);if(t<60)return`${t}m`;let s=Math.floor(t/60),r=t%60;return 0===r?`${s}h`:`${s}h${r}m`}(i.expiresAt-o)," left",l.length>1?" on the next to expire":"","."]}),(0,t.jsxs)("p",{className:"text-muted-foreground mt-0.5",children:["Builtin, custom and convention policies are suspended for"," ",1===l.length?"that session":"those sessions","; cloud-managed policies keep enforcing. It lifts on its own — or run"," ",(0,t.jsx)("span",{className:"font-mono text-foreground",children:"failproofai config --resume"}),"."]})]})]})}function P(){return(0,t.jsx)("span",{title:"Enforcement was paused for this session — local policies did not run",className:"ml-1.5 inline-flex items-center rounded px-1.5 py-0.5 text-[0.6rem] font-medium uppercase tracking-wide border border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-500",children:"paused"})}function C({item:e}){if(!e.pausedBy)return null;let s="number"==typeof e.pauseExpiresAt?new Date(e.pauseExpiresAt).toLocaleTimeString():null;return(0,t.jsxs)("div",{className:"sm:col-span-2 lg:col-span-3 mt-1 flex items-start gap-2 rounded border border-amber-500/30 bg-amber-500/5 px-2.5 py-2",children:[(0,t.jsx)(g,{className:"h-3.5 w-3.5 shrink-0 text-amber-500/80 mt-0.5","aria-hidden":"true"}),(0,t.jsxs)("p",{className:"text-[0.7rem] leading-relaxed text-muted-foreground",children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:"Not enforced — paused."})," Enforcement was suspended for this session","cli"===e.pausedBy?" from the CLI":` by ${e.pausedBy}`,s?`, lifting at ${s}`:"",". Builtin, custom and convention policies did not run for this event; cloud-managed policies did."]})]})}let _=(0,y.createServerReference)("002046304e29604aa8cbf7a705a0b0cb10f0107bc7",y.callServer,void 0,y.findSourceMapURL,"getHooksConfigAction"),T=(0,y.createServerReference)("6023f1edb44d2c59d885e2e29ae3c64b0eb8b99b61",y.callServer,void 0,y.findSourceMapURL,"toggleCustomPolicyAction"),U=(0,y.createServerReference)("00f1ecba9174304fbb93569d0e033f4865066292d7",y.callServer,void 0,y.findSourceMapURL,"addBundledPackWebAction"),I=(0,y.createServerReference)("60108624130001bc9dbf4e8e1307141c56159c5492",y.callServer,void 0,y.findSourceMapURL,"addPackWebAction"),R=(0,y.createServerReference)("40766af94e91a9f1d1f24968f7850bef9a5da8d317",y.callServer,void 0,y.findSourceMapURL,"previewPackWebAction"),$=(0,y.createServerReference)("40e72f2550f56a9e5c364f2c27d7e229f1f0a2a32c",y.callServer,void 0,y.findSourceMapURL,"removePackWebAction"),A=(0,y.createServerReference)("70194e5b4e969564d6ba8cdb2daabce94e0cae2dc9",y.callServer,void 0,y.findSourceMapURL,"togglePackPolicyAction"),E=(0,y.createServerReference)("6094649d90331c3592c6f4b16824de045d7d0a8703",y.callServer,void 0,y.findSourceMapURL,"installHooksWebAction"),L=(0,y.createServerReference)("60ad20bb5532a5fa256d1cbbb15105439db610ae06",y.callServer,void 0,y.findSourceMapURL,"removeHooksWebAction"),M=(0,y.createServerReference)("600932e3f698a1881d8dd49848a1baa98eced6aa63",y.callServer,void 0,y.findSourceMapURL,"updatePolicyParamsAction");var B=e.i(85881),F=e.i(12344),z=e.i(80060),D=e.i(2711),W=e.i(24578);let H={claude:{PreToolUse:"block",UserPromptSubmit:"block",PermissionRequest:"block",Stop:"block",SubagentStop:"block",PreCompact:"block",PostToolBatch:"block",ConfigChange:"block",UserPromptExpansion:"block",TaskCreated:"block",TaskCompleted:"block",TeammateIdle:"block",Elicitation:"block",ElicitationResult:"block",PostToolUse:"observe",PostToolUseFailure:"observe",SessionStart:"observe",Setup:"observe",SubagentStart:"observe",SessionEnd:"observe",StopFailure:"observe",PermissionDenied:"observe",Notification:"observe",InstructionsLoaded:"observe",CwdChanged:"observe",FileChanged:"observe",PostCompact:"observe",WorktreeRemove:"observe"},codex:{PreToolUse:"block",PermissionRequest:"block",UserPromptSubmit:"block",Stop:"block",SubagentStop:"block",PostToolUse:"block",SessionStart:"observe",SubagentStart:"observe",PreCompact:"observe",PostCompact:"observe"},copilot:{PreToolUse:"block",Stop:"block",SubagentStop:"block",UserPromptSubmit:"block",PermissionRequest:"block",PostToolUse:"block",SessionStart:"observe",SessionEnd:"observe",PostToolUseFailure:"observe",PreCompact:"observe",Notification:"observe"},cursor:{PreToolUse:"block",Stop:"block",UserPromptSubmit:"block",PostToolUse:"observe",SessionStart:"observe",SessionEnd:"observe"},opencode:{PreToolUse:"block",PostToolUse:"observe",SessionStart:"observe",SessionEnd:"observe",UserPromptSubmit:"observe",PermissionRequest:"observe"},pi:{PreToolUse:"block",UserPromptSubmit:"block",PostToolUse:"observe",SessionStart:"observe",SessionEnd:"observe",Stop:"observe"},hermes:{PreToolUse:"block",PostToolUse:"observe",SubagentStop:"observe",SessionStart:"observe",SessionEnd:"observe"},openclaw:{PreToolUse:"block",UserPromptSubmit:"block",Stop:"block",PostToolUse:"observe",SessionStart:"observe",SessionEnd:"observe",SubagentStop:"observe",PreCompact:"observe"},factory:{PreToolUse:"block",UserPromptSubmit:"block",Stop:"block",PreCompact:"block",PostToolUse:"observe",SubagentStop:"observe",SessionStart:"observe",SessionEnd:"observe",Notification:"observe"},devin:{PreToolUse:"block",UserPromptSubmit:"block",Stop:"block",PermissionRequest:"block",PostToolUse:"observe",SessionStart:"observe",SessionEnd:"observe"},antigravity:{PreToolUse:"block",Stop:"block",PostToolUse:"observe",UserPromptSubmit:"observe"},goose:{PreToolUse:"block",UserPromptSubmit:"observe",PostToolUse:"observe",SessionStart:"observe",SessionEnd:"observe"}};var O=e.i(34713),q=e.i(67881);function X({sessionId:e,transcriptPath:s,integration:r,cwd:a}){if(!e)return(0,t.jsx)("span",{className:"text-muted-foreground",children:"\\u2014"});let o=e?e.slice(0,8):"—",l="codex"===r||(s?.includes("/.codex/")??!1),i="copilot"===r||(s?.includes("/.copilot/session-state/")??!1),c="cursor"===r||(s?.includes("/.cursor/")??!1),d="opencode"===r||(s?.includes("/.local/share/opencode/")??!1)||(s?.includes("/.opencode/")??!1),m="pi"===r||(s?.includes("/.pi/")??!1);if(l||i||c||d||m){let s,r=a?(s=/^([A-Za-z]):[\\/](.*)$/.exec(a))?s[1]+"--"+s[2].replace(/[\\/]/g,"-"):a.replace(/[\\/]/g,"-"):l?"codex":i?"copilot":c?"cursor":d?"opencode":"pi";return(0,t.jsx)(n.default,{href:`/project/${encodeURIComponent(r)}/session/${encodeURIComponent(e)}`,className:"text-primary hover:underline font-mono",onClick:e=>e.stopPropagation(),children:o})}let u=s?function(e){let t=e.replace(/\\/g,"/").split("/").filter(Boolean);if(t.length<2)return null;let s=t[t.length-2];return!s||s.startsWith(".")?null:s}(s):null;return u?(0,t.jsx)(n.default,{href:`/project/${encodeURIComponent(u)}/session/${encodeURIComponent(e)}`,className:"text-primary hover:underline font-mono",onClick:e=>e.stopPropagation(),children:o}):(0,t.jsx)("span",{className:"text-muted-foreground font-mono",children:o})}function K({decision:e}){return"deny"===e?(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[0.65rem] font-semibold tracking-wide uppercase bg-red-500/10 text-red-400 border border-red-500/20",children:[(0,t.jsx)(b.ShieldX,{className:"h-3 w-3"}),"Deny"]}):"instruct"===e?(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[0.65rem] font-semibold tracking-wide uppercase bg-amber-500/10 text-amber-400 border border-amber-500/20",children:[(0,t.jsx)(p.ShieldAlert,{className:"h-3 w-3"}),"Instruct"]}):(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[0.65rem] font-semibold tracking-wide uppercase bg-emerald-500/10 text-emerald-400 border border-emerald-500/20",children:[(0,t.jsx)(h.ShieldCheck,{className:"h-3 w-3"}),"Allow"]})}function V({eventType:e}){return(0,t.jsx)("span",{className:"inline-flex items-center rounded px-1.5 py-0.5 text-[0.6rem] font-medium bg-muted text-muted-foreground border border-border/50",children:e})}function J({integration:e}){if(!e)return null;let s=(0,W.getCliLabel)(e),r=(0,W.getCliBadgeClasses)(e);return(0,t.jsx)("span",{className:`inline-flex items-center rounded px-1.5 py-0.5 text-[0.6rem] font-medium border ${r}`,title:`Agent CLI: ${s}`,children:s})}function G({mode:e}){let s="default"===e;return(0,t.jsx)("span",{title:e,className:`inline-block max-w-full truncate rounded px-1.5 py-0.5 align-middle text-[0.6rem] font-medium border ${s?"bg-sky-500/10 text-sky-400 border-sky-500/20":"bg-amber-500/10 text-amber-400 border-amber-500/20"}`,children:e})}function Z({ms:e}){return(0,t.jsx)("span",{className:`font-mono text-[0.7rem] ${e>500?"text-red-400":e>100?"text-amber-400":"text-muted-foreground"}`,children:e<1e3?`${e}ms`:`${(e/1e3).toFixed(1)}s`})}function Q({text:e,field:r}){let[n,o]=(0,s.useState)(!1),{capture:l}=(0,F.usePostHog)(),i=async t=>{t.stopPropagation(),l("activity_copy_clicked",{field:r??"unknown"});try{await navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),1500)}catch{let t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),o(!0),setTimeout(()=>o(!1),1500)}};return(0,t.jsx)("button",{onClick:i,className:"inline-flex items-center justify-center h-5 w-5 rounded hover:bg-muted/50 text-muted-foreground hover:text-foreground transition-colors",title:"Copy",children:n?(0,t.jsx)(a.Check,{className:"h-3 w-3 text-emerald-400"}):(0,t.jsx)(c.Copy,{className:"h-3 w-3"})})}function Y({value:e,onChange:s}){return(0,t.jsx)("div",{className:"inline-flex items-center rounded-md border border-border bg-muted/30 p-0.5",children:[{label:"All",value:""},{label:"Allow",value:"allow"},{label:"Instruct",value:"instruct"},{label:"Deny",value:"deny"}].map(r=>(0,t.jsx)("button",{onClick:()=>s(r.value),className:`px-2.5 py-1 text-[0.65rem] font-medium rounded transition-all ${e===r.value?"deny"===r.value?"bg-red-500/15 text-red-400 shadow-sm":"allow"===r.value?"bg-emerald-500/15 text-emerald-400 shadow-sm":"instruct"===r.value?"bg-amber-500/15 text-amber-400 shadow-sm":"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:r.label},r.value))})}function ee({stats:e}){let s=e.totalEvents>0?e.denyCount/e.totalEvents*100:0,r=s.toFixed(s>=10?0:1),n=0===e.denyCount?"":s>=5?" is-deny":s>=2?" is-warn":"";return(0,t.jsxs)("div",{className:"stat-bar",role:"group","aria-label":"Activity stats",children:[(0,t.jsxs)("div",{className:"stat-cell",children:[(0,t.jsx)("span",{className:"eyebrow",children:"total events"}),(0,t.jsx)("span",{className:"value",children:e.totalEvents.toLocaleString()}),(0,t.jsx)("span",{className:"meta",children:"across all installed agents"})]}),(0,t.jsxs)("div",{className:"stat-cell",children:[(0,t.jsx)("span",{className:"eyebrow",children:"deny rate"}),(0,t.jsxs)("span",{className:`value${n}`,children:[r,"%"]}),(0,t.jsxs)("span",{className:"meta",children:[e.denyCount.toLocaleString()," of ",e.totalEvents.toLocaleString()," denied"]})]}),(0,t.jsxs)("div",{className:"stat-cell",children:[(0,t.jsx)("span",{className:"eyebrow",children:"top policy"}),(0,t.jsx)("span",{className:"value",style:{fontSize:16,fontWeight:500,color:e.topPolicy?"var(--accent-pink)":"var(--dim)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:e.topPolicy??void 0,children:e.topPolicy??"—"}),(0,t.jsx)("span",{className:"meta",children:"most-evaluated policy in scope"})]})]})}function et({item:e}){if("observe"!==function(e,t){if(!e||!t)return;let s=H[e];if(s)return s[t]}(e.integration,e.eventType))return null;let s=e.matchedPolicies??[];if(0===s.length)return null;let r=e.integration?(0,W.getCliLabel)(e.integration):"This CLI",n=s.map(e=>e.replace(/^(custom|\.failproofai-(project|user))\//,"")),a=1===n.length?n[0]:`${n.length} policies`,o="deny"===e.decision;return(0,t.jsxs)("div",{className:"sm:col-span-2 lg:col-span-3 mt-1 flex items-start gap-2 rounded border border-amber-500/30 bg-amber-500/5 px-2.5 py-2",children:[(0,t.jsx)(g,{className:"h-3.5 w-3.5 shrink-0 text-amber-500/80 mt-0.5","aria-hidden":"true"}),(0,t.jsxs)("p",{className:"text-[0.7rem] leading-relaxed text-muted-foreground",children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:o?"Not enforced.":"Ran, but cannot enforce here."})," ",(0,t.jsx)("span",{className:"font-mono",children:a})," ran on"," ",(0,t.jsx)("span",{className:"font-mono",children:e.eventType}),", but ",r," discards hook verdicts for this event",o?" — the action went ahead anyway.":", so a policy cannot block here."," ","Move the check to an event ",r," enforces on, such as"," ",(0,t.jsx)("span",{className:"font-mono",children:"PreToolUse"}),"."]})]})}function es({item:e}){return(0,t.jsx)("tr",{children:(0,t.jsx)("td",{colSpan:11,className:"px-0 py-0",children:(0,t.jsxs)("div",{className:"activity-detail animate-expand text-xs",children:[(0,t.jsxs)("span",{className:"activity-detail-eyebrow",children:[(0,t.jsx)("span",{"aria-hidden":"true",children:"▾"}),"event detail"]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-x-8 gap-y-2",children:[(0,t.jsx)(C,{item:e}),(0,t.jsx)(et,{item:e}),e.policySource&&(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Decided by: "}),(0,t.jsx)("span",{className:"font-mono text-foreground",children:"cloud"===e.policySource&&e.cloudPolicyId?`cloud \xb7 ${e.cloudPolicyId} version ${e.cloudVersion}`:e.policySource})]}),void 0!==e.cloudDeployment&&(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Cloud deployment: "}),(0,t.jsx)("span",{className:"font-mono text-foreground",children:e.cloudDeployment})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Session ID: "}),(0,t.jsx)("span",{className:"font-mono text-foreground",children:e.sessionId??"—"}),e.sessionId&&(0,t.jsx)(Q,{text:e.sessionId,field:"session_id"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"CWD: "}),(0,t.jsx)("span",{className:"font-mono text-foreground",children:e.cwd??"—"}),e.cwd&&(0,t.jsx)(Q,{text:e.cwd,field:"cwd"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Transcript: "}),(0,t.jsx)("span",{className:"font-mono text-foreground break-all",children:e.transcriptPath??"—"}),e.transcriptPath?.startsWith("opencode-db://")&&(0,t.jsx)("span",{className:"text-muted-foreground ml-1",children:"(stored in opencode DB)"})]})]}),e.policyNames&&e.policyNames.length>1&&(0,t.jsxs)("div",{style:{marginTop:8},children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Policies: "}),(0,t.jsx)("span",{className:"font-mono text-foreground",children:e.policyNames.join(", ")})]}),e.reason&&(0,t.jsxs)("div",{style:{marginTop:8},children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"Full reason: "}),(0,t.jsx)("span",{className:"text-foreground",children:e.reason})]})]})})})}function er({hooksInstalled:e,onSwitchTab:r}){let{intervalSec:n}=(0,B.useAutoRefresh)(),{capture:a}=(0,F.usePostHog)(),l=(0,z.useUrlParams)(),i=(0,s.useRef)(!1),[c,d]=(0,s.useState)(()=>(0,D.paramToPage)(l.get("page"))),[m,u]=(0,s.useState)(null),[p,h]=(0,s.useState)([]),[b,f]=(0,s.useState)(null),[g,v]=(0,s.useState)(()=>{let e=l.get("decision");return"allow"===e||"deny"===e||"instruct"===e?e:""}),[y,C]=(0,s.useState)(()=>l.get("event")??""),[_,T]=(0,s.useState)(()=>l.get("policy")??""),[U,I]=(0,s.useState)(()=>l.get("session")??""),[R,$]=(0,s.useState)(()=>{let e=l.get("cli");return(0,W.isKnownCli)(e)?e:""}),[A,E]=(0,s.useState)(()=>{let e=l.get("source");return"custom"===e||"convention"===e||"cloud"===e||"pack"===e?e:""}),L=(0,s.useRef)(null),M=(0,s.useRef)(!0),H=(0,s.useRef)({filterDecision:g,filterEventType:y,filterPolicy:_,filterSessionId:U,filterCli:R,filterSource:A});H.current={filterDecision:g,filterEventType:y,filterPolicy:_,filterSessionId:U,filterCli:R,filterSource:A},(0,s.useEffect)(()=>{if(!i.current){i.current=!0;return}l.setAll({decision:g||void 0,event:y||void 0,policy:_||void 0,session:U||void 0,cli:R||void 0,source:A||void 0,page:(0,D.pageToParam)(c)})},[g,y,_,U,R,A,c]);let q=""!==g||""!==y||""!==_||""!==U||""!==R||""!==A,Q=(0,s.useCallback)(async e=>{try{let t,{filterDecision:s,filterEventType:r,filterPolicy:n,filterSessionId:a,filterCli:o,filterSource:l}=H.current;t=""!==s||""!==r||""!==n||""!==a||""!==o||""!==l?await (0,k.searchHookActivityAction)({decision:s||void 0,eventType:r||void 0,policyName:n||void 0,sessionId:a||void 0,integration:o||void 0,source:l||void 0},e):await N(e),u(t)}catch{}},[]);(0,s.useEffect)(()=>{Q(c);let e=setInterval(()=>Q(c),n>0?1e3*n:5e3);return()=>clearInterval(e)},[c,Q,n]),(0,s.useEffect)(()=>{let e=!1,t=()=>{w().then(t=>{e||h(t)}).catch(()=>{})};t();let s=setInterval(t,n>0?1e3*n:5e3);return()=>{e=!0,clearInterval(s)}},[n]),(0,s.useEffect)(()=>(L.current&&clearTimeout(L.current),L.current=setTimeout(()=>{if(d(1),f(null),Q(1),M.current){M.current=!1;return}a("activity_filter_changed",{active_filter_count:+(""!==g)+ +(""!==y)+ +(""!==_)+ +(""!==U)+ +(""!==R),has_decision:""!==g,has_event_type:""!==y,has_policy:""!==_,has_session:""!==U,has_cli:""!==R,decision:g||null,event_type:y||null,cli:R||null})},300),()=>{L.current&&clearTimeout(L.current)}),[g,y,_,U,R]);let et=m?.entries??[],en=m?.totalPages??1;return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(S,{pauses:p}),m?.stats&&m.stats.totalEvents>0&&(0,t.jsx)("div",{style:{marginBottom:18},children:(0,t.jsx)(ee,{stats:m.stats})}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"filter-bar",children:[(0,t.jsxs)("div",{className:"filter-group",children:[(0,t.jsx)("span",{className:"filter-label",children:"decision"}),(0,t.jsx)(Y,{value:g,onChange:v})]}),(0,t.jsxs)("div",{className:"filter-group",children:[(0,t.jsx)("span",{className:"filter-label",children:"event"}),(0,t.jsxs)("select",{value:y,onChange:e=>C(e.target.value),className:"filter-input",children:[(0,t.jsx)("option",{value:"",children:"all events"}),(0,t.jsx)("option",{value:"PreToolUse",children:"PreToolUse"}),(0,t.jsx)("option",{value:"PostToolUse",children:"PostToolUse"}),(0,t.jsx)("option",{value:"SessionStart",children:"SessionStart"}),(0,t.jsx)("option",{value:"SessionEnd",children:"SessionEnd"}),(0,t.jsx)("option",{value:"UserPromptSubmit",children:"UserPromptSubmit"}),(0,t.jsx)("option",{value:"PermissionRequest",children:"PermissionRequest"})]})]}),(0,t.jsxs)("div",{className:"filter-group",children:[(0,t.jsx)("span",{className:"filter-label",children:"source"}),(0,t.jsxs)("select",{value:A,onChange:e=>{let t=e.target.value;E("custom"===t||"convention"===t||"cloud"===t||"pack"===t?t:"")},className:"filter-input","aria-label":"Filter by policy source",children:[(0,t.jsx)("option",{value:"",children:"all sources"}),(0,t.jsx)("option",{value:"custom",children:"custom"}),(0,t.jsx)("option",{value:"convention",children:"convention"}),(0,t.jsx)("option",{value:"cloud",children:"cloud"}),(0,t.jsx)("option",{value:"pack",children:"pack"})]})]}),(0,t.jsxs)("div",{className:"filter-group",children:[(0,t.jsx)("span",{className:"filter-label",children:"cli"}),(0,t.jsxs)("select",{value:R,onChange:e=>{let t=e.target.value;$(""===t||(0,W.isKnownCli)(t)?t:"")},className:"filter-input","aria-label":"Filter by CLI",children:[(0,t.jsx)("option",{value:"",children:"all clis"}),W.KNOWN_CLI_IDS.map(e=>(0,t.jsx)("option",{value:e,children:(0,W.getCliLabel)(e)},e))]})]}),(0,t.jsxs)("div",{className:"filter-group filter-group--grow",children:[(0,t.jsx)("span",{className:"filter-label",children:"policy"}),(0,t.jsx)("input",{type:"text",value:_,onChange:e=>T(e.target.value),placeholder:"filter by policy…",className:"filter-input"})]}),(0,t.jsxs)("div",{className:"filter-group filter-group--grow",children:[(0,t.jsx)("span",{className:"filter-label",children:"session"}),(0,t.jsx)("input",{type:"text",value:U,onChange:e=>I(e.target.value),placeholder:"filter by session…",className:"filter-input"})]}),q&&(0,t.jsx)("button",{type:"button",className:"filter-clear",onClick:()=>{v(""),C(""),$(""),T(""),I(""),E("")},"aria-label":"Clear all filters",children:"[ clear ]"})]}),0===et.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 px-4 text-center",children:[(0,t.jsx)(x.Shield,{className:"h-12 w-12 text-muted-foreground/30"}),!1===e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-4 font-medium",children:"Policies are not installed"}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground mt-1 max-w-sm",children:["Go to the"," ",(0,t.jsx)("button",{className:"underline hover:text-foreground transition-colors",onClick:()=>r?.("policies"),children:"Policies tab"})," ","and click ",(0,t.jsx)("span",{className:"font-mono bg-muted px-1 rounded",children:"Install"})," to enable policy monitoring."]})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-4",children:q?"No matching activity.":"Waiting for hook events…"})]}):(0,t.jsx)("div",{className:"overflow-x-auto activity-table-wrap",children:(0,t.jsxs)("table",{className:"w-full text-xs activity-table",style:{tableLayout:"fixed"},children:[(0,t.jsxs)("colgroup",{children:[(0,t.jsx)("col",{style:{width:32}}),(0,t.jsx)("col",{style:{width:"7%"}}),(0,t.jsx)("col",{style:{width:"9%"}}),(0,t.jsx)("col",{style:{width:"12%"}}),(0,t.jsx)("col",{style:{width:"11%"}}),(0,t.jsx)("col",{style:{width:"9%"}}),(0,t.jsx)("col",{style:{width:"13%"}}),(0,t.jsx)("col",{style:{width:"12%"}}),(0,t.jsx)("col",{style:{width:"11%"}}),(0,t.jsx)("col",{style:{width:"8%"}}),(0,t.jsx)("col",{style:{width:"8%"}})]}),(0,t.jsx)("thead",{className:"activity-thead",children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{className:"px-4 py-3"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Time"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Decision"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Event"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"CLI"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Tool"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Policy"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Reason"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Mode"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Duration"}),(0,t.jsx)("th",{className:"px-3 py-3 activity-th",children:"Session"})]})}),(0,t.jsx)("tbody",{className:"divide-y divide-border/30",children:et.map((e,r)=>{let n="deny"===e.decision,l=b===r,i="instruct"===e.decision;return(0,t.jsxs)(s.Fragment,{children:[(0,t.jsxs)("tr",{onClick:()=>{f(e=>{let t=e===r?null:r,s=et[r];return a("activity_row_toggled",{expanded:null!==t,decision:s?.decision??null,policy_name:s?.policyName??null,event_type:s?.eventType??null}),t})},className:`activity-data-row cursor-pointer transition-colors ${n?"bg-red-500/[0.03] hover:bg-red-500/[0.07] border-l-2 border-l-red-500/40":i?"bg-amber-500/[0.03] hover:bg-amber-500/[0.07] border-l-2 border-l-amber-500/40":r%2==0?"hover:bg-muted/30":"bg-muted/[0.04] hover:bg-muted/30"} ${l?"bg-muted/20":""}`,children:[(0,t.jsx)("td",{className:"px-4 py-2",children:(0,t.jsx)(o.ChevronDown,{className:`h-3.5 w-3.5 text-muted-foreground transition-transform duration-150 ${l?"rotate-0":"-rotate-90"}`})}),(0,t.jsx)("td",{className:"px-3 py-2 text-muted-foreground whitespace-nowrap",title:new Date(e.timestamp).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}),children:(0,O.formatRelativeTime)(e.timestamp)}),(0,t.jsxs)("td",{className:"px-3 py-2",children:[(0,t.jsx)(K,{decision:e.decision}),e.pausedBy&&(0,t.jsx)(P,{})]}),(0,t.jsx)("td",{className:"px-3 py-2",children:(0,t.jsx)(V,{eventType:e.eventType})}),(0,t.jsx)("td",{className:"px-3 py-2",children:(0,t.jsx)(J,{integration:e.integration})}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:e.toolName??"—"}),(0,t.jsx)("td",{className:"px-3 py-2 font-mono text-foreground",children:e.policyNames&&e.policyNames.length>1?(0,t.jsxs)("span",{title:e.policyNames.join(", "),children:[e.policyNames[0],(0,t.jsxs)("span",{className:"text-muted-foreground text-[0.6rem]",children:[" +",e.policyNames.length-1]})]}):e.policyName??"—"}),(0,t.jsx)("td",{className:"px-3 py-2 text-muted-foreground truncate",title:e.reason??"",children:e.reason??"—"}),(0,t.jsx)("td",{className:"px-3 py-2",children:e.permissionMode?(0,t.jsx)(G,{mode:e.permissionMode}):"—"}),(0,t.jsx)("td",{className:"px-3 py-2",children:(0,t.jsx)(Z,{ms:e.durationMs})}),(0,t.jsx)("td",{className:"px-3 py-2",title:e.sessionId??"",children:(0,t.jsx)(X,{sessionId:e.sessionId,transcriptPath:e.transcriptPath,integration:e.integration,cwd:e.cwd})})]}),l&&(0,t.jsx)(es,{item:e})]},`${e.timestamp}-${r}`)})})]})}),(0,t.jsx)(j.default,{currentPage:c,totalPages:en,onPageChange:e=>{a("activity_pagination_changed",{from_page:c,to_page:e,total_pages:en}),d(e),f(null)}})]})]})}function en({enabled:e,onChange:s,disabled:r}){return(0,t.jsx)("button",{onClick:s,disabled:r,className:`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors disabled:opacity-40 ${e?"bg-emerald-500":"bg-muted-foreground/30"}`,"aria-label":e?"Disable policy":"Enable policy",children:(0,t.jsx)("span",{className:`inline-block h-3 w-3 rounded-full bg-white shadow transition-transform ${e?"translate-x-3.5":"translate-x-0.5"}`})})}function ea({policy:e,onClose:r,onSave:n}){let a=e.params??{},o=e.currentParams??{},[l,i]=(0,s.useState)(()=>{let e={};for(let[t,s]of Object.entries(a)){let r=t in o?o[t]:s.default;e[t]=r}return e});(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[r]);let c=(e,t)=>{i(s=>({...s,[e]:t}))};return(0,t.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:e=>{e.target===e.currentTarget&&r()},children:(0,t.jsxs)("div",{className:"bg-card border border-border rounded-lg shadow-xl w-full max-w-lg mx-4 max-h-[80vh] flex flex-col",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-mono font-semibold text-foreground",children:e.name}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:e.description})]}),(0,t.jsx)("button",{onClick:r,className:"text-muted-foreground hover:text-foreground transition-colors",children:(0,t.jsx)(v.X,{className:"h-4 w-4"})})]}),(0,t.jsx)("div",{className:"overflow-y-auto flex-1 px-4 py-4 space-y-4",children:Object.entries(a).map(([e,s])=>(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-xs font-semibold text-foreground mb-1 font-mono",children:e}),(0,t.jsx)("p",{className:"text-[0.65rem] text-muted-foreground mb-1.5",children:s.description}),((e,s)=>{let r=l[e];if("boolean"===s.type)return(0,t.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,t.jsx)("input",{type:"checkbox",checked:!!r,onChange:t=>c(e,t.target.checked),className:"rounded border-border"}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:s.description})]});if("number"===s.type)return(0,t.jsx)("input",{type:"number",value:"number"==typeof r?r:"",onChange:t=>c(e,Number(t.target.value)),className:"w-full h-7 rounded border border-border bg-background px-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-primary/40"});if("string[]"===s.type){let s=Array.isArray(r)?r.join("\n"):"";return(0,t.jsx)("textarea",{value:s,onChange:t=>c(e,t.target.value.split("\n").filter(e=>""!==e.trim())),rows:4,placeholder:"One entry per line",className:"w-full rounded border border-border bg-background px-2 py-1.5 text-xs text-foreground font-mono focus:outline-none focus:ring-2 focus:ring-primary/40 resize-y"})}if("pattern[]"===s.type){let s=Array.isArray(r)?r:[];return(0,t.jsxs)("div",{className:"space-y-1.5",children:[s.map((r,n)=>(0,t.jsxs)("div",{className:"flex gap-1.5 items-center",children:[(0,t.jsx)("input",{type:"text",value:r.regex,onChange:t=>{let r=[...s];r[n]={...r[n],regex:t.target.value},c(e,r)},placeholder:"regex",className:"flex-1 h-6 rounded border border-border bg-background px-2 text-xs font-mono focus:outline-none focus:ring-2 focus:ring-primary/40"}),(0,t.jsx)("input",{type:"text",value:r.label,onChange:t=>{let r=[...s];r[n]={...r[n],label:t.target.value},c(e,r)},placeholder:"label",className:"flex-1 h-6 rounded border border-border bg-background px-2 text-xs focus:outline-none focus:ring-2 focus:ring-primary/40"}),(0,t.jsx)("button",{onClick:()=>c(e,s.filter((e,t)=>t!==n)),className:"text-muted-foreground/50 hover:text-destructive transition-colors",children:(0,t.jsx)(v.X,{className:"h-3.5 w-3.5"})})]},n)),(0,t.jsx)("button",{onClick:()=>c(e,[...s,{regex:"",label:""}]),className:"text-xs text-primary hover:underline",children:"+ Add pattern"})]})}return(0,t.jsx)("input",{type:"text",value:"string"==typeof r?r:"",onChange:t=>c(e,t.target.value),className:"w-full h-7 rounded border border-border bg-background px-2 text-xs text-foreground focus:outline-none focus:ring-2 focus:ring-primary/40"})})(e,s)]},e))}),(0,t.jsxs)("div",{className:"flex items-center justify-end gap-2 px-4 py-3 border-t border-border",children:[(0,t.jsx)(q.Button,{variant:"outline",size:"sm",onClick:r,className:"h-7 text-xs",children:"Cancel"}),(0,t.jsx)(q.Button,{size:"sm",onClick:()=>n(l),className:"h-7 text-xs",children:"Save"})]})]})})}function eo({message:e,onDismiss:s,onInstall:n,isPending:a}){let{capture:o}=(0,F.usePostHog)();return(0,r.createPortal)((0,t.jsxs)("div",{className:"fixed top-4 right-4 z-[9999] w-full max-w-sm",style:{animation:"slideInFromRight 0.25s ease-out"},children:[(0,t.jsx)("style",{children:`
2
- @keyframes slideInFromRight {
3
- from { transform: translateX(calc(100% + 1rem)); opacity: 0; }
4
- to { transform: translateX(0); opacity: 1; }
5
- }
6
- `}),(0,t.jsxs)("div",{className:"rounded-lg border border-red-500/40 bg-red-950/95 shadow-2xl shadow-red-900/40 overflow-hidden backdrop-blur-sm",children:[(0,t.jsx)("div",{className:"h-0.5 w-full bg-gradient-to-r from-red-600 via-red-400 to-red-600"}),(0,t.jsxs)("div",{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("div",{className:"shrink-0 mt-0.5 flex h-5 w-5 items-center justify-center rounded-full bg-red-500 ring-2 ring-red-500/30",children:(0,t.jsx)(v.X,{className:"h-3 w-3 text-white",strokeWidth:3})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-[0.65rem] font-bold uppercase tracking-widest text-red-400 mb-0.5",children:"Error"}),(0,t.jsx)("p",{className:"text-sm text-red-100 leading-snug",children:e})]}),(0,t.jsx)("button",{onClick:s,className:"shrink-0 -mt-0.5 -mr-0.5 rounded p-0.5 text-red-400/60 transition-colors hover:bg-red-500/20 hover:text-red-200","aria-label":"Dismiss",children:(0,t.jsx)(v.X,{className:"h-4 w-4"})})]}),(0,t.jsxs)("div",{className:"mt-3 flex gap-2",children:[(0,t.jsx)(q.Button,{size:"sm",onClick:()=>{o("hooks_install_from_error_clicked",{error_message:e.slice(0,200)}),s(),n()},disabled:a,className:"h-7 flex-1 border-0 bg-red-500 px-3 text-xs font-semibold text-white hover:bg-red-400 disabled:opacity-50",children:"Install hooks"}),(0,t.jsx)(q.Button,{variant:"ghost",size:"sm",onClick:s,className:"h-7 px-3 text-xs text-red-400 hover:bg-red-500/10 hover:text-red-200",children:"Dismiss"})]})]})]})]}),document.body)}function el({onHooksInstallChange:e}){let[r,n]=(0,s.useState)(null),[a,o]=(0,s.useTransition)(),[l,c]=(0,s.useState)(null),[d,m]=(0,s.useState)(null),[p,h]=(0,s.useState)(null),[b,f]=(0,s.useState)(()=>new Set),g=(0,s.useRef)(!1),{capture:v}=(0,F.usePostHog)(),j=(0,s.useCallback)((e,t)=>{v("action_error_displayed",{error_type:e,error_message:t.slice(0,200)}),c(t)},[v]),y=(0,s.useCallback)(async()=>{try{let t=await _();n(t),e?.(t.clis.some(e=>e.installed))}catch{}},[e]);(0,s.useEffect)(()=>{y()},[y]),(0,s.useEffect)(()=>{r&&(g.current?f(new Set(r.clis.filter(e=>e.installed).map(e=>e.id))):(g.current=!0,f(new Set(r.clis.filter(e=>e.installed||e.detected).map(e=>e.id)))))},[r?.clis]);let N=(0,s.useMemo)(()=>new Set((r?.clis??[]).filter(e=>e.installed).map(e=>e.id)),[r?.clis]),k=(0,s.useMemo)(()=>{let e=[],t=[];for(let s of r?.clis??[]){let r=b.has(s.id);r&&!N.has(s.id)&&e.push(s.id),!r&&N.has(s.id)&&t.push(s.id)}return{toInstall:e,toRemove:t}},[r?.clis,b,N]),w=k.toInstall.length>0||k.toRemove.length>0,S=(e,t)=>{r&&(n(s=>s?{...s,customPolicies:s.customPolicies?.map(s=>s.id===e?{...s,enabled:!t}:s),conventionPolicies:s.conventionPolicies.map(s=>({...s,policies:s.policies.map(s=>s.id===e?{...s,enabled:!t}:s)}))}:s),o(async()=>{try{await T(e,!t)}catch{j("custom_policy_toggle","Failed to save custom policy change."),y()}}))},P=()=>{let{toInstall:e,toRemove:t}=k;(0!==e.length||0!==t.length)&&(v("cli_install_remove_submitted",{to_install:e,to_remove:t,count_install:e.length,count_remove:t.length}),o(async()=>{try{c(null),e.length>0&&await E("user",e),t.length>0&&await L("user",t)}catch(e){j("cli_apply",e instanceof Error?e.message:"Failed to apply changes.")}finally{await y()}}))};if(!r)return(0,t.jsx)("div",{className:"flex items-center justify-center py-16",children:(0,t.jsxs)("span",{className:"text-sm text-muted-foreground",children:["Loading","…"]})});let C=r.clis.some(e=>e.installed),U=N.size,I=b.size,R=Array.from(new Set(r.policies.map(e=>e.category)));return(0,t.jsxs)(t.Fragment,{children:[p&&(0,t.jsx)(ea,{policy:p,onClose:()=>{v("policy_config_modal_closed",{policy_name:p.name,action:"cancel"}),h(null)},onSave:e=>{if(!p)return;let t=p.name;h(null),o(async()=>{try{c(null),await M(t,e),await y()}catch(e){j("param_update",e instanceof Error?e.message:"Failed to save configuration.")}})}}),(0,t.jsxs)("div",{className:"bg-card border border-border rounded-lg overflow-hidden",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-4 px-5 py-3.5 border-b border-border/60 bg-muted/10",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 min-w-0 flex-wrap",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:`h-2 w-2 rounded-full transition-shadow ${C?"bg-emerald-400 shadow-[0_0_8px_rgba(52,211,153,0.6)]":"bg-muted-foreground/40"}`,"aria-hidden":!0}),(0,t.jsx)("span",{className:"text-[0.65rem] uppercase tracking-[0.2em] font-mono text-foreground/90",children:"Integrations"})]}),(0,t.jsx)("span",{className:"text-[0.65rem] font-mono text-muted-foreground/40",children:"·"}),(0,t.jsxs)("div",{className:"text-[0.65rem] uppercase tracking-[0.2em] font-mono text-muted-foreground",children:[(0,t.jsx)("span",{className:"text-foreground tabular-nums",children:U.toString().padStart(2,"0")}),(0,t.jsxs)("span",{className:"opacity-50",children:[" / 0",r.clis.length," active"]})]}),w&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"text-[0.65rem] font-mono text-muted-foreground/40",children:"·"}),(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-[0.65rem] uppercase tracking-[0.2em] font-mono text-pink-400",children:[(0,t.jsx)("span",{className:"h-1 w-1 rounded-full bg-pink-400 animate-pulse"}),k.toInstall.length+k.toRemove.length," pending"]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 shrink-0",children:[(0,t.jsx)(q.Button,{variant:"outline",size:"sm",onClick:()=>{let e=Array.from(N).filter(e=>b.has(e));0!==e.length&&(v("cli_reinstall_submitted",{cli_ids:e,count:e.length}),o(async()=>{try{c(null),await E("user",e)}catch(e){j("cli_reinstall",e instanceof Error?e.message:"Failed to reinstall.")}finally{await y()}}))},disabled:a||0===I,className:"text-xs h-7 px-3 font-mono",children:"Reinstall"}),(0,t.jsx)(q.Button,{variant:"default",size:"sm",onClick:P,disabled:a||!w,className:"text-xs h-7 px-3 font-mono",children:"Apply changes"})]})]}),(0,t.jsx)("div",{className:"divide-y divide-border/30 border-b border-border/60",children:r.clis.map((e,s)=>{let n=b.has(e.id),o=N.has(e.id),l=n!==o,i=(0,W.getCliBadgeClasses)(e.id),c=i.split(" ").find(e=>e.startsWith("text-"))??"text-foreground";return(0,t.jsxs)("label",{className:`group relative flex items-center gap-3 pl-6 pr-5 py-3 cursor-pointer transition-colors hover:bg-muted/15 ${l?"bg-pink-500/[0.04]":""}`,children:[(0,t.jsx)("div",{className:`absolute left-0 top-0 bottom-0 w-[3px] ${c} bg-current transition-opacity ${n?"opacity-100":"opacity-25 group-hover:opacity-60"}`,"aria-hidden":!0}),(0,t.jsx)("div",{className:"font-mono text-[0.65rem] text-muted-foreground/40 tabular-nums w-6 select-none",children:(s+1).toString().padStart(2,"0")}),(0,t.jsxs)("div",{className:"relative shrink-0",children:[(0,t.jsx)("input",{type:"checkbox",checked:n,onChange:()=>{var t;return t=e.id,void f(e=>{let s=new Set(e),n=!s.has(t);n?s.add(t):s.delete(t);let a=r?.clis.find(e=>e.id===t);return v("cli_selection_toggled",{cli_id:t,checked:n,current_state:a?.installed?"installed":a?.detected?"detected":"inactive"}),s})},disabled:a,className:"sr-only peer","aria-label":`Toggle ${e.label}`}),(0,t.jsx)("div",{className:`h-[18px] w-[18px] rounded-sm border transition-all peer-focus-visible:ring-2 peer-focus-visible:ring-primary/40 ${n?"bg-primary border-primary":"bg-background/50 border-border group-hover:border-foreground/40"}`,children:n&&(0,t.jsx)("svg",{viewBox:"0 0 18 18",className:"h-full w-full text-primary-foreground",fill:"none","aria-hidden":!0,children:(0,t.jsx)("path",{d:"M4 9.5L7.5 12.5L14 6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),(0,t.jsx)("div",{className:"min-w-[150px] shrink-0",children:(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:e.label})}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0",children:[o?(0,t.jsxs)("span",{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-sm text-[0.6rem] uppercase tracking-[0.15em] font-mono border ${i}`,children:[(0,t.jsx)("span",{className:"h-1 w-1 rounded-full bg-current shadow-[0_0_4px_currentColor]"}),"Active"]}):e.detected?(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-sm text-[0.6rem] uppercase tracking-[0.15em] font-mono border border-border/60 text-muted-foreground/80 bg-muted/20",children:[(0,t.jsx)("span",{className:"h-1 w-1 rounded-full bg-current opacity-60"}),"Detected"]}):(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-sm text-[0.6rem] uppercase tracking-[0.15em] font-mono border border-border/30 text-muted-foreground/40",children:"Inactive"}),l&&(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-sm text-[0.6rem] uppercase tracking-[0.15em] font-mono border border-pink-500/40 text-pink-400 bg-pink-500/10",children:n?"+ install":"− remove"})]}),(0,t.jsx)("div",{className:"ml-auto hidden lg:block text-[0.7rem] font-mono text-muted-foreground/50 truncate max-w-[420px] group-hover:text-muted-foreground/80 transition-colors",title:e.settingsPath,children:e.settingsPath})]},e.id)})}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-b border-border/40 bg-muted/5",children:[(0,t.jsxs)("span",{className:"text-xs text-muted-foreground",children:[(0,t.jsx)("span",{className:"font-semibold text-foreground",children:r.policies.filter(e=>e.enabled).length+(r.customPolicies?.filter(e=>e.enabled).length??0)+(r.conventionPolicies?.reduce((e,t)=>e+t.policies.filter(e=>e.enabled).length,0)??0)})," / ",r.policies.length+(r.customPolicies?.length??0)+(r.conventionPolicies?.reduce((e,t)=>e+t.policies.length,0)??0)," ","policies enabled"]}),C&&(0,t.jsxs)("span",{className:"text-[0.65rem] text-muted-foreground/60",children:["· shared across ",U," active CLI",1===U?"":"s"]})]}),l&&(0,t.jsx)("div",{className:"px-4 py-2 bg-red-500/10 border-b border-red-500/20 text-xs text-red-400",children:l}),d&&(0,t.jsx)(eo,{message:d,onDismiss:()=>m(null),onInstall:P,isPending:a}),R.map(e=>{let s=r.policies.filter(t=>t.category===e),l=s.filter(e=>e.enabled).length;return(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 bg-muted/20 border-b border-border/50",children:[(0,t.jsx)("span",{className:"text-[0.7rem] font-semibold uppercase tracking-wider text-muted-foreground",children:e}),(0,t.jsxs)("span",{className:"text-[0.7rem] text-muted-foreground",children:[l," / ",s.length," enabled"]})]}),s.map(e=>(0,t.jsxs)("div",{className:"flex items-start gap-3 px-4 py-3 border-b border-border/20 hover:bg-muted/20 transition-colors",children:[(0,t.jsx)("div",{className:"mt-0.5 shrink-0",children:(0,t.jsx)(en,{enabled:e.enabled,onChange:()=>{var t;let s;return t=e.enabled,s=e.name,void(!r||(!r.clis.some(e=>e.installed)?m("Policies are not installed. Install policies to continue."):(m(null),n(r=>r?{...r,policies:r.policies.map(e=>e.name===s?{...e,enabled:!t}:e),packs:r.packs.map(r=>r.id===e.packId?{...r,policies:r.policies.map(e=>e.name===s?{...e,enabled:!t}:e)}:r)}:r),o(async()=>{try{await A(e.packId,s,!t)}catch{j("policy_toggle","Failed to save policy change."),y()}}))))},disabled:a})}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 min-w-0 w-56 shrink-0 mt-0.5",children:[(0,t.jsx)("span",{className:"text-xs font-mono text-foreground truncate",children:e.name}),e.beta&&(0,t.jsx)("span",{className:"shrink-0 text-[0.6rem] px-1 py-0.5 rounded border bg-violet-500/10 text-violet-400 border-violet-500/20",children:"beta"})]}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground leading-relaxed",children:e.description}),e.eventScope&&(0,t.jsx)("span",{className:"block text-[0.65rem] text-muted-foreground/40 font-mono mt-0.5 hidden lg:block",children:e.eventScope}),e.params&&Object.keys(e.params).length>0&&(0,t.jsx)("div",{className:"flex flex-wrap gap-1 mt-1.5",children:Object.entries(e.params).map(([s,r])=>{let n=e.currentParams?.[s]??r.default,a=JSON.stringify(n)!==JSON.stringify(r.default);return(0,t.jsxs)("span",{className:`inline-flex items-center gap-1 font-mono text-[0.6rem] px-1.5 py-0.5 rounded border ${a?"bg-primary/10 text-primary/70 border-primary/20":"bg-muted/40 text-muted-foreground/55 border-border/40"}`,children:[(0,t.jsxs)("span",{className:"opacity-70",children:[s,":"]}),(0,t.jsx)("span",{children:function(e,t){if("string[]"===e||"pattern[]"===e){let s=Array.isArray(t)?t:[];return 0===s.length?"none":"pattern[]"===e?`${s.length} pattern${1!==s.length?"s":""}`:1===s.length?String(s[0]).slice(0,24):`${s.length} values`}return"boolean"===e?t?"on":"off":null==t||""===t?"—":String(t).slice(0,32)}(r.type,n)})]},s)})})]}),e.params&&Object.keys(e.params).length>0&&(0,t.jsx)("button",{className:"shrink-0 mt-0.5 text-muted-foreground hover:text-primary transition-colors",onClick:()=>{let t=Object.entries(e.params??{}).filter(([t,s])=>JSON.stringify(e.currentParams?.[t]??s.default)!==JSON.stringify(s.default)).length;v("policy_config_modal_opened",{policy_name:e.name,param_count:Object.keys(e.params??{}).length,has_customized_params:t>0,customized_count:t}),h(e)},title:"Edit parameters",children:(0,t.jsx)(u.Settings,{className:"h-3.5 w-3.5"})})]},e.name))]},e)}),(r.customPoliciesPaths?.length||r.customPoliciesPath)&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 bg-muted/20 border-b border-border/50",children:[(0,t.jsx)("span",{className:"text-[0.7rem] font-semibold uppercase tracking-wider text-muted-foreground",children:"Custom Policies"}),(0,t.jsxs)("span",{className:"text-[0.7rem] text-muted-foreground",children:[r.customPolicies?.length??0," detected"]})]}),(r.customPoliciesPaths??[r.customPoliciesPath]).map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/20",children:[(0,t.jsx)(i,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e})]},e)),(0,t.jsxs)("div",{className:"flex items-start gap-2 px-4 py-2.5 border-b border-border/20 bg-muted/10",children:[(0,t.jsx)(x.Shield,{className:"h-3.5 w-3.5 text-muted-foreground/60 shrink-0 mt-0.5"}),(0,t.jsx)("p",{className:"text-[0.7rem] text-muted-foreground/70 leading-relaxed",children:"Re-run the install command to add, remove, or reorder files."})]}),r.customPolicies?.map(e=>(0,t.jsxs)("div",{className:"flex items-start gap-3 px-4 py-3 border-b border-border/20 hover:bg-muted/20 transition-colors",children:[(0,t.jsx)("div",{className:"mt-0.5 shrink-0",children:(0,t.jsx)(en,{enabled:e.enabled,onChange:()=>S(e.id,e.enabled),disabled:a})}),(0,t.jsx)("div",{className:"flex items-center gap-1.5 min-w-0 w-56 shrink-0 mt-0.5",children:(0,t.jsx)("span",{className:"text-xs font-mono text-foreground truncate",children:e.name})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[e.description&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground leading-relaxed",children:e.description}),e.eventScope&&(0,t.jsx)("span",{className:"block text-[0.65rem] text-muted-foreground/40 font-mono mt-0.5 hidden lg:block",children:e.eventScope})]})]},e.id))]}),r.conventionPolicies?.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 bg-muted/20 border-b border-border/50",children:[(0,t.jsxs)("span",{className:"text-[0.7rem] font-semibold uppercase tracking-wider text-muted-foreground",children:["Convention Policies — ","project"===e.scope?"Project":"User"]}),(0,t.jsxs)("span",{className:"text-[0.7rem] text-muted-foreground",children:[e.policies.length," hook",1===e.policies.length?"":"s"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/20",children:[(0,t.jsx)(i,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsx)("span",{className:"text-xs font-mono text-muted-foreground truncate",children:e.path})]}),0===e.policies.length?(0,t.jsxs)("div",{className:"flex items-start gap-2 px-4 py-2.5 border-b border-border/20 bg-muted/10",children:[(0,t.jsx)(x.Shield,{className:"h-3.5 w-3.5 text-muted-foreground/60 shrink-0 mt-0.5"}),(0,t.jsxs)("p",{className:"text-[0.7rem] text-muted-foreground/70 leading-relaxed",children:["No policies could be read from this file. It is still loaded at runtime — run ",(0,t.jsx)("span",{className:"font-mono",children:"failproofai policies"})," to see what it registers."]})]}):e.policies.map(s=>(0,t.jsxs)("div",{className:"flex items-start gap-3 px-4 py-3 border-b border-border/20 hover:bg-muted/20 transition-colors",children:[(0,t.jsx)("div",{className:"mt-0.5 shrink-0",children:(0,t.jsx)(en,{enabled:s.enabled,onChange:()=>S(s.id,s.enabled),disabled:a})}),(0,t.jsx)("div",{className:"flex items-center gap-1.5 min-w-0 w-56 shrink-0 mt-0.5",children:(0,t.jsx)("span",{className:"text-xs font-mono text-foreground truncate",children:s.name})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[s.description&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground leading-relaxed",children:s.description}),s.eventScope&&(0,t.jsx)("span",{className:"block text-[0.65rem] text-muted-foreground/40 font-mono mt-0.5 hidden lg:block",children:s.eventScope})]})]},`${e.path}:${s.name}`))]},e.path)),(0,t.jsx)(ei,{packs:r.packs??[],disabled:a,onChanged:y,onError:e=>j("pack_action",e)})]})]})}function ei({packs:e,disabled:r,onChanged:n,onError:a}){let[o,l]=(0,s.useState)(""),[i,c]=(0,s.useState)(null),[u,x]=(0,s.useState)(null),[p,h]=(0,s.useState)(null),{capture:b}=(0,F.usePostHog)(),j=async()=>{if(o.trim()){c("preview"),h(null);try{let e=await R(o);if(!e.ok)return void a(e.error??"Could not read that pack.");h(e)}finally{c(null)}}},y=async(e,t)=>{c(e),x(null);try{let e=await t();if(!e.ok)return void a(e.error??"Could not install that pack.");x(e.version?`${e.id}@${e.version}`:e.id??null),l(""),n()}catch(e){a(e instanceof Error?e.message:"Could not install that pack.")}finally{c(null)}};return(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 bg-muted/20 border-b border-border/50",children:[(0,t.jsx)("span",{className:"text-[0.7rem] font-semibold uppercase tracking-wider text-muted-foreground",children:"Policy Packs"}),(0,t.jsx)("span",{className:"text-[0.7rem] text-muted-foreground",children:0===e.length?"none installed":`${e.length} installed`})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-4 py-3 border-b border-border/20",children:[(0,t.jsx)("input",{value:o,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&o.trim()&&!i&&(b("pack_install_submitted",{via:"input"}),y("input",()=>I(o)))},placeholder:"core · acme/ops · acme/ops@v1.2.0 · a release URL",spellCheck:!1,disabled:r||null!==i,className:"flex-1 min-w-[16rem] rounded-md border border-border/60 bg-background px-2.5 py-1.5 text-xs font-mono placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-ring disabled:opacity-50","aria-label":"Pack source"}),(0,t.jsx)(q.Button,{size:"sm",variant:"outline",disabled:r||null!==i||0===o.trim().length,onClick:()=>{b("pack_preview_submitted",{}),j()},children:"preview"===i?"Reading…":"Preview"}),(0,t.jsxs)(q.Button,{size:"sm",variant:"default",disabled:r||null!==i||0===o.trim().length,onClick:()=>{b("pack_install_submitted",{via:"button"}),y("input",()=>I(o))},children:[(0,t.jsx)(m,{className:"h-3.5 w-3.5"}),"input"===i?"Installing…":"Install"]})]}),p?.ok&&(0,t.jsxs)("div",{className:"border-b border-border/20 bg-muted/5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2.5",children:[(0,t.jsx)(d,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsxs)("span",{className:"text-xs font-mono text-foreground",children:[p.id,"@",p.version]}),(0,t.jsxs)("span",{className:"text-[0.7rem] text-muted-foreground",children:[p.policies?.length??0," policies ·"," ",p.policies?.filter(e=>e.defaultEnabled).length??0," on by default"]}),"observe"===p.effect&&(0,t.jsx)("span",{className:"text-[0.65rem] uppercase tracking-wider text-amber-500",children:"observes only"}),(0,t.jsx)("button",{onClick:()=>h(null),className:"ml-auto text-muted-foreground/60 hover:text-foreground","aria-label":"Close preview",children:(0,t.jsx)(v.X,{className:"h-3.5 w-3.5"})})]}),(0,t.jsx)("div",{className:"max-h-64 overflow-y-auto",children:p.policies?.map(e=>(0,t.jsxs)("div",{className:"flex items-start gap-3 px-4 py-2 border-t border-border/10",children:[(0,t.jsx)("span",{className:`text-[0.65rem] uppercase tracking-wider w-14 shrink-0 mt-0.5 ${e.defaultEnabled?"text-emerald-500":"text-muted-foreground/50"}`,children:e.defaultEnabled?"default":"opt-in"}),(0,t.jsx)("span",{className:"text-xs font-mono text-foreground w-56 shrink-0 truncate",children:e.name}),(0,t.jsxs)("span",{className:"text-xs text-muted-foreground leading-relaxed min-w-0",children:[e.description,(0,t.jsx)("span",{className:"block text-[0.65rem] text-muted-foreground/40 font-mono mt-0.5",children:e.category})]})]},e.name))}),(0,t.jsx)("div",{className:"px-4 py-2.5 border-t border-border/20",children:(0,t.jsxs)(q.Button,{size:"sm",variant:"default",disabled:r||null!==i,onClick:()=>{b("pack_install_submitted",{via:"preview"}),y("input",()=>I(o)).then(()=>h(null))},children:[(0,t.jsx)(m,{className:"h-3.5 w-3.5"}),"Install its defaults"]})})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-2 px-4 py-2.5 border-b border-border/20 bg-muted/10",children:[(0,t.jsx)("span",{className:"text-[0.7rem] text-muted-foreground/70 mr-1",children:"Failproof AI policies:"}),(0,t.jsx)(q.Button,{size:"sm",variant:"outline",disabled:r||null!==i,onClick:()=>{b("pack_install_submitted",{via:"ours"}),y("ours",()=>I("FailproofAI/policies"))},children:"ours"===i?"Installing…":"Install from GitHub"}),(0,t.jsx)(q.Button,{size:"sm",variant:"outline",disabled:r||null!==i,onClick:()=>{b("pack_install_submitted",{via:"bundled"}),y("bundled",()=>U())},children:"bundled"===i?"Installing…":"Install offline copy"}),u&&(0,t.jsxs)("span",{className:"text-[0.7rem] text-emerald-500 font-mono",children:["installed ",u]})]}),e.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 border-b border-border/20",children:[(0,t.jsx)(d,{className:"h-3.5 w-3.5 text-muted-foreground shrink-0"}),(0,t.jsxs)("span",{className:"text-xs font-mono text-foreground truncate",children:[e.id,e.version?`@${e.version}`:""]}),"observe"===e.effect&&(0,t.jsx)("span",{className:"text-[0.65rem] uppercase tracking-wider text-amber-500",children:"observing"}),(0,t.jsx)("span",{className:"text-[0.65rem] text-muted-foreground/50 font-mono truncate hidden lg:inline",children:e.source}),(0,t.jsx)("button",{onClick:()=>void y(e.id,()=>$(e.id)),disabled:r||null!==i,className:"ml-auto text-muted-foreground/60 hover:text-foreground disabled:opacity-40","aria-label":`Remove ${e.id}`,children:(0,t.jsx)(f,{className:"h-3.5 w-3.5"})})]}),e.error?(0,t.jsxs)("div",{className:"flex items-start gap-2 px-4 py-2.5 border-b border-border/20 bg-amber-500/5",children:[(0,t.jsx)(g,{className:"h-3.5 w-3.5 text-amber-500 shrink-0 mt-0.5"}),(0,t.jsxs)("p",{className:"text-[0.7rem] text-muted-foreground leading-relaxed",children:["This pack will not load: ",e.error]})]}):(0,t.jsx)("div",{className:"flex items-center gap-3 px-4 py-2.5 border-b border-border/20",children:(0,t.jsxs)("span",{className:"text-[0.7rem] text-muted-foreground",children:[e.policies.filter(e=>e.enabled).length," of ",e.policies.length," on — listed by category above"]})})]},`${e.id}@${e.version}`))]})}function ec({activeTab:e,onChange:s}){return(0,t.jsx)("div",{className:"tabs",style:{padding:0,marginBottom:24},children:[{id:"activity",label:"Activity"},{id:"policies",label:"Configure"}].map(r=>(0,t.jsx)("button",{type:"button",onClick:()=>s(r.id),className:`tab${e===r.id?" is-active":""}`,children:r.label.toLowerCase()},r.id))})}e.s(["default",0,function({initialTab:e="activity"}){let r=(0,z.useUrlParams)(),{capture:n}=(0,F.usePostHog)(),[a,o]=(0,s.useState)(e),[l,i]=(0,s.useState)(void 0),[c,d]=(0,s.useState)(null),[m,u]=(0,s.useState)([]);(0,s.useEffect)(()=>{_().then(e=>{i(e.clis.some(e=>e.installed)),d({enabled:e.enabledPolicies.length,total:e.policies.length+(e.customPolicies?.length??0)+(e.conventionPolicies?.reduce((e,t)=>e+t.policies.length,0)??0)}),u(e.clis.filter(e=>e.installed).map(e=>e.label))}).catch(()=>i(void 0))},[]);let x=0===m.length?"Policy evaluations":m.length<=3?`Policy evaluations across ${m.join(", ")}`:`Policy evaluations across ${m.length} agents`,p=e=>{e!==a&&n("policies_tab_switched",{tab:e,from_tab:a}),o(e),r.setAll({tab:"activity"===e?void 0:e})};return(0,t.jsx)("main",{className:"report",children:(0,t.jsxs)("section",{className:"section","data-screen-label":"policies",children:[(0,t.jsx)("h2",{style:{fontFamily:"var(--font-mono)",fontSize:24,fontWeight:600,letterSpacing:"-0.01em",color:"var(--ink)",margin:"0 0 16px"},children:"activity"===a?"Policies":"Configure Policies"}),"activity"===a?(0,t.jsxs)("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:32,flexWrap:"wrap",margin:"0 0 24px"},children:[(0,t.jsxs)("div",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--ink-2)",lineHeight:1.7,flex:"1 1 480px",minWidth:0},children:[x,c&&(0,t.jsxs)("span",{style:{color:"var(--dim)"},children:[" · ","enabled policies"," ",(0,t.jsxs)("span",{style:{color:"var(--ink)",fontVariantNumeric:"tabular-nums"},children:[c.enabled,"/",c.total]})]})]}),(0,t.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:6,flex:"0 0 auto"},children:[(0,t.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:10,letterSpacing:"0.22em",textTransform:"uppercase",color:"var(--dim)"},children:"want to change which policies fire?"}),(0,t.jsx)("button",{type:"button",className:"btn btn-primary",onClick:()=>p("policies"),children:"[ configure policies → ]"})]})]}):(0,t.jsx)("p",{style:{fontFamily:"var(--font-mono)",fontSize:14,color:"var(--ink-2)",lineHeight:1.7,maxWidth:720,margin:"0 0 24px"},children:"switch policies on or off across your installed harnesses."}),(0,t.jsx)(ec,{activeTab:a,onChange:p}),"activity"===a?(0,t.jsx)(er,{hooksInstalled:l,onSwitchTab:p}):(0,t.jsx)(el,{onHooksInstallChange:i})]})})}],64245)}]);