@codua/codeoutline-win32-x64 0.1.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 (44) hide show
  1. package/DISTRIBUTION.md +98 -0
  2. package/LICENSE +24 -0
  3. package/README.md +132 -0
  4. package/README.zh-CN.md +132 -0
  5. package/THIRD_PARTY.md +32 -0
  6. package/build-info.json +1 -0
  7. package/codeoutline +4 -0
  8. package/codeoutline.cmd +3 -0
  9. package/licenses/libdeflate.txt +22 -0
  10. package/licenses/lua-cmsgpack.txt +22 -0
  11. package/licenses/luajit.txt +56 -0
  12. package/licenses/mbedtls.txt +553 -0
  13. package/licenses/rpmalloc.txt +12 -0
  14. package/licenses/xnet2lua.txt +24 -0
  15. package/licenses/yyjson.txt +21 -0
  16. package/package.json +1 -0
  17. package/scripts/codeoutline/cli.lua +32 -0
  18. package/scripts/codeoutline/command.lua +155 -0
  19. package/scripts/codeoutline/common.lua +124 -0
  20. package/scripts/codeoutline/control.lua +4 -0
  21. package/scripts/codeoutline/explore.lua +500 -0
  22. package/scripts/codeoutline/graph.lua +380 -0
  23. package/scripts/codeoutline/http.lua +156 -0
  24. package/scripts/codeoutline/index.lua +404 -0
  25. package/scripts/codeoutline/index_worker.lua +43 -0
  26. package/scripts/codeoutline/lang/c.lua +362 -0
  27. package/scripts/codeoutline/lang/cpp.lua +539 -0
  28. package/scripts/codeoutline/lang/csharp.lua +334 -0
  29. package/scripts/codeoutline/lang/go.lua +233 -0
  30. package/scripts/codeoutline/lang/java.lua +274 -0
  31. package/scripts/codeoutline/lang/js.lua +466 -0
  32. package/scripts/codeoutline/lang/lua.lua +218 -0
  33. package/scripts/codeoutline/lang/python.lua +184 -0
  34. package/scripts/codeoutline/lang/rust.lua +276 -0
  35. package/scripts/codeoutline/main.lua +104 -0
  36. package/scripts/codeoutline/mcp.lua +188 -0
  37. package/scripts/codeoutline/parse.lua +49 -0
  38. package/scripts/codeoutline/path.lua +36 -0
  39. package/scripts/codeoutline/service.lua +135 -0
  40. package/scripts/codeoutline/text.lua +43 -0
  41. package/scripts/codeoutline/version.lua +1 -0
  42. package/scripts/codeoutline/xscan.lua +625 -0
  43. package/xnet2lua/bin/xnet.exe +0 -0
  44. package/xnet2lua/scripts/core/share/xhttp_codec.lua +835 -0
