@lkangd/cc-env 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +15 -0
  2. package/dist/cli.js +68 -6
  3. package/dist/commands/completion.js +60 -0
  4. package/dist/commands/doctor.js +73 -0
  5. package/dist/commands/preset/edit.js +16 -11
  6. package/dist/commands/preset/rename.js +16 -0
  7. package/dist/commands/run.js +9 -1
  8. package/dist/ink/preset-edit-app.js +112 -0
  9. package/package.json +11 -2
  10. package/.claude/settings.json +0 -6
  11. package/.claude/settings.local.json +0 -8
  12. package/.nvmrc +0 -1
  13. package/CHANGELOG.md +0 -71
  14. package/docs/product-specs/index.draft.md +0 -106
  15. package/docs/product-specs/index.md +0 -911
  16. package/docs/product-specs/optional.md +0 -42
  17. package/docs/references/claude-code-env.md +0 -224
  18. package/docs/superpowers/plans/2026-04-24-cc-env-init-shell-migration.md +0 -1331
  19. package/docs/superpowers/plans/2026-04-24-cc-env.md +0 -1666
  20. package/docs/superpowers/plans/2026-04-26-preset-create-interactive-refactor.md +0 -1432
  21. package/docs/superpowers/specs/2026-04-24-cc-env-design.md +0 -438
  22. package/docs/superpowers/specs/2026-04-24-cc-env-init-shell-migration-design.md +0 -181
  23. package/docs/superpowers/specs/2026-04-26-preset-create-interactive-refactor-design.md +0 -78
  24. package/src/cli.ts +0 -340
  25. package/src/commands/init.ts +0 -139
  26. package/src/commands/preset/create.ts +0 -96
  27. package/src/commands/preset/delete.ts +0 -62
  28. package/src/commands/preset/show.ts +0 -51
  29. package/src/commands/restore.ts +0 -150
  30. package/src/commands/run.ts +0 -158
  31. package/src/core/errors.ts +0 -13
  32. package/src/core/find-claude.ts +0 -70
  33. package/src/core/format.ts +0 -29
  34. package/src/core/fs.ts +0 -18
  35. package/src/core/gitignore.ts +0 -26
  36. package/src/core/logger.ts +0 -11
  37. package/src/core/mask.ts +0 -17
  38. package/src/core/paths.ts +0 -41
  39. package/src/core/process-env.ts +0 -11
  40. package/src/core/schema.ts +0 -55
  41. package/src/core/spawn.ts +0 -36
  42. package/src/flows/init-flow.ts +0 -61
  43. package/src/flows/preset-create-flow.ts +0 -129
  44. package/src/flows/restore-flow.ts +0 -144
  45. package/src/ink/init-app.tsx +0 -110
  46. package/src/ink/preset-create-app.tsx +0 -451
  47. package/src/ink/preset-delete-app.tsx +0 -114
  48. package/src/ink/preset-show-app.tsx +0 -76
  49. package/src/ink/restore-app.tsx +0 -230
  50. package/src/ink/run-preset-select-app.tsx +0 -83
  51. package/src/ink/summary.tsx +0 -91
  52. package/src/services/claude-settings-env-service.ts +0 -72
  53. package/src/services/history-service.ts +0 -48
  54. package/src/services/preset-service.ts +0 -72
  55. package/src/services/project-env-service.ts +0 -128
  56. package/src/services/project-state-service.ts +0 -31
  57. package/src/services/settings-env-service.ts +0 -40
  58. package/src/services/shell-env-service.ts +0 -112
  59. package/src/types.d.ts +0 -19
  60. package/tests/cli/help.test.ts +0 -133
  61. package/tests/cli/init.test.ts +0 -76
  62. package/tests/cli/restore.test.ts +0 -172
  63. package/tests/commands/create.test.ts +0 -263
  64. package/tests/commands/output.test.ts +0 -119
  65. package/tests/commands/run.test.ts +0 -218
  66. package/tests/core/gitignore.test.ts +0 -98
  67. package/tests/core/paths.test.ts +0 -24
  68. package/tests/core/schema-mask.test.ts +0 -182
  69. package/tests/core/spawn.test.ts +0 -47
  70. package/tests/flows/init-flow.test.ts +0 -40
  71. package/tests/flows/preset-create-flow.test.ts +0 -225
  72. package/tests/flows/restore-flow.test.ts +0 -157
  73. package/tests/integration/init-restore.test.ts +0 -406
  74. package/tests/services/claude-shell.test.ts +0 -183
  75. package/tests/services/storage.test.ts +0 -143
  76. package/tsconfig.build.json +0 -9
  77. package/tsconfig.json +0 -22
  78. package/vitest.config.ts +0 -8
