okf 1.0.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 (65) hide show
  1. checksums.yaml +7 -0
  2. data/.okf/capabilities/agent-skill.md +46 -0
  3. data/.okf/capabilities/graph-server.md +60 -0
  4. data/.okf/capabilities/index.md +20 -0
  5. data/.okf/capabilities/library-api.md +67 -0
  6. data/.okf/capabilities/linter.md +49 -0
  7. data/.okf/capabilities/read-views.md +84 -0
  8. data/.okf/capabilities/validator.md +40 -0
  9. data/.okf/cli.md +52 -0
  10. data/.okf/design/core-shell-split.md +58 -0
  11. data/.okf/design/index.md +10 -0
  12. data/.okf/design/ruby-floor.md +45 -0
  13. data/.okf/design/runtime-dependencies.md +44 -0
  14. data/.okf/design/server-trust-boundary.md +35 -0
  15. data/.okf/format/citations.md +33 -0
  16. data/.okf/format/cross-links.md +52 -0
  17. data/.okf/format/frontmatter.md +38 -0
  18. data/.okf/format/index.md +9 -0
  19. data/.okf/format/okf-format.md +43 -0
  20. data/.okf/index.md +18 -0
  21. data/.okf/log.md +9 -0
  22. data/.okf/model/bundle.md +38 -0
  23. data/.okf/model/concept.md +44 -0
  24. data/.okf/model/graph.md +44 -0
  25. data/.okf/model/index.md +8 -0
  26. data/.okf/overview.md +66 -0
  27. data/CHANGELOG.md +54 -0
  28. data/CODE_OF_CONDUCT.md +10 -0
  29. data/LICENSE.txt +201 -0
  30. data/NOTICE +10 -0
  31. data/README.md +276 -0
  32. data/exe/okf +6 -0
  33. data/lib/okf/bundle/folder.rb +94 -0
  34. data/lib/okf/bundle/graph.rb +118 -0
  35. data/lib/okf/bundle/linter/report.rb +56 -0
  36. data/lib/okf/bundle/linter.rb +416 -0
  37. data/lib/okf/bundle/reader.rb +60 -0
  38. data/lib/okf/bundle/validator/result.rb +35 -0
  39. data/lib/okf/bundle/validator.rb +131 -0
  40. data/lib/okf/bundle/writer.rb +137 -0
  41. data/lib/okf/bundle.rb +216 -0
  42. data/lib/okf/cli.rb +910 -0
  43. data/lib/okf/concept/file.rb +63 -0
  44. data/lib/okf/concept.rb +101 -0
  45. data/lib/okf/markdown/citations.rb +49 -0
  46. data/lib/okf/markdown/frontmatter.rb +55 -0
  47. data/lib/okf/markdown/links.rb +98 -0
  48. data/lib/okf/path.rb +34 -0
  49. data/lib/okf/server/app.rb +120 -0
  50. data/lib/okf/server/graph.rb +112 -0
  51. data/lib/okf/server/runner.rb +78 -0
  52. data/lib/okf/server/templates/graph.html.erb +803 -0
  53. data/lib/okf/skill/SKILL.md +133 -0
  54. data/lib/okf/skill/reference/APACHE-2.0.txt +202 -0
  55. data/lib/okf/skill/reference/SPEC.md +460 -0
  56. data/lib/okf/skill/reference/authoring.md +218 -0
  57. data/lib/okf/skill/reference/cli.md +196 -0
  58. data/lib/okf/skill/templates/concept.md +24 -0
  59. data/lib/okf/skill/templates/index.md +8 -0
  60. data/lib/okf/skill/templates/log.md +6 -0
  61. data/lib/okf/skill/templates/root-index.md +12 -0
  62. data/lib/okf/skill.rb +82 -0
  63. data/lib/okf/version.rb +5 -0
  64. data/lib/okf.rb +55 -0
  65. metadata +142 -0
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stringio"
4
+ require "webrick"
5
+
6
+ module OKF
7
+ module Server
8
+ # Runs a Rack app under WEBrick — the handful of lines a rackup dependency
9
+ # would otherwise bring in. WEBrick ships with Ruby up to 2.7 and as the
10
+ # `webrick` gem from 3.0 on; both work here, so the gem's server mode keeps
11
+ # rack's own Ruby support range (>= 2.4).
12
+ #
13
+ # The env it builds covers what a GET-serving Rack app needs (method, path,
14
+ # query, headers, rack.input); it is not a general CGI bridge. Part of the
15
+ # shell — it opens sockets.
16
+ module Runner
17
+ module_function
18
+
19
+ # Serve +app+ until interrupted (INT/TERM shut the server down).
20
+ def run(app, host:, port:)
21
+ server = build(app, host: host, port: port)
22
+ %w[INT TERM].each { |signal| trap(signal) { server.shutdown } }
23
+ server.start
24
+ end
25
+
26
+ # A configured-but-not-started WEBrick server, so callers (and tests) can
27
+ # pick the port (0 = ephemeral), start it on their own thread, and shut it
28
+ # down deterministically.
29
+ def build(app, host:, port:)
30
+ server = WEBrick::HTTPServer.new(
31
+ BindAddress: host, Port: port,
32
+ Logger: WEBrick::Log.new(nil, WEBrick::BasicLog::WARN), AccessLog: []
33
+ )
34
+ server.mount_proc("/") { |request, response| handle(app, request, response) }
35
+ server
36
+ end
37
+
38
+ def handle(app, request, response)
39
+ status, headers, body = app.call(env_for(request))
40
+ response.status = status.to_i
41
+ headers.each { |name, value| response[name] = value }
42
+ payload = String.new
43
+ body.each { |chunk| payload << chunk } # a Rack body only guarantees #each
44
+ response.body = payload
45
+ ensure
46
+ body.close if body.respond_to?(:close)
47
+ end
48
+
49
+ def env_for(request)
50
+ env = {
51
+ "REQUEST_METHOD" => request.request_method,
52
+ "SCRIPT_NAME" => "",
53
+ "PATH_INFO" => request.path,
54
+ "QUERY_STRING" => request.query_string.to_s,
55
+ "SERVER_NAME" => request.host.to_s,
56
+ "SERVER_PORT" => request.port.to_s,
57
+ "SERVER_PROTOCOL" => "HTTP/#{request.http_version}",
58
+ "rack.url_scheme" => "http",
59
+ "rack.input" => StringIO.new(read_body(request)),
60
+ "rack.errors" => $stderr
61
+ }
62
+ request.each { |name, value| env["HTTP_#{name.upcase.tr("-", "_")}"] = value }
63
+ # Rack reads the entity headers unprefixed.
64
+ env["CONTENT_TYPE"] = env.delete("HTTP_CONTENT_TYPE") if env.key?("HTTP_CONTENT_TYPE")
65
+ env["CONTENT_LENGTH"] = env.delete("HTTP_CONTENT_LENGTH") if env.key?("HTTP_CONTENT_LENGTH")
66
+ env
67
+ end
68
+
69
+ # The request body as a string; bodyless requests (every GET this server
70
+ # sees) read as "".
71
+ def read_body(request)
72
+ request.body.to_s
73
+ rescue WEBrick::HTTPStatus::Status, StandardError
74
+ ""
75
+ end
76
+ end
77
+ end
78
+ end