@@ -0,0 +1,155 @@
1
+ -- Unified CLI. Launch through codeoutline (npm/native) or xnet with LOG_STDERR=1.
2
+ local source = assert(xutils.realpath(debug.getinfo(1, 'S').source:sub(2))):gsub('\\', '/')
3
+ local scripts = assert(source:match('^(.*)/codeoutline/[^/]+$'))
4
+ package.path = scripts .. '/?.lua;' .. package.path
5
+ local version = require('codeoutline.version')
6
+ local help = [[CodeOutline - Lua code indexing and MCP
7
+
8
+ Usage:
9
+ codeoutline serve --stdio [--project PATH] [--allow-root PATH ...]
10
+ codeoutline serve --http [--host HOST] [--port PORT] [--project PATH]
11
+ codeoutline explore --project PATH --query QUERY [--budget BYTES]
12
+ codeoutline status [--project PATH]
13
+ codeoutline rebuild [--project PATH]
14
+ codeoutline doctor [--project PATH]
15
+ codeoutline --version
16
+
17
+ HTTP options: --allow-host HOST, --allow-origin ORIGIN (repeatable).
18
+ Remote HTTP requires CODEOUTLINE_TOKEN (at least 16 bytes).
19
+ Project defaults to the working directory for one-shot commands.
20
+ doctor reports JSON diagnostics and exits nonzero on a failed check.
21
+ ]]
22
+
23
+ local function parse(args)
24
+ local clean = {}
25
+ for _, value in ipairs(args) do
26
+ if value ~= 'LOG_STDERR=1' then clean[#clean + 1] = value end
27
+ end
28
+ local command = clean[1] or '--help'
29
+ if command == '--help' or command == '-h' or command == '--version' then
30
+ assert(#clean <= 1, 'unexpected arguments after ' .. command)
31
+ return command, {}
32
+ end
33
+ local allowed = {
34
+ serve = { stdio = true, http = true, project = true, host = true, port = true,
35
+ ['allow-root'] = true, ['allow-host'] = true, ['allow-origin'] = true },
36
+ explore = { project = true, query = true, budget = true },
37
+ status = { project = true }, rebuild = { project = true }, doctor = { project = true },
38
+ }
39
+ assert(allowed[command], 'unknown command: ' .. command)
40
+ local options, i = {}, 2
41
+ while i <= #clean do
42
+ local name, value = clean[i]:match('^%-%-([%w-]+)=(.*)$')
43
+ if not name then name = clean[i]:match('^%-%-([%w-]+)$') end
44
+ assert(name and (allowed[command][name] or name == 'help'), 'unknown option: ' .. clean[i])
45
+ local flag = name == 'stdio' or name == 'http' or name == 'help'
46
+ if flag then
47
+ assert(value == nil, '--' .. name .. ' does not take a value')
48
+ value = true
49
+ elseif value == nil then
50
+ i = i + 1
51
+ value = clean[i]
52
+ assert(value and not value:match('^%-%-'), 'missing value for --' .. name)
53
+ end
54
+ assert(value ~= '', 'empty value for --' .. name)
55
+ if name:match('^allow-') then
56
+ options[name] = options[name] or {}
57
+ table.insert(options[name], value)
58
+ else
59
+ assert(options[name] == nil, 'duplicate option --' .. name)
60
+ options[name] = value
61
+ end
62
+ i = i + 1
63
+ end
64
+ return command, options
65
+ end
66
+
67
+ local function doctor(root)
68
+ local checks, healthy = {}, true
69
+ local function check(name, fn)
70
+ local ok, detail = pcall(fn)
71
+ checks[#checks + 1] = { name = name, ok = ok, detail = tostring(detail) }
72
+ healthy = healthy and ok
73
+ end
74
+ check('runtime', function()
75
+ for _, name in ipairs({ 'realpath', 'temp_file', 'replace_file', 'read_stdin', 'random_bytes', 'sha256_hex', 'list_dir', 'to_utf8' }) do
76
+ assert(type(xutils[name]) == 'function', 'rebuild xnet2lua: missing xutils.' .. name)
77
+ end
78
+ assert(cmsgpack and xcompress and xshared and xnet and xproc, 'rebuild xnet2lua with xproc and default modules')
79
+ return 'xnet2lua / ' .. (jit and jit.version or _VERSION)
80
+ end)
81
+ -- A warning, not a failure: UTF-8 projects work without the GBK converter.
82
+ check('gbk', function()
83
+ if xutils.to_utf8('\214\208\206\196', 'gbk') == '中文' then return 'system converter available' end
84
+ return 'unavailable: GBK sources cannot be decoded; install the system GBK converter'
85
+ .. ' (glibc-gconv-extra on EL8/EL9)'
86
+ end)
87
+ check('scanner', function()
88
+ return xscan and os.getenv('XSCAN_PURE_LUA') ~= '1' and 'native xscan' or 'pure Lua fallback'
89
+ end)
90
+ local idx
91
+ check('project', function()
92
+ idx = require('codeoutline.index').open(root)
93
+ return idx.root
94
+ end)
95
+ check('enumerator', function()
96
+ assert(idx, 'fix project path first')
97
+ local files = idx:list_files()
98
+ return idx.enumerator .. ': ' .. #files .. ' supported files'
99
+ end)
100
+ check('cache', function()
101
+ assert(idx, 'fix project path first')
102
+ local dir = assert(idx.cache_path:match('^(.*)/[^/]+$'))
103
+ assert(xutils.mkdir_p(dir))
104
+ local temp = assert(xutils.temp_file(dir))
105
+ local ok, err = pcall(function()
106
+ local f = assert(io.open(temp, 'wb'))
107
+ local wrote, why = f:write('codeoutline doctor\n')
108
+ local closed, close_error = f:close()
109
+ assert(wrote, why); assert(closed, close_error)
110
+ end)
111
+ local removed, remove_error = os.remove(temp)
112
+ assert(ok, err); assert(removed, remove_error)
113
+ return dir
114
+ end)
115
+ io.write(xutils.json_pack({ ok = healthy, version = version, checks = checks }), '\n')
116
+ return healthy and 0 or 1
117
+ end
118
+
119
+ local function run()
120
+ local command, options = parse(arg or {})
121
+ if command == '--help' or command == '-h' or options.help then io.write(help); return 0 end
122
+ if command == '--version' then io.write(version, '\n'); return 0 end
123
+ if command == 'serve' then
124
+ assert(not not options.stdio ~= not not options.http, 'serve requires exactly one of --stdio or --http')
125
+ arg = { options.stdio and 'STDIO=1' or 'HTTP=1' }
126
+ for _, name in ipairs({ 'project', 'host', 'port', 'allow-root', 'allow-host', 'allow-origin' }) do
127
+ local value = options[name]
128
+ if value then
129
+ for _, item in ipairs(type(value) == 'table' and value or { value }) do
130
+ arg[#arg + 1] = name:upper():gsub('-', '_') .. '=' .. item
131
+ end
132
+ end
133
+ end
134
+ return dofile(scripts .. '/codeoutline/main.lua')
135
+ end
136
+ local root = options.project or '.'
137
+ if command == 'doctor' then return doctor(root) end
138
+ local svc = require('codeoutline.service')
139
+ if command == 'explore' then
140
+ assert(options.query, 'explore requires --query')
141
+ local budget
142
+ if options.budget then budget = assert(tonumber(options.budget), '--budget must be a number') end
143
+ local text = svc.explore(root, options.query, { budget = budget })
144
+ io.write(text, '\n')
145
+ else
146
+ io.write(xutils.json_pack(svc[command](root)), '\n')
147
+ end
148
+ return 0
149
+ end
150
+
151
+ local ok, result = pcall(run)
152
+ if not ok then io.stderr:write('codeoutline: ', tostring(result), '\n'); result = 1 end
153
+ if type(result) == 'table' then return result end
154
+ io.stdout:flush()
155
+ return { __init = function() xthread.stop(result) end }
@@ -0,0 +1,124 @@
1
+ -- common.lua — the per-file result model every language parser fills, plus
2
+ -- helpers shared by the parsers.
3
+ --
4
+ -- Result: {
5
+ -- path, language,
6
+ -- nodes = { {kind, name, qualified, line, end_line, sig?, parent?, static?, bases?} },
7
+ -- refs = { {from = node index | 0 (file scope), name, kind, line, recv?} },
8
+ -- imports = { {path, line, names?} },
9
+ -- }
10
+ -- Refs are attributed after parsing: a parser only records where each call
11
+ -- sits (token index) and assign_refs() hands it to the innermost node whose
12
+ -- token range contains it. That keeps nested functions/classes correct
13
+ -- without each parser tracking scope for every call site.
14
+
15
+ local M = {}
16
+ local text = require('codeoutline.text')
17
+
18
+ function M.new(path, language)
19
+ return { path = path, language = language, nodes = {}, refs = {}, imports = {} }
20
+ end
21
+
22
+ -- Collapse a token span into a one-line signature.
23
+ function M.sig(T, a, b, max)
24
+ local src = T.src:sub(T.s[a], T.e[b])
25
+ src = src:gsub('%s+', ' ')
26
+ max = max or 200
27
+ if #src > max then src = text.prefix(text.valid(src), max) .. '...' end
28
+ return src
29
+ end
30
+
31
+ -- ti/tj: token range the node covers (used for ref attribution, then dropped).
32
+ function M.add_node(r, T, f)
33
+ local parent = f.parent and r.nodes[f.parent]
34
+ local sep = f.sep or '.'
35
+ f.qualified = parent and (parent.qualified .. sep .. f.name) or ((r.prefix and (r.prefix .. sep) or '') .. f.name)
36
+ f.line = f.line or T:line(f.ti)
37
+ f.end_line = f.end_line or T:eline(f.tj)
38
+ f.sep = nil
39
+ r.nodes[#r.nodes + 1] = f
40
+ return #r.nodes
41
+ end
42
+
43
+ -- Record every call site in token range [a, b].
44
+ local MEMBER = { ['.'] = true, ['->'] = true, ['::'] = true, ['?.'] = true }
45
+ function M.add_calls(r, T, a, b)
46
+ local skip = r.skip_calls
47
+ local member = r.member_ops or MEMBER -- Lua adds ':' (obj:method())
48
+ for _, x in ipairs(T:calls(a, b)) do
49
+ if skip and skip[T:text(x)] then goto next end
50
+ local kind, recv = 'call', nil
51
+ local p = x - 1
52
+ if p >= 1 and T.k[p] == 'op' and member[T:text(p)] then
53
+ kind = 'member_call'
54
+ if T.k[p - 1] == 'id' or T.k[p - 1] == 'kw' then recv = T:text(p - 1) end
55
+ elseif p >= 1 and T.k[p] == 'kw' and T:text(p) == 'new' then
56
+ kind = 'new'
57
+ elseif p >= 1 and T.k[p] == 'op' and T:text(p) == '@' then
58
+ kind = 'annotation'
59
+ end
60
+ r.refs[#r.refs + 1] = { tok = x, name = T:text(x), kind = kind, line = T:line(x), recv = recv }
61
+ ::next::
62
+ end
63
+ end
64
+
65
+ -- Identifiers used as bare values — `lua_pushcfunction(L, fn)`, `{"name", fn}`,
66
+ -- `cb = fn;` — the usual way C code registers callbacks. Only single-token
67
+ -- operands between separators qualify, which keeps locals-in-expressions out.
68
+ local BEFORE = { [','] = true, ['('] = true, ['='] = true, ['{'] = true, ['&'] = true }
69
+ local AFTER = { [','] = true, [')'] = true, ['}'] = true, [';'] = true }
70
+ function M.add_value_refs(r, T, a, b)
71
+ local seen = {}
72
+ for _, x in ipairs(T:idents(a, b)) do
73
+ local p, q = x - 1, x + 1
74
+ if T.k[p] == 'op' and T.k[q] == 'op' and BEFORE[T:text(p)] and AFTER[T:text(q)] then
75
+ local name = T:text(x)
76
+ if not seen[name] then
77
+ seen[name] = true
78
+ r.refs[#r.refs + 1] = { tok = x, name = name, kind = 'ref', line = T:line(x) }
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ -- Hand each ref to the innermost node whose token range contains it. Node
85
+ -- ranges nest or are disjoint, so one sweep with a stack does it.
86
+ function M.assign_refs(r)
87
+ local order = {}
88
+ for i, n in ipairs(r.nodes) do if n.ti then order[#order + 1] = i end end
89
+ table.sort(order, function(a, b)
90
+ local na, nb = r.nodes[a], r.nodes[b]
91
+ if na.ti ~= nb.ti then return na.ti < nb.ti end
92
+ if na.tj ~= nb.tj then return na.tj > nb.tj end
93
+ return a < b
94
+ end)
95
+ -- table.sort is unstable (and randomizes pivots on large arrays), so
96
+ -- break ties by insertion order to keep output deterministic.
97
+ for i, ref in ipairs(r.refs) do ref.seq = i end
98
+ table.sort(r.refs, function(a, b)
99
+ if a.tok ~= b.tok then return a.tok < b.tok end
100
+ return a.seq < b.seq
101
+ end)
102
+ local stack, oi = {}, 1
103
+ for _, ref in ipairs(r.refs) do
104
+ while oi <= #order and r.nodes[order[oi]].ti <= ref.tok do
105
+ local n = r.nodes[order[oi]]
106
+ while #stack > 0 and r.nodes[stack[#stack]].tj < n.ti do stack[#stack] = nil end
107
+ stack[#stack + 1] = order[oi]
108
+ oi = oi + 1
109
+ end
110
+ while #stack > 0 and r.nodes[stack[#stack]].tj < ref.tok do stack[#stack] = nil end
111
+ ref.from = stack[#stack] or 0
112
+ end
113
+ end
114
+
115
+ -- Drop parser-internal fields so the result is plain data.
116
+ function M.finish(r)
117
+ M.assign_refs(r)
118
+ for _, ref in ipairs(r.refs) do ref.tok, ref.seq = nil, nil end
119
+ for _, n in ipairs(r.nodes) do n.ti, n.tj = nil, nil end
120
+ r.prefix, r.skip_calls = nil, nil
121
+ return r
122
+ end
123
+
124
+ return M
@@ -0,0 +1,4 @@
1
+ -- Per-Lua-state cancellation checkpoint installed only by the service worker.
2
+ local M = {}
3
+ function M.check() if M.callback then M.callback() end end
4
+ return M