@@ -1,61 +0,0 @@
1
- export type InitFlowStep = 'keys' | 'confirm' | 'done'
2
-
3
- export type InitFlowState = {
4
- step: InitFlowStep
5
- availableKeys: string[]
6
- requiredKeys: string[]
7
- selectedKeys: string[]
8
- }
9
-
10
- export type InitFlowAction =
11
- | { type: 'toggle-key'; key: string }
12
- | { type: 'continue' }
13
- | { type: 'confirm' }
14
-
15
- export function createInitFlowState(
16
- availableKeys: string[],
17
- requiredKeys: string[],
18
- ): InitFlowState {
19
- return {
20
- step: 'keys',
21
- availableKeys,
22
- requiredKeys,
23
- selectedKeys: requiredKeys,
24
- }
25
- }
26
-
27
- export function advanceInitFlow(
28
- state: InitFlowState,
29
- action: InitFlowAction,
30
- ): InitFlowState {
31
- if (state.step === 'keys' && action.type === 'toggle-key') {
32
- if (state.requiredKeys.includes(action.key)) {
33
- return state
34
- }
35
-
36
- const selectedKeys = state.selectedKeys.includes(action.key)
37
- ? state.selectedKeys.filter((key) => key !== action.key)
38
- : [...state.selectedKeys, action.key]
39
-
40
- return {
41
- ...state,
42
- selectedKeys,
43
- }
44
- }
45
-
46
- if (state.step === 'keys' && action.type === 'continue') {
47
- return {
48
- ...state,
49
- step: 'confirm',
50
- }
51
- }
52
-
53
- if (state.step === 'confirm' && action.type === 'confirm') {
54
- return {
55
- ...state,
56
- step: 'done',
57
- }
58
- }
59
-
60
- return state
61
- }
@@ -1,129 +0,0 @@
1
- import type { EnvMap } from '../core/schema.js'
2
-
3
- export type PresetCreateSource = 'file' | 'manual'
4
- export type PresetCreateDestination = 'global' | 'project'
5
-
6
- export type PresetCreateStep =
7
- | 'source'
8
- | 'filePath'
9
- | 'keys'
10
- | 'manualInput'
11
- | 'name'
12
- | 'destination'
13
- | 'confirm'
14
- | 'done'
15
-
16
- export type PresetCreateFlowState = {
17
- step: PresetCreateStep
18
- source?: PresetCreateSource
19
- filePath?: string
20
- env: EnvMap
21
- allKeys: string[]
22
- selectedKeys: string[]
23
- presetName: string
24
- destination?: PresetCreateDestination
25
- error?: string | undefined
26
- }
27
-
28
- export type PresetCreateFlowResult = Pick<
29
- PresetCreateFlowState,
30
- 'source' | 'env' | 'selectedKeys' | 'presetName' | 'destination'
31
- > & {
32
- filePath?: string | undefined
33
- }
34
-
35
- export type PresetCreateFlowAction =
36
- | { type: 'select-source'; source: PresetCreateSource }
37
- | { type: 'set-file-path'; filePath: string }
38
- | { type: 'set-error'; error: string }
39
- | { type: 'select-keys'; keys: string[]; env: EnvMap }
40
- | { type: 'add-manual-pair'; key: string; value: string }
41
- | { type: 'finish-manual-input' }
42
- | { type: 'set-name'; name: string }
43
- | { type: 'select-destination'; destination: PresetCreateDestination }
44
- | { type: 'confirm' }
45
-
46
- export function createPresetCreateFlowState(): PresetCreateFlowState {
47
- return {
48
- step: 'source',
49
- env: {},
50
- allKeys: [],
51
- selectedKeys: [],
52
- presetName: '',
53
- }
54
- }
55
-
56
- export function advancePresetCreateFlow(
57
- state: PresetCreateFlowState,
58
- action: PresetCreateFlowAction,
59
- ): PresetCreateFlowState {
60
- switch (state.step) {
61
- case 'source':
62
- if (action.type !== 'select-source') return state
63
- return {
64
- ...state,
65
- step: action.source === 'file' ? 'filePath' : 'manualInput',
66
- source: action.source,
67
- }
68
-
69
- case 'filePath':
70
- if (action.type === 'set-error') {
71
- return { ...state, error: action.error }
72
- }
73
- if (action.type !== 'set-file-path') return state
74
- return {
75
- ...state,
76
- step: 'keys',
77
- filePath: action.filePath,
78
- error: undefined,
79
- }
80
-
81
- case 'keys':
82
- if (action.type !== 'select-keys') return state
83
- return {
84
- ...state,
85
- step: 'name',
86
- selectedKeys: action.keys,
87
- env: action.env,
88
- }
89
-
90
- case 'manualInput':
91
- if (action.type === 'add-manual-pair') {
92
- const hasKey = state.selectedKeys.includes(action.key)
93
- return {
94
- ...state,
95
- env: { ...state.env, [action.key]: action.value },
96
- selectedKeys: hasKey ? state.selectedKeys : [...state.selectedKeys, action.key],
97
- error: undefined,
98
- }
99
- }
100
- if (action.type === 'set-error') {
101
- return { ...state, error: action.error }
102
- }
103
- if (action.type !== 'finish-manual-input') return state
104
- return { ...state, step: 'name' }
105
-
106
- case 'name':
107
- if (action.type !== 'set-name') return state
108
- return {
109
- ...state,
110
- step: 'destination',
111
- presetName: action.name,
112
- }
113
-
114
- case 'destination':
115
- if (action.type !== 'select-destination') return state
116
- return {
117
- ...state,
118
- step: 'confirm',
119
- destination: action.destination,
120
- }
121
-
122
- case 'confirm':
123
- if (action.type !== 'confirm') return state
124
- return { ...state, step: 'done' }
125
-
126
- case 'done':
127
- return state
128
- }
129
- }
@@ -1,144 +0,0 @@
1
- import type { HistoryRecord } from '../core/schema.js'
2
-
3
- export type RestoreFlowStep = 'record' | 'target' | 'confirm' | 'done'
4
-
5
- type BaseRestoreFlowState = {
6
- records: HistoryRecord[]
7
- selectedTimestamp?: string
8
- }
9
-
10
- export type RestoreFlowState =
11
- | ({ step: 'record' } & BaseRestoreFlowState)
12
- | ({ step: 'target'; selectedTimestamp: string } & BaseRestoreFlowState)
13
- | ({ step: 'confirm'; selectedTimestamp: string } & BaseRestoreFlowState & (
14
- | {
15
- targetType: 'settings'
16
- }
17
- | {
18
- targetType: 'preset'
19
- targetName: string
20
- }
21
- ))
22
- | ({ step: 'done'; selectedTimestamp: string } & BaseRestoreFlowState & (
23
- | {
24
- targetType: 'settings'
25
- }
26
- | {
27
- targetType: 'preset'
28
- targetName: string
29
- }
30
- ))
31
-
32
- export type RestoreFlowAction =
33
- | {
34
- type: 'select-record'
35
- timestamp: string
36
- }
37
- | {
38
- type: 'select-target'
39
- targetType: 'settings' | 'preset'
40
- targetName?: string
41
- }
42
- | {
43
- type: 'confirm'
44
- }
45
-
46
- export function createRestoreFlowState(records: HistoryRecord[]): RestoreFlowState {
47
- return {
48
- step: 'record',
49
- records,
50
- }
51
- }
52
-
53
- export function advanceRestoreFlow(
54
- state: RestoreFlowState,
55
- action: RestoreFlowAction,
56
- ): RestoreFlowState {
57
- switch (state.step) {
58
- case 'record': {
59
- if (action.type !== 'select-record') {
60
- return state
61
- }
62
-
63
- const selectedRecord = state.records.find(
64
- (record) => record.timestamp === action.timestamp,
65
- )
66
-
67
- if (!selectedRecord) {
68
- return state
69
- }
70
-
71
- if (selectedRecord.action === 'init') {
72
- return {
73
- ...state,
74
- step: 'confirm',
75
- selectedTimestamp: action.timestamp,
76
- } as RestoreFlowState
77
- }
78
-
79
- return {
80
- ...state,
81
- step: 'target',
82
- selectedTimestamp: action.timestamp,
83
- }
84
- }
85
-
86
- case 'target':
87
- if (action.type !== 'select-target' || !state.selectedTimestamp) {
88
- return state
89
- }
90
-
91
- if (action.targetType === 'preset' && !action.targetName) {
92
- return state
93
- }
94
-
95
- if (action.targetType === 'settings') {
96
- return {
97
- ...state,
98
- step: 'confirm',
99
- targetType: 'settings',
100
- }
101
- }
102
-
103
- const targetName = action.targetName as string
104
-
105
- return {
106
- ...state,
107
- step: 'confirm',
108
- targetType: 'preset',
109
- targetName,
110
- }
111
-
112
- case 'confirm':
113
- if (action.type !== 'confirm' || !state.selectedTimestamp) {
114
- return state
115
- }
116
-
117
- const selectedRecord = state.records.find(
118
- (record) => record.timestamp === state.selectedTimestamp,
119
- )
120
-
121
- if (selectedRecord?.action === 'init') {
122
- return {
123
- ...state,
124
- step: 'done',
125
- } as RestoreFlowState
126
- }
127
-
128
- if (!state.targetType) {
129
- return state
130
- }
131
-
132
- if (state.targetType === 'preset' && !state.targetName) {
133
- return state
134
- }
135
-
136
- return {
137
- ...state,
138
- step: 'done',
139
- }
140
-
141
- case 'done':
142
- return state
143
- }
144
- }
@@ -1,110 +0,0 @@
1
- import React, { useEffect, useState } from 'react'
2
- import { Box, Text, useApp, useInput } from 'ink'
3
-
4
- import {
5
- advanceInitFlow,
6
- createInitFlowState,
7
- } from '../flows/init-flow.js'
8
-
9
- export function InitApp({
10
- keys = [],
11
- requiredKeys = [],
12
- sourceFiles = [],
13
- onSubmit,
14
- }: {
15
- keys?: string[]
16
- requiredKeys?: string[]
17
- sourceFiles?: string[]
18
- onSubmit?: (result: { confirmed: boolean; selectedKeys: string[] }) => void
19
- }) {
20
- const { exit } = useApp()
21
- const [cursor, setCursor] = useState(0)
22
- const [flowState, setFlowState] = useState(() =>
23
- createInitFlowState(keys, requiredKeys),
24
- )
25
-
26
- useEffect(() => {
27
- if (!onSubmit) {
28
- return
29
- }
30
-
31
- if (keys.length === 0) {
32
- onSubmit({ confirmed: false, selectedKeys: [] })
33
- exit()
34
- }
35
- }, [exit, keys.length, onSubmit])
36
-
37
- useInput((input, key) => {
38
- if (!onSubmit) {
39
- return
40
- }
41
-
42
- if (key.upArrow || input === 'k') {
43
- setCursor((c) => Math.max(0, c - 1))
44
- return
45
- }
46
-
47
- if (key.downArrow || input === 'j') {
48
- setCursor((c) => Math.min(keys.length - 1, c + 1))
49
- return
50
- }
51
-
52
- if (input === ' ') {
53
- const targetKey = keys[cursor]
54
- if (targetKey) {
55
- setFlowState((prev) =>
56
- advanceInitFlow(prev, { type: 'toggle-key', key: targetKey }),
57
- )
58
- }
59
- return
60
- }
61
-
62
- if (key.return) {
63
- onSubmit({ confirmed: true, selectedKeys: flowState.selectedKeys })
64
- exit()
65
- return
66
- }
67
-
68
- if (key.escape || input.toLowerCase() === 'q') {
69
- onSubmit({ confirmed: false, selectedKeys: [] })
70
- exit()
71
- }
72
- })
73
-
74
- return (
75
- <Box flexDirection="column">
76
- <Text bold>Select env keys to migrate into managed shell config</Text>
77
- {sourceFiles.length > 0 ? (
78
- <Box flexDirection="column">
79
- <Text dimColor>Source:</Text>
80
- {sourceFiles.map((file) => (
81
- <Text key={file} color="cyan"> {file}</Text>
82
- ))}
83
- </Box>
84
- ) : null}
85
- <Text dimColor>↑/k ↓/j navigate · space toggle · enter confirm · q cancel</Text>
86
- <Box flexDirection="column" marginTop={1}>
87
- {keys.map((key, i) => {
88
- const isRequired = requiredKeys.includes(key)
89
- const isSelected = flowState.selectedKeys.includes(key)
90
- const isCursor = i === cursor
91
- const checkbox = isSelected ? '[x]' : '[ ]'
92
-
93
- return (
94
- <Box key={key}>
95
- <Text>{isCursor ? '❯ ' : ' '}</Text>
96
- <Text color={isSelected ? 'green' : ''}>{checkbox}</Text>
97
- <Text> {key}</Text>
98
- {isRequired ? <Text dimColor> (required)</Text> : null}
99
- </Box>
100
- )
101
- })}
102
- </Box>
103
- <Box marginTop={1}>
104
- <Text dimColor>
105
- {flowState.selectedKeys.length} of {keys.length} selected
106
- </Text>
107
- </Box>
108
- </Box>
109
- )
110
